










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Segmentation and paging background
-^
Segmentation– Intel segmentation hardware– Linux use of Intel segmentation
-^
Paging– Intel paging hardware– Linux use of Intel paging
-^
Memory layout– Kernel layout in physical memory– Process virtual memory layout– Kernel virtual memory layout
Motivated by logical use of memory areas– Code, heap, stack, etc.
-^
Base + offset– Segment registers contain base
-^
Segments variable size (usually large)
-^
Process as collection of segments– No notion of linear, contiguous memory– Similar to “multi-stream” files (Mac)
-^
Requires “segment table”
Logical
Linear
(virtual) – 0 .. 4GB (64GB with PAE)
Physical
Segment registers: cs, ss, ds, es, fs, gs– Indices ("selectors") into "segment descriptor tables"
-^
Segment descriptor tables: GDT, LDT– Global and local (per process, in theory)– Each holds about 8000 descriptors
-^
Segment descriptors: 8 bytes each– Base/limit, code/data privileges, type– Cached in ro registers when seg registers loaded
-^
Task segment descriptor (TSS)– Special segment for holding process context
Page table "maps" linear address space– Some pages may be invalid– Address space grows/shrinks (mapping)
Intel page size: 4K or 4M ("jumbo pages")– Jumbo pages reduce table size
-^
Paging "enabled" by writing
cr
register
How big are page tables on 64 bit arch?– Sparc, Alpha, Itanium– Assume 16K pages => 32 M per process!
-^
Better idea: three-level paging trees– Page Global Directory (pgd)– Page Middle Directory (pmd)– Page Table (pt)
-^
Carve linear address into 4 pieces
-^
Conceptual paging model– On Intel, page middle directory is compiled out
cache line!
keep cache utilized
Three-level scheme– Middle directories "collapsed" w/ macro tricks– No bits assigned for middle directory
-^
On context switch (address space change)– Save/load registers in TSS– Install new top-level directory (write cr3)– Flush TLB
-^
Lot's of macros for:– Allocating/deallocating, altering, querying…– Page directories, tables, entries– Examples:
-^
Kernel is "pinned" (non-swappable)
-^
Usually about 1M; mapped in first 2M
-^
Some "holes" in low memory– Zero frame always invalid (avoids null dereference)– ISA "i/o aperture" (640K .. 1M)
-^
Kernel layout symbols (System.map)– _text (code start) (usually about 1M)– _etext (initialized data start)– _edata (uninitialized data start)– _end (end of kernel data)
-^
Remaining frames allocated as needed by kernel pageallocator
Kernel page tables initialized in two stagesduring startup– Phase one: only maps 4MB (provisional)– Phase two: maps all memory
-^
Provisional– Static PGD, just one PT– swapper_pg_dir– Low 4M of user & kernel map low 4M physical– Allows kernel to be addressed virtually or physically
Kernel code– Operates using linear (virtual) addresses– Macros to go from physical to virtual and back
Kernel mapped using jumbo pages
-^
Kernel virtual address space– Low physical frames (containing kernel) mapped to
virtual addresses starting at PAGE_OFFSET
and user processes and mapped to virtual addresses