Swapping and Backing Store
What you'll learn: How the operating system moves entire pages between RAM and disk to support virtual memory larger than physical memory.
The Core Idea
When physical RAM fills up, the OS must make room for new pages. Swapping is the process of moving pages from RAM to disk storage (called the backing store or swap space) and bringing them back when needed. This allows the system to run programs whose combined memory demands exceed the actual RAM available.
Think of RAM as your desk and the backing store as a filing cabinet. When your desk gets cluttered, you move papers you're not currently using to the cabinet. When you need them again, you pull them out and may have to file something else away.
How It Works
When a page fault occurs for a page that's been swapped out:
- The MMU triggers a page fault (the page is marked as "not present")
- The OS locates the page on disk using metadata in the page table
- The OS finds a free frame in RAM (possibly evicting another page first)
- The disk controller reads the page from backing store into RAM
- The page table is updated with the new physical address
- The faulting instruction restarts
The backing store is typically a dedicated disk partition or file reserved for this purpose. It must be fast enough to avoid severe performance degradation.
Why It Matters
Swapping enables overcommitment of memory—running more processes than physical RAM could hold simultaneously. The OS bets that not all pages will be needed at once. However, excessive swapping (called thrashing) can grind the system to a halt when the disk becomes the bottleneck.
Key Takeaway: Swapping uses disk storage as an extension of RAM, moving inactive pages to backing store and retrieving them on demand, enabling virtual memory to exceed physical memory capacity.