Load Instruction Walkthrough: TLB Miss, Page Walk, L1 Cache Hit
System DesignModel answerLast updated
Decode a 48-bit virtual address under 4-level paging, trace a load through a TLB miss and page walk to an L1 hit, and say where read permission is checked.
Setup
A machine uses these memory parameters:
- 48-bit virtual addresses
- 4 KB pages
- Four-level hierarchical page tables, with 9 virtual-address bits used to index each level
- 40-bit physical addresses
- 8-byte page table entries (PTEs)
- At the start of the scenario the TLB is cold (empty) and the L1 data cache is warm (it already holds the target line)
Questions
- Address layout. How are the 48 virtual-address bits divided? Give the number of bits and the bit positions for the page offset and for the L4, L3, L2 and L1 indices. Explain why each index is 9 bits wide.
- Load trace. A
loadexecutes and misses in the TLB, but the data is already in the L1 data cache. Walk through what happens in order. Say which hardware unit performs the translation, how the final physical address is built, and keep translation hit/miss clearly separate from cache hit/miss. - Permission check. At which point in this flow does the hardware decide whether the current process may read this page?
Worked example
The program loads from virtual address 0x000012345678.
- Show how the MMU slices this address into fields to begin the walk, and the byte offset it reads inside each table.
- Suppose the leaf PTE has its read permission bit cleared (R = 0). What exception results, and at what stage of the instruction's execution is it detected and taken?
Hints
Hint 1
A 4 KB table of 8-byte entries holds exactly 512 entries, which tells you how many index bits each level needs. The page offset takes the low 12 bits, and the other 36 bits are the virtual page number.
Hint 2
The TLB caches translations and the data cache holds data. A TLB miss triggers a hardware page walk of up to four dependent reads starting from the root-table register. After the walk, the physical address is the frame number joined to the untouched 12-bit offset, and only then can the L1 tag compare complete.
Hint 3
The permission bits live in the PTE, so they can only be checked once the leaf entry is available, either at the end of the walk or from the cached TLB entry on a later hit. A violation raises a precise page fault at retirement, so the loaded value must never reach the register file.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Bit layout
A 4 KB page is 2^12 bytes, so the page offset is 12 bits. The remaining 48 − 12 = 36 bits form the virtual page number (VPN). Four levels share those 36 bits, giving 9 bits each.
The 9-bit width follows from the table size. One table occupies one 4 KB page, and with 8-byte entries it holds 4096 / 8 = 512 = 2^9 entries. A 9-bit index therefore addresses every slot exactly.
| Bits | Field |
|---|---|
| 47–39 | L4 index (root) |
| 38–30 | L3 index |
| 29–21 | L2 index |
| 20–12 | L1 index (leaf table) |
| 11–0 | Page offset |
The physical address has 40 bits, so the physical frame number (PFN) is 40 − 12 = 28 bits. The final address is (PFN << 12) | offset.
2. Decoding 0x000012345678
- Offset:
0x678 - L1 index:
(VA >> 12) & 0x1FF=0x12345 & 0x1FF=0x145(325) - L2 index:
(VA >> 21) & 0x1FF=0x091(145) - L3 index:
0 - L4 index:
0
Each index is multiplied by 8 to get a byte offset in its table:
| Level | Entry location |
|---|---|
| L4 | root base + 0 |
| L3 | L3 base + 0 |
| L2 | L2 base + 0x91 × 8 = base + 0x488 |
| L1 | L1 base + 0x145 × 8 = base + 0xA28 |
def split_va(va: int) -> dict:
assert 0 <= va < (1 << 48)
return {
"L4": (va >> 39) & 0x1FF,
"L3": (va >> 30) & 0x1FF,
"L2": (va >> 21) & 0x1FF,
"L1": (va >> 12) & 0x1FF,
"offset": va & 0xFFF,
}
def build_pa(pfn: int, offset: int) -> int:
assert 0 <= pfn < (1 << 28) and 0 <= offset < (1 << 12)
return (pfn << 12) | offset
print(split_va(0x000012345678))
# {'L4': 0, 'L3': 0, 'L2': 145, 'L1': 325, 'offset': 1656}
3. Trace: TLB miss, L1 data hit
- Address generation. The load unit computes the virtual address from base register plus displacement.
- TLB probe (miss). The data TLB is searched with the VPN (and the address-space tag such as ASID/PCID). The TLB is cold, so it misses, and a second-level TLB would miss too. This is only a translation miss. It says nothing about whether the data is cached.
- Hardware page walk. The MMU's page-table walker takes over (on x86 and ARM this is hardware, not the OS):
- Read the root table's physical address from the root register (CR3 on x86, TTBR on ARM,
satpon RISC-V). - Read the L4 entry at index 0, check that it is present, and extract the next table's frame number.
- Repeat for L3[0], L2[0x91], and finally L1[0x145].
- Each step is a physical memory read that can itself be served by the data caches, and paging-structure caches may let the walker skip upper levels. The worst case is four dependent reads.
- Read the root table's physical address from the root register (CR3 on x86, TTBR on ARM,
- Leaf PTE handling. The walker obtains the 28-bit PFN and the permission bits (read/write/execute, user/supervisor, no-execute), updates the accessed bit if needed, and runs the permission check described below.
- TLB fill. The VPN-to-PFN mapping and its permissions are installed in the TLB, so later accesses to this page hit.
- Physical address formation.
PA = (PFN << 12) | 0x678. The offset is never translated. - L1 data cache lookup (hit). The physical tag derived from the PA matches a line in the indexed set, which is a cache hit. The data returns in a few cycles and the load completes.
Two points deserve emphasis:
- Most L1 caches are virtually indexed, physically tagged. With 64-byte lines and 64 sets, the set index uses bits 11:6, which lie inside the page offset, so the set can be selected while the TLB is still working. The hit/miss decision, though, needs the physical tag, so the cache result cannot be trusted until the walk finishes.
- The cost of this load is roughly the walk latency (tens to hundreds of cycles depending on where the table entries are cached) plus the few cycles of the L1 hit. A warm cache does not hide a cold TLB.
4. Where read permission is enforced
Permission is checked during translation, as soon as the leaf PTE is available:
- on a TLB miss, at the end of the page walk, and
- on a TLB hit, from the permission bits stored in the TLB entry.
In both cases it happens before the loaded value is architecturally delivered. The hardware verifies that the entry is present/valid, that read access is allowed, that the user/supervisor bit matches the current privilege level (plus protections such as SMAP/PAN), and that no reserved bits are set. Many designs combine the rights from all levels, so a restriction at any level applies.
Example with R = 0 in the leaf PTE. The MMU raises a page fault:
| Architecture | Exception |
|---|---|
| RISC-V | Load page fault (cause 13) |
| ARM | Data abort, permission fault |
| x86 | #PF, with an error code separating not-present from protection violation (x86 has no separate read bit; any present page is readable) |
It is detected in the memory-access stage once the translation result is known, and reported as a precise exception. The faulting instruction is taken at retirement, younger instructions are squashed, and the faulting virtual address is saved (CR2, stval, or FAR). The data must not be written to the register file, even though the line sits in L1. The Meltdown vulnerability came from hardware that let dependent instructions use that data transiently before the fault took effect.
5. Common mistakes
- Claiming the cache hit is known from the virtual address alone. The tag comparison needs the physical address.
- Treating a TLB miss as a cache miss, or sending the data fetch to DRAM after a TLB miss.
- Wrong index widths, or forgetting to multiply by the 8-byte entry size.
- Saying the OS performs the walk on x86 or ARM. The OS only handles the fault if the walk fails.
- Treating the root-table register as holding a virtual address. It holds a physical one.
- Checking permissions only in the OS. The hardware enforces them on every access.
6. Likely follow-ups
- 2 MB huge pages. The L2 entry becomes the leaf (page-size bit set), the walk takes three levels, and the offset grows to 21 bits. One TLB entry covers 512 times more memory, increasing TLB reach, at the cost of internal fragmentation and the need for contiguous physical memory. 1 GB pages shorten the walk further.
- Context switch. Changing the root register flushes non-global TLB entries unless entries are tagged with ASID/PCID, which avoids most flushes. Global kernel mappings can stay.
- Reducing walk cost. Paging-structure caches, caching PTEs in the data cache, and huge pages all shorten or speed up walks.