KatInterview

Load Instruction Walkthrough: TLB Miss, Page Walk, L1 Cache Hit

System DesignModel answer
MediumModel answerSystem Designvirtual-memorytlbpage-table

Last 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

  1. 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.
  2. Load trace. A load executes 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.
  3. 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.