What Is Virtual Memory?

Tanenbaum Chapter 3 (Sec 3.1 & 3.2): From manual overlays to automated virtual paging, direct mapping, and the principle of locality.

1. The Root of Memory Management: Detailed Mechanics of Manual Overlays

In early computing, physical memory (RAM) was strictly limited in capacity. If a mainframe computer had 64 KB of RAM, but a scientific simulation or database engine required 160 KB of code and data to execute, the program could never fit into hardware all at once.

To solve this without modern virtual hardware, programmers invented Overlays. The application was manually partitioned into independent modules that shared the exact same physical memory address space.

For example, a program might have a Resident Root (main loop and I/O handlers) occupying the bottom 24 KB of RAM permanently, leaving a shared upper region (e.g., addresses 0x6000 to 0xFFFF). When the program needed to perform complex math, it loaded Module A into that shared space. When it needed to generate a report, Module A was overwritten in place by Module B from disk or magnetic tape.

Figure 1: The 64 KB Physical RAM Partitioning in Overlay Systems Physical RAM (64 KB Total) Resident Root (Always in RAM) OS Kernels, I/O Handlers, Main Loop (24 KB) Shared Overlay Region (Addresses 0x6000 – 0xFFFF) Only ONE module can occupy this physical box at a time! Module A (Math Engine) or Module B (Report Writer)
Figure 2: Manual Overlay Swapping Sequence Disk / Storage Module B Module A 1. Overwrite RAM Overlay Box Module B (Replaced A) The Developer's Burden: If Module B needed to call Module A, the programmer had to manually manage disk swapping code in application logic.

2. The Evolutionary Bridge: From Manual Overlays to Paged Virtual Memory

While manual overlays worked, they placed an immense burden on human software engineers. As operating systems evolved, computer science progressed through three distinct generations of memory management:

Figure 3: The Historical Evolution of Memory Management 1. Manual Overlays • Managed by Programmer • Static shared code blocks High developer overhead 2. Process Swapping • Managed by OS Kernel • Whole programs to disk Requires contiguous RAM 3. Paged Virtual Memory • Hardware MMU + OS • Fixed 4 KB page swapping Fully transparent & flexible

3. Direct Comparison: How Paging Automates & Generalizes Overlays

Notice the profound structural similarity between manual overlays (Figure 1) and paged virtual memory (Figure 5 below). In both systems, physical memory is smaller than total code size, so blocks are swapped in and out from disk storage.

The difference is that virtual memory paging turns the rigid, manual overlay box into a dynamic, hardware-managed mapping array. Instead of the programmer declaring a single static overlay region, the MMU maps every virtual page independently to any physical frame on the fly.

Figure 5: From Static Overlays to Dynamic Virtual Pages pointing to Physical RAM Virtual Address Space (Program's Illusion) Virtual Page 0 Virtual Page 1 (Math) Virtual Page 2 (Report) Paged out to SSD Swap (Present = 0) Physical DRAM Frames Frame 0 ← Page 0 (Resident Root) Frame 1 ← Page 1 (Dynamic Overlay Box) SSD Swap Storage Page 2 Stored on Disk (Awaiting Page Fault)

4. How Virtual Memory Paging Automates Swapping

Virtual memory paging took the core concept of swapping—moving inactive blocks between RAM and disk—and automated it at the hardware level in units of small, fixed 4 KB pages.

When a CPU instruction tries to read a virtual address whose page is currently stored on SSD swap, the MMU detects that the PTE's Present bit is 0. The hardware triggers an immediate page fault exception. The operating system kernel intercepts this fault, selects an empty physical frame in DRAM (or evicts a cold page to swap), issues an asynchronous disk read to fetch the missing 4 KB page, updates the page table, and restarts the instruction—all without the application program ever knowing it happened.

Figure 6: The Hardware Address Translation Bridge Virtual Address Space Page 0 (Code) Page 1 (Data / Swap) Hardware MMU & Page Table Physical RAM (DRAM) Frame 12 (Mapped) Not in RAM (Fault!) SSD Swap Storage Page 1 on Disk

5. The Principle of Locality (Temporal vs. Spatial)

Virtual memory paging works so efficiently because real-world programs exhibit the Principle of Locality. Without this behavioral pattern, swapping 4 KB pages to disk would cause catastrophic performance degradation ("thrashing").

  • Temporal Locality: If a CPU accesses a memory address at time t, it is highly likely to access that exact same address again in the near future (e.g., loop control variables, active stack frames).
  • Spatial Locality: If a CPU accesses memory address X, it will likely access nearby addresses (X+1, X+2, etc.) shortly thereafter (e.g., looping through arrays or executing contiguous machine instructions).
Figure 7: Visualizing Temporal and Spatial Locality Temporal Locality (Reuse Over Time) Address 0x1004 Repeated Access (e.g., Loop Counter) Spatial Locality (Sequential Access) data[0] 0x2000 data[1] 0x2004 data[2] 0x2008 → CPU traverses adjacent addresses sequentially

6. Interactive Sandbox: Virtual-to-Physical Mapping & Swapping

Simulate a system with only 4 physical DRAM frames. Watch what happens when virtual memory requests exceed physical RAM capacity.

Physical DRAM Frames (4 Slots)
SSD Swap Partition (Overflow)