00x511—2—30x52…10230x534 MiB0x2A60x2A70x2A80—…50x2A7…1023—DIRTABLEOFFSETCPUCR3 · FRAME0x500x5030x5250x2A70x1231walk123
Back: the page directory and physical memoryMiddle and front: the flat table, one page table, the address and the CPU with CR3Tokens: the address fields and frame numbers handed on at each levelAt the back, the page directory and physical memory; in the middle, the one flat 4 MiB table and one page table; in front, the virtual address and the CPU with CR3. The address 0x00C05123 splits into 3, 5 and 0x123. CR3 finds the directory, entry 3 finds the page table, entry 5 finds frame 0x2A7, and the offset picks the byte. A second address hits a directory entry that is not present: a page fault. The frame numbers (0x50, 0x51, 0x52, 0x53, 0x2A7) and the byte 42 are example data: a real kernel picks whichever frames are free. The sizes and the 10 | 10 | 12 split are those of classic 32-bit x86 paging.

The problem

  1. On a 32-bit machine with 4 KiB pages, a flat page table needs one 4-byte entry for each of about a million pages: 4 MiB for every process. Most programs use only a few pages, so nearly all those entries are empty.

Walking the tree

Gaps and trade-offs

What happens

;; step 1/11 · one-table
address space   2^32 bytes = 4 GiB
page size       2^12 bytes = 4 KiB
pages           2^32 / 2^12 = 2^20 = 1,048,576
entry size      4 bytes
flat table      2^20 x 4 = 4,194,304 bytes = 4 MiB
                one per process, and it must sit in one piece

The frame numbers (0x50, 0x51, 0x52, 0x53, 0x2A7) and the byte 42 are example data: a real kernel picks whichever frames are free. The sizes and the 10 | 10 | 12 split are those of classic 32-bit x86 paging. A real entry holds more than a frame number: the low bits carry flags such as present, writable and user-allowed. The figure shows only the frame number, and a dash for an entry that is not present.