Interview Prep Zoneby CuriouserLabs

Question 1 of 5 · senior level

What is virtual memory, and what does that one layer of indirection actually buy us?

🎤 Say this first

Every process sees a private virtual address space; the MMU translates virtual→physical on every access using per-process page tables. That single indirection buys: isolation (you can't even express another process's address), the illusion of abundance (allocate 10GB on an 8GB machine — pages materialize on first touch), sharing (libc mapped once, visible everywhere; copy-on-write fork), swapping (RAM as a cache over disk), and simplicity (every program links at the same addresses). It's arguably the highest-ROI indirection in computing.

The full picture

🎬 Virtual memory: TLB, page tables and page faults

1 / 5
Virtual space (per process)page 0x4page 0x5page 0x6page 0x7MMU + TLBtranslates EVERY accessPage table0x4 → frame 0x9 ✓0x7 → —Physical RAM (frames)frame 0x8frame 0x9frame 0xAframe 0xBOne indirection buys isolation, overcommit, swapping, sharing and COW — the OS's best trade ever.

The process uses VIRTUAL addresses — a private, contiguous-looking address space. Physical RAM is a shared pool of page frames. The MMU translates every single memory access.

TLB hit, table walk, and the page fault — the three speeds of a memory access.
  • Mechanically: address = virtual page number + offset; page table maps VPN→physical frame; pages are 4KB (or 2MB/1GB huge pages). Permissions (r/w/x) ride on the page table entry — that's how W^X and read-only .text are enforced.
  • Overcommit is policy, not accident: malloc/mmap hand out address space; RAM is committed on first touch (a minor fault). The bill can arrive later as the OOM killer — allocation success ≠ memory availability.
  • Address space layout: text, data, heap growing up, stacks, mmap region, kernel space at the top of the address space — plus ASLR shuffling bases as an exploit-mitigation.
  • JVM lens: -Xmx reserves virtual space (cheap); RSS grows as the heap is touched — why a freshly started JVM with a 30GB Xmx shows small RSS, and why 'VIRT' in top scares people needlessly.

🔄 Likely follow-up questions

  • What's the difference between VIRT/RSS/PSS in process memory accounting?
  • How does mmap of a file differ from read() into a buffer?
  • Why do 64-bit address spaces make ASLR and large heaps practical?