Hacker News new | ask | show | jobs
by SCdF 138 days ago
You should still use swap. It's not "2x RAM" as advice anymore, and hasn't been for years: https://chrisdown.name/2018/01/02/in-defence-of-swap.html

tl;dr; give it 4-8GB and forget about it.

1 comments

I've heard "square root of physical memory" as a heuristic, although in practice I use less than this with some of my larger systems.
The proper rule of thumb is to make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kill if a fast memory leak happens.
That's not so much a rule of thumb as an assessment you can only make after thorough experimentation or careful analysis.
It doesn't take that much experimentation, though. Either set up not enough swap and keep increasing it by a little bit until you stop needing to increase it, or set up too much, and monitor your max use for a while (days/weeks), and then decrease it to a little more than the max you used.
I went with "set up 0 swap" and then never needed to increase it. I built my PC in 2023, when RAM prices were still reasonable, stuck 128GiB of ECC DDR5 in, and haven't run into any need for swap. Start with 0, turn on zswap, and if you don't have enough RAM then make a swap file & set it up as backing for zswap.
You don't need "horough experimentation or careful analysis". Just keep free swap space below few hundred megabytes but above zero.
"Keep swap space below few hundred megabytes but above zero" is a good example of a rule of thumb.

"Make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kill if a fast memory leak happens" is not.