Using Disk as RAM
Physical RAM is limited. What happens when you fill up your 8GB of RAM, but processes keep asking for more?
Linux uses Swap — a dedicated space on your storage device (either a dedicated partition or a swap file) that acts as overflow RAM. Think of it like a hotel that's fully booked: when all rooms are taken, guests are redirected to a nearby overflow motel. It works, but it's slower and less convenient.
When RAM gets full, the kernel's page reclaim mechanism identifies pages that haven't been accessed recently. It writes those pages to the swap area and marks the corresponding page table entries as "not present." The physical RAM frame is now free for something else.
If a process later needs that swapped-out data, a major page fault occurs, and the kernel reads the page back from swap into RAM — potentially evicting another page to make room.
Swap on SSDs vs. HDDs
The performance penalty of swap depends heavily on your storage:
- HDD swap: Catastrophic for performance. Random I/O on spinning disks is ~100x slower than RAM.
- SSD swap: Painful but survivable. SSDs are ~10x slower than RAM for random reads, but orders of magnitude faster than HDDs.
- NVMe swap: Tolerable for brief bursts. NVMe SSDs can reach ~1/3 of RAM bandwidth for sequential reads.
Swap in containerized environments: Many Kubernetes deployments disable swap entirely (swapoff -a) because the kubelet historically required it to be disabled for predictable memory accounting. Kubernetes 1.28+ introduced experimental swap support for Linux nodes, but it remains non-default.
Current swap usage is visible via swapon --show, and /proc/swaps reports the same information from the kernel's perspective.