KatInterview

From Virtual Address to Physical Memory: A Full Walkthrough

System DesignModel answer
MediumModel answerSystem Designoperating-systemsvirtual-memoryTLB

Last updated

Trace every step a CPU takes to resolve a virtual address — TLB, page-table walk, MMU checks, page faults, and context-switch invalidation.

Virtual Address Resolution

Modern processes never see physical RAM directly. Instead, each process operates in its own private virtual address space, and the hardware translates every memory reference to a real location at runtime.

Suppose a process executes a load instruction targeting some virtual address. Walk through everything that happens between that instruction and the moment data arrives in a register.

What your answer should cover

  • How a virtual address is decomposed into page number and offset
  • The role of the Translation Lookaside Buffer (TLB) and what happens on a hit vs. a miss
  • How the Memory Management Unit (MMU) walks page tables when the TLB cannot satisfy a request
  • Permission and validity bits, and how the hardware uses them
  • The difference between a TLB miss (translation absent from the cache) and a page fault (page not resident or access is illegal)
  • What the operating system does when it handles a page fault
  • How address spaces are managed across context switches, including TLB invalidation
  • At least one performance-oriented topic: huge pages, Address Space Identifiers (ASIDs), or multi-core TLB shootdowns

Constraints and assumptions

  • Treat address translation and physical memory/cache access as two distinct stages — explain where the boundary is
  • Acknowledge that page-table depth, cache-access ordering (VIPT vs. PIPT), and shootdown protocols differ by architecture; you do not need to commit to one, but note that variation exists
  • A complete answer distinguishes a TLB miss from a page fault — they are not the same event

Clarifying questions worth raising

Before diving in, a strong candidate might ask:

  1. Should we assume a specific architecture (x86-64 4-level paging, ARMv8, RISC-V Sv48) or keep it architecture-agnostic?
  2. Is the target page resident in physical memory, currently swapped out, or entirely unmapped?
  3. Should the answer include multi-core scenarios such as TLB shootdowns on page-table updates?

Hints

Hint 1

Start from first principles: a virtual address has two logical parts. What are they, and what does each one tell the hardware?

Hint 2

A TLB miss and a page fault are handled by different actors — one is handled by hardware (or a hardware-triggered microcode walk), the other traps into the OS kernel. Be precise about which is which and when each occurs.

Hint 3

Think about what has to happen when the scheduler switches from process A to process B. The page tables change — what does that mean for the TLB, and how do ASIDs or PCIDs reduce the cost of that transition?