1. The Problem: The Linear Page Table Memory Explosion
As explored in previous lessons, a single-level linear page table requires an entry for every virtual page in a process's address space. On a 32-bit architecture with 4 KB pages (212 = 4,096 bytes), a process has 232 / 212 = 220 (1,048,576) virtual pages.
If each Page Table Entry (PTE) is 4 bytes, a single process must allocate a 4 MB contiguous block of RAM solely to store its page table. In a multiprogrammed system running 64 active processes, over 256 MB of physical RAM is consumed strictly by bookkeeping page tables—even if most of those virtual addresses are never touched! On 64-bit architectures, a linear table would require petabytes of RAM, making it physically impossible.
2. The Solution: Hierarchical Multilevel Paging
To avoid allocating memory for unused virtual address ranges, operating systems adopt Hierarchical Multilevel Paging (such as two-level paging in 32-bit systems or four-level paging in x86_64).
Instead of keeping the entire million-entry page table in memory, the page table itself is broken up into page-sized pieces (e.g., 1,024 entries per table). A Top-Level Page Directory is introduced, where each entry points to a second-level page table.
If a large chunk of virtual memory (e.g., between the heap and the stack) is completely unallocated, the corresponding top-level directory entry is marked
NULL. Consequently, the entire 4 MB second-level page table for that region does not need to exist in physical memory at all!
3. Address Slicing Mechanics
A 32-bit virtual address is split into three distinct fields:
- PT1 (Top 10 bits, bits 31–22): Indexes into the Top-Level Page Directory (1,024 possible entries).
- PT2 (Middle 10 bits, bits 21–12): Indexes into the chosen Second-Level Page Table (1,024 entries per table).
- Offset (Lowest 12 bits, bits 11–0): Locates the exact byte within the 4 KB physical frame (4,096 bytes).
Notice how top-level entries without active mappings hold NULL, meaning the entire 4 MB second-level table does not need to exist in memory.