Β§20.1–20.2Simple Solution: Bigger Pages … Hybrid Approach: Paging and Segments

Part I OSTEP pp. 215–218 Β· ~7 min read

Paging’s other bill: the table itself. A 32-bit space with 4KB pages and 4-byte PTEs means a million entries β€” 4MB per process, hundreds of megabytes across a busy system, all spent on translations.

The Crux: How To Make Page Tables Smaller?

Simple array-based (linear) page tables are too big. How can we make them smaller? What are the key ideas? What inefficiencies arise from the new data structures?

20.1 Simple Solution: Bigger Pages

Quadruple the page size β€” 16KB pages in a 32-bit space β€” and the table shrinks fourfold:

218Β PTEsΓ—4 B=1 MBΒ perΒ table2^{18} \ \text{PTEs} \times 4\,\text{B} = 1\,\text{MB per table}

The reduction exactly mirrors the page-size increase. But big pages punish us inside each page: applications allocate a page and use bits of it, and memory fills with mostly-empty giants β€” internal fragmentation again. So common cases stay small: 4KB (x86), 8KB (SPARCv9).

Aside: Multiple Page Sizes

Many architectures (MIPS, SPARC, x86-64) support several page sizes: a 4KB default, plus large pages (e.g. 4MB) on request β€” so a DBMS can drop a hot, giant structure onto ONE page, consuming a single TLB entry. The main motive isn’t table space at all: it’s reducing TLB pressure. The cost is a notably more complex VM manager β€” which is why large pages are often granted only through an explicit application interface.

20.2 Hybrid Approach: Paging and Segments

When two reasonable approaches both fall short, try the combination β€” chocolate, meet peanut butter. Years ago Multics (Jack Dennis) did exactly this to shrink page tables. First, stare at the waste a linear table carries for a barely-used address space:

Figure 20.1 (left): a 16KB address space, 1KB pages β€” four pages used, twelve empty
code β€” VPN 0 β“˜0(free)1heap β€” VPN 4 β“˜4(free) β€” nine untouched pages β“˜5stack β€” VPN 14 β“˜14stack β€” VPN 15 β“˜1516

click a region marked β“˜ for details

Figure 20.1 (right): the four pages, scattered through a 32-frame physical memory
(other frames)04(other frames)5KB10(other frames)11KB23(other frames)24KB28(other frames)29KB32
Figure 20.2: the linear page table for that address space β€” count the rows that say nothing
PFNvalidprotpresentdirty
VPN 0101r-x10
VPN 1β€”0β€”β€”β€”
VPN 2β€”0β€”β€”β€”
VPN 3β€”0β€”β€”β€”
VPN 4231rw-11
VPN 5β€”0β€”β€”β€”
VPN 6β€”0β€”β€”β€”
VPN 7β€”0β€”β€”β€”
VPN 8β€”0β€”β€”β€”
VPN 9β€”0β€”β€”β€”
VPN 10β€”0β€”β€”β€”
VPN 11β€”0β€”β€”β€”
VPN 12β€”0β€”β€”β€”
VPN 13β€”0β€”β€”β€”
VPN 14281rw-11
VPN 1541rw-11
Dotted-underlined cells have explanations β€” click one.

Twelve of sixteen entries describe emptiness β€” for a 16KB space. Don’t imagine the 32-bit version; it’s far too gruesome.

The hybrid: one page table per logical segment β€” code, heap, stack. The MMU keeps chapter 16’s base/bounds pairs, repurposed: the base register no longer points at the segment but at that segment’s page table in physical memory; the bounds register holds the segment’s maximum valid page. A 32-bit address then carries three fields:

Seg (2)VPN (18)Offset (12)

On a TLB miss the hardware picks the pair by segment and indexes that segment’s table β€” virtually the linear lookup, with three base registers instead of one:

SN           = (VirtualAddress & SEG_MASK) >> SN_SHIFT
VPN          = (VirtualAddress & VPN_MASK) >> VPN_SHIFT
AddressOfPTE = Base[SN] + (VPN * sizeof(PTE))

The saving lives in the bounds register: a code segment using three pages keeps a three-entry page table, and the unallocated sea between heap and stack β€” belonging to no segment β€” costs nothing. Accesses beyond a segment’s end fault, as ever.

But the hybrid inherits its parents’ flaws. It’s still segmentation: a large, sparsely-used heap drags a long page table again β€” the usage-pattern rigidity of chapter 16. And page tables are now arbitrary-sized (any multiple of PTEs), so finding memory for them resurrects external fragmentation β€” chapter 17’s whole battle, waged now on behalf of the bookkeeping itself. People kept looking.

Tip: Use Hybrids

Two good, opposing ideas? Check the combination β€” hybrid corn beats every natural species. But not every cross is a Reese’s cup: behold the Zeedonk (zebra Γ— donkey), which exists, and which you should look up, prepared to be amazed.

Check yourself

1.Quadrupling the page size (4KB β†’ 16KB) shrinks the linear page table 4Γ— (4MB β†’ 1MB). Why don't systems just keep going?

2.Many architectures let a 'smart' application place a hot data structure in one 4MB large page. What's the MAIN motivation?

3.In the Multics-style hybrid, what do the segment base and bounds registers hold β€” and where do the savings come from?

4.The hybrid saves real memory, yet the book keeps looking. What are its two lingering problems?

5.The tiny 16KB address space uses 4 of its 16 pages, and its linear page table shows it. What's the lesson of Figure 20.2?

5 questions