Every so often someone tells me to turn off swap because I have plenty of RAM. They're missing what swap is actually for. Swap isn't a slower substitute for RAM you fall back on when you run out. It's a place for the kernel to park pages that nobody is using, so the RAM they were sitting in can go to something that is.
A long-running process accumulates pages it touched once at startup and never again. With swap, the kernel can quietly evict those cold pages to disk and reclaim the memory for page cache, which actually speeds things up. With swap off, those dead pages squat in RAM forever, and the kernel has less room to cache the files you're really using. So "no swap" can make a machine with spare RAM slower, not faster.
Here's where I've landed across the homelab:
- A small swap partition or file on every box, sized a few gigabytes. Not the old "twice your RAM" rule; that advice died with spinning disks and 1GB machines.
vm.swappiness = 10on the busy boxes, so the kernel prefers reclaiming page cache and only reaches for swap when it's genuinely useful. The default of 60 is fine for desktops, a bit eager for servers.- Swap on a partition where I can, because a swap file on btrfs is more faff than it's worth.
$ free -h
total used free shared buff/cache available
Mem: 31Gi 6.2Gi 1.1Gi 0.3Gi 24Gi 24Gi
Swap: 4.0Gi 128Mi 3.9Gi
That 128Mi of swap in use isn't a warning sign, it's the system working as intended: a handful of cold pages evicted so the 24Gi of buff/cache could grow. The day swap usage climbs and stays high under memory pressure, that's the kernel telling me I genuinely need more RAM. That signal is worth keeping. Turn swap off and you lose it: instead of graceful degradation and a clear warning, you get the OOM killer arriving without notice to shoot something important. I'll take the few gigabytes of disk.