Swapping: Mechanisms

Chapter 21's key idea: physical memory doesn't have to hold every page a process owns. The OS reserves a slice of disk as swap space and moves pages back and forth between it and physical frames, so address spaces can be bigger than RAM. This tool follows the mechanism end to end — where a page can live, and what happens when the hardware reaches for one that isn't there.

Reserve some space on the disk

  • The OS carves out a chunk of disk for moving pages back and forth — the swap space.
  • It remembers what lives there in page-sized units, the same granularity as a physical frame.
  • A page is either resident (has a valid PFN) or swapped out (has a disk address instead) — a PTE needs a bit to say which.

Click any frame or swap block below to see the page-table entry it corresponds to.

Proc 0 Proc 1 Proc 2 Proc 3 Free

Physical Memory

PFN 0 – 3

Swap Space

Block 0 – 7

Pick a frame or a swap block above to inspect its page-table entry.

Every page, one page table

Same four processes, all their pages. Whether a page is in memory or on disk is just one more field in its PTE — the process never notices which.

ProcessVPNPresentLocation

Swap space lets the sum of every process's address space exceed physical memory — the trade-off is that reaching for a swapped-out page now costs a disk access.