Virtual Memory and Paging

College Depth 65 in the knowledge graph I know this Set as goal
Unlocks 14 downstream topics
virtual-memory paging page-table TLB address-translation

Core Idea

Virtual memory gives each process the illusion of a private, contiguous address space larger than physical RAM. The virtual address space is divided into fixed-size pages; corresponding physical memory units are called frames. A page table maintained by the OS and hardware maps virtual page numbers to physical frame numbers. The Translation Lookaside Buffer (TLB) caches recent page table entries to speed up address translation. Pages not in physical memory are stored on disk and fetched on a page fault.

How It's Best Learned

Trace the full address translation path: virtual address → TLB lookup or page table walk → physical address → cache lookup → memory. Simulate page replacement policies on a small address sequence. Understand the page fault handler's role in the OS.

Common Misconceptions

Explainer

From your study of the memory hierarchy, you understand that faster memory is smaller and more expensive, while slower memory is larger and cheaper. Virtual memory extends this principle one level further: it uses main memory (DRAM) as a "cache" for an even larger and slower storage level — the disk. But virtual memory does far more than just expand capacity. It gives each running process the illusion that it has the entire address space to itself, completely isolated from every other process. This abstraction is so foundational that virtually every modern operating system depends on it.

The mechanism works by dividing the virtual address space into fixed-size chunks called pages (typically 4 KB) and physical memory into same-sized chunks called frames. A data structure called the page table, maintained by the operating system, maps each virtual page number to a physical frame number. When a program accesses memory address 0x7FFF0042, the hardware splits this into a virtual page number and an offset within that page. It looks up the page number in the page table to find which physical frame holds that page, then combines the frame number with the offset to form the actual physical address. The program never knows or cares where its data physically resides — it works entirely in virtual addresses.

Because the page table can be enormous (a 48-bit virtual address space with 4 KB pages has billions of entries), walking through it on every memory access would be devastatingly slow. The Translation Lookaside Buffer (TLB) solves this by caching recently used page table entries in a small, fast hardware structure — typically 64 to 1024 entries with sub-nanosecond access time. Thanks to locality, most accesses hit the TLB, and the full page table walk is only needed on a TLB miss. This is the same caching principle you learned in the memory hierarchy, now applied to address translation itself.

When a program accesses a page that is not currently in physical memory — perhaps it was swapped to disk to make room for another process — a page fault occurs. The hardware traps to the operating system, which finds the page on disk, loads it into a free frame (evicting another page if necessary, using replacement policies similar to those you studied for caches), updates the page table, and restarts the instruction. This is expensive — disk access is millions of times slower than DRAM — but it happens rarely in well-behaved programs because locality keeps the working set of actively used pages small enough to fit in physical memory. The genius of virtual memory is that it makes the common case fast (TLB hit, page in memory) while gracefully handling the uncommon case (page fault) through a transparent software mechanism that the program never sees.

Practice Questions 5 questions

Prerequisite Chain

Counting to 10Counting to 20Understanding ZeroThe Number ZeroCounting to FiveOne-to-One CorrespondenceCombining Small Groups Within 5Addition Within 10Addition Within 20Two-Digit Addition Without RegroupingTwo-Digit Addition with RegroupingAddition Within 100Repeated Addition as MultiplicationMultiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Two-Digit by One-Digit DivisionDivision with RemaindersRemainders and Quotients in DivisionDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueReading and Writing DecimalsComparing and Ordering DecimalsAdding and Subtracting DecimalsMultiplying DecimalsDividing DecimalsDividing FractionsMixed Number ArithmeticOrder of OperationsOperators and ExpressionsArithmetic Operators and Operator PrecedenceComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsCombinational Circuit DesignFlip-Flops and LatchesBinary Counters: Design and AnalysisBinary ArithmeticFixed-Point Number RepresentationTwo's Complement RepresentationOverflow and Underflow DetectionBinary Adders: Half-Adders and Full-AddersFull Adder and Carry PropagationCarry Lookahead Adder DesignHalf Adder Circuit DesignMultiplication Circuit DesignSequential Circuit DesignRegisters and Register FilesInstruction Set Architecture (ISA)Assembly Language BasicsMemory Organization and AddressingMemory HierarchyCache Memory DesignCache Replacement PoliciesVirtual Memory and Paging

Longest path: 66 steps · 239 total prerequisite topics

Prerequisites (3)

Leads To (4)