Ramblings of an aging IT geek
← Ramblings of an aging IT geek
linux

how much swap, and why i stopped arguing about it

After years of dogmatic swap opinions I settled on a small, deliberate swap setup for my homelab boxes and tuned swappiness to match.

A Linux terminal

Every so often someone declares, with great confidence, that swap is obsolete. You have plenty of RAM, the argument goes, so just turn it off. I've held that view myself. I've also watched a box with no swap fall straight off a cliff into the OOM killer the moment something briefly overcommitted, with no warning and no grace, so I've come round.

Here's where I landed for the homelab. Every box gets a small swap, a couple of gigabytes, regardless of how much RAM it has. Not because I expect to page heavily into it, I very much don't, but because a little swap gives the kernel somewhere to evict genuinely cold pages so the page cache and the actually-hot stuff have more room. With zero swap the kernel has to keep every anonymous page resident even if it hasn't been touched in days.

Then I set vm.swappiness low, 10 rather than the default 60, so the kernel only reaches for swap when it's actually under memory pressure rather than pre-emptively:

# /etc/sysctl.d/99-swap.conf
vm.swappiness = 10

The result is a system that uses swap as the safety valve it's meant to be, not as primary storage. On a healthy day these boxes show a few megabytes in swap and never touch it again. On a bad day, swap buys me the minutes I need to notice, rather than the OOM killer silently shooting whatever was largest.

So that's settled, for me at least. A small swap, low swappiness, and proper memory alerting so I see pressure before the kernel has to make decisions on my behalf. The debate was never really about whether swap is good. It was about what you want to happen at the edge, and I'd rather have a margin than a cliff.