RAM is limited and expensive. When all RAM is full, the OS needs somewhere to put inactive processes so active ones can continue running.
Swap space is a portion of the disk used as an extension of RAM — inactive pages are moved (swapped) from RAM to disk to free memory.
- RAM becomes full → OS selects inactive pages
- Pages are written to swap space on disk
- If swapped-out page is needed again, OS reads it back (page fault)
- Process continues as if nothing happened (transparent to process)
- Acts as overflow for RAM (allows more processes than physical RAM)
- Much slower than RAM (disk access is ~100,000x slower)
- Can be dedicated partition or swap file in file system
- Excessive swapping = “thrashing” (system becomes very slow)
- Built from: Disk Management, Paging
- Builds into: Virtual Memory
- Related: Page Fault, Thrashing
- Contrasts with: RAM (fast but limited vs slow but large)
- Swap on SSD wears out flash cells (limited write endurance)
- Too much swapping = thrashing (spending all time swapping, not working)
- Some systems allow disabling swap (risky — OOM killer may activate)