Page tables and address translation
Split virtual addresses into page numbers and offsets, then distinguish hardware translation work from operating-system fault handling.
On this page
The question for today
What you’ll understand
- Translate a byte address using a page-frame mapping.
- Estimate leaf page-table storage under explicit architecture assumptions.
- Explain why a TLB miss does not necessarily cause a page fault.
A pointer names a location in a process address space, not an interchangeable physical RAM position. The translation system decides which physical frame, permissions, and memory attributes apply to an access. Understanding that indirection lets an engineer separate an invalid pointer, an ordinary translation-cache miss, and a legitimate access whose backing page needs operating-system work.
Keep the byte offset; translate the page number
Take a byte-addressed machine with a power-of-two page size. The low address bits identify a byte within the page; the remaining bits identify a virtual page. A page-table entry can associate that virtual page with a physical frame. For an ordinary mapping, translation preserves the offset and replaces the page number. Two virtual pages may refer to one physical frame, so virtual address inequality does not prove that the underlying storage differs. Conversely, identical virtual pointers in different processes can refer to entirely different frames.
Permissions belong to the translation contract as well as the frame number. A present page may permit reads and forbid writes or instruction fetches. The processor checks the effective permissions for the requested operation, including relevant higher-level restrictions and privilege rules. A program therefore cannot establish that an access will succeed merely by observing that physical RAM exists. Use the architecture manual when investigating permission interactions; examples with one simple read-write flag are explanatory reductions, not complete hardware formats.
A hierarchy stores sparse mappings
A flat array needs an entry for every possible virtual page even if the process uses a tiny part of its address space. A hierarchy instead divides page-number bits into indices. An upper entry points to the next table or, on supported architectures and levels, directly maps a large page. Entire absent subtrees can represent large holes. Linux provides architecture-neutral names for multiple levels, but an architecture may fold unused levels. Never infer the actual hardware walk depth from the number of names visible in generic kernel source.
For a teaching calculation, assume base pages of 4 KiB and eight-byte leaf entries. One 4 KiB leaf-table page holds 512 entries, covering 2 MiB of fully mapped virtual space. Mapping a contiguous, base-page-aligned 1 GiB range needs 262,144 leaf entries, containing 2 MiB of entry data. Allocated table pages can also contain unused entries at the range boundaries. This is not the cost of every 1 GiB reservation: untouched holes, huge mappings, alignment, and the tables already present all change allocation. Count installed mappings and allocated table pages rather than multiplying a process virtual-size metric blindly.
Translation-cache misses are not absent pages
A translation lookaside buffer caches recent translations. On hardware with a hardware page walker, a TLB miss can be satisfied by walking valid page tables without a software page-fault exception. A fault instead indicates an access condition requiring the fault path, such as an absent mapping or disallowed write; some faults are recoverable. Translation invalidation also matters when the kernel changes mappings. A stale cached translation cannot simply be left in use because the memory containing its old table entry was updated.
Use the probability lab as a deliberately restricted cache-hit calculation. Set success probability to 0.8 and trials to 20; the displayed mean predicts sixteen hits in an independent equal-probability model. The four expected misses say nothing about whether pages are resident. Change the probability to 0.5 and predict ten hits before inspecting the readout. Real TLB behavior depends on reference order, page sizes, associativity, and invalidations, so the binomial bars neither model a page walk nor establish a fault rate.
Work it through
Translate one pointer and price its leaf table
Assume 4 KiB pages. Virtual address 0x12345 belongs to a page mapped to physical frame 0xAB. Separately, a fully populated 8 MiB range begins at a 2 MiB-aligned virtual address and uses eight-byte base-page leaf entries. Its leaf tables must be freshly allocated, with none already present.
Divide the virtual address by 0x1000: its virtual page is 0x12 and its byte offset is 0x345. The offset is 837 bytes, safely below 4,096.
Multiply frame 0xAB by 0x1000 to get physical base 0xAB000, then add 0x345. The translated byte address is 0xAB345 if the requested access has permission.
The 8 MiB range contains 8 × 1,048,576 / 4,096 = 2,048 base pages. Its entries contain 2,048 × 8 = 16,384 bytes. Because the start is aligned to each leaf table's 2 MiB coverage, exactly four fresh 4 KiB leaf-table pages suffice, excluding upper levels. A merely 4 KiB-aligned start can straddle five such table pages.
Address translation preserves 0x345, while the table-storage estimate depends on how mappings are represented rather than just how many bytes the application requested.
The living notebook
Explore the model
Interactive lab · probability
A miss is not yet a fault
Set binomial success probability p=0.8 and trial count n=20. Predict sixteen modeled translation-cache hits, then compare with p=0.5. Independence and a constant hit probability are teaching assumptions; this is not a TLB, page walker, or MMU simulator.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA cache-hit model can count expected misses but cannot determine whether a miss reaches a valid resident mapping.
Pause & reason
Check your understanding
Your turn
Try it yourself
With 16 KiB base pages and eight-byte leaf entries, how many entries fit in one leaf-table page, and how much virtual space do they cover?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
First divide table bytes by entry bytes; each entry then maps one base page.
Compare with the solution
16,384 / 8 = 2,048 entries. They cover 2,048 × 16,384 = 33,554,432 bytes, or 32 MiB, assuming a fully populated ordinary leaf table and ignoring architecture-specific reserved fields or alternative mapping formats.
Keep the idea
Take it with you
- Separate virtual page number from the byte offset.
- Hierarchies avoid allocating full leaf tables for every unused address range.
- A TLB miss, a page fault, and a storage read are different events.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.