Virtual Memory

Virtual memory is the hardware-software mechanism that gives every process the illusion of a private, contiguous address space spanning terabytes — even though physical RAM is shared, fragmented, and far smaller — by translating virtual addresses to physical addresses through page tables managed by the OS and enforced by the MMU (memory management unit) in hardware. Virtual memory enables process isolation (one process cannot access another's data), overcommitment (allocate more memory than physically exists), memory-mapped files, and demand paging (load only what's needed). Every modern processor — from phone SoCs to AI servers — implements virtual memory.

How it works — address translation. When a program accesses address 0x7FFF_1234_5678, the MMU splits it into a page number + offset, walks the multi-level page table (4 or 5 levels on x86-64), and produces the physical address. If the page is not in RAM (page fault), the OS loads it from storage (swap or file). This happens on every memory access — so it must be fast:

$$\text{Virtual address} \xrightarrow{\text{TLB/page table}} \text{Physical address}$$

The Translation Lookaside Buffer (TLB) caches recent translations so >99% of accesses resolve in 1 cycle without walking the page table.

Page table structure (x86-64, 4-level):

LevelBits usedEntriesEach entry coversName
PML4 (L4)[47:39]512512 GBPage map level 4
PDPT (L3)[38:30]5121 GBPage directory pointer
PD (L2)[29:21]5122 MBPage directory
PT (L1)[20:12]5124 KBPage table
Offset[11:0]—1 byte (within 4 KB page)—

Total addressable: 2⁴⁸ bytes = 256 TB of virtual space per process (5-level paging extends to 2⁵⁷ = 128 PB).

TLB — the critical performance structure. A full page-table walk takes 4 memory accesses (one per level) × ~5 ns each = 20 ns penalty. The TLB caches 64–4096 recent translations in a small, fast associative array:

TLB typeEntriesPage sizeHit rateMiss penalty
L1 ITLB64–1284 KB>99%~7 cycles (L2 TLB)
L1 DTLB64–964 KB>99%~7 cycles
L2 STLB (unified)1024–40964 KB / 2 MB>99.9%~20 ns (page walk)
Huge-page TLB32–642 MB or 1 GB~100% (AI workloads)—

Huge pages — why AI workloads need them. A 80 GB HBM allocation at 4 KB pages requires 20 million page-table entries and 20 million TLB slots (impossible — TLBs are small). At 2 MB huge pages: only ~40,000 entries. At 1 GB pages: only 80 entries — fits entirely in the TLB with zero misses. This is why AI frameworks (PyTorch, JAX) and GPU drivers use huge pages for pinned memory: eliminating TLB misses on the massive tensor allocations that dominate AI workloads.

Virtual memory for GPU and AI chips:

  • CPU MMU: full virtual memory — page tables in DRAM, hardware page-table walker, 4-level or 5-level, demand paging, copy-on-write.
  • GPU (NVIDIA): separate GPU page tables managed by the driver. Unified Virtual Memory (UVM) allows CPU and GPU to share a virtual address space — the driver migrates pages between CPU DRAM and GPU HBM on demand (but at high cost; explicit placement is preferred for performance).
  • AI ASIC (TPU): minimal or no virtual memory — DMA addresses are physical or use a simple IOMMU. The software runtime manages all allocation explicitly.

Page faults and demand paging. When a virtual page has no physical mapping (first access, swapped out, or memory-mapped file), a page fault triggers:
1. CPU traps to the OS kernel
2. OS determines the cause (valid fault → allocate page; invalid → segfault/kill)
3. OS finds a free physical frame (or evicts one to swap)
4. OS fills the page (zeroed, from file, from swap)
5. OS updates the page table, returns to user — process resumes

A page fault takes ~1–10 microseconds — acceptable for rare events, catastrophic if frequent (thrashing). AI training avoids this by pinning all memory upfront.

Virtual Memory Technical Microarchitecture Detailed Domain Pipeline, Architectural Blocks & Engineering Performance Optimization (ID 100197) 1. Fetch & Decode Instruction Fetch (IF) PC Generator & L1 I-Cache Branch Predictor Gshare / TAGE & BTB Instruction Decode (ID) Register Rename & ROB Width: 4-Way Superscalar 2. Execution Engine ALU Cluster (INT) Single-Cycle Arithmetic & Shifts FPU / SIMD Engine 256-bit Vector FMA Pipelines Load / Store Queues Out-of-Order Memory Disambiguation 3. Memory & Writeback L1 D-Cache & TLB 32KB 8-Way Set Assoc Hit Latency: 4 Cycles L2 / L3 Cache Controller Inclusive/Non-Inclusive Hierarchy MESI Coherence Protocol In-Order Retirement Commits Architectural State Key Insight: Optimal Virtual Memory architecture balances performance throughput, systemic latency, and physical constraints. Technical specification & verification reference for Virtual Memory (Row ID 100197)

Virtual memory and the CFS platform. Virtual memory is the OS abstraction that lets multiple processes share hardware safely. The CFS operating-system keyword covers the broader OS context; the memory-hierarchy keyword covers the physical storage layers that VM maps onto; and the cache-coherence keyword covers how multiple cores agree on the contents of shared physical addresses that VM translates to.

Take virtual memory further

Ask the copilot about this term, or have our engineers assess it against your process.