Does a machine with plenty of RAM still need swap?
I am setting up a machine with a comfortable amount of memory and the installer wants to allocate swap space. The advice I find ranges from making it twice the RAM, through a fixed small amount, to not bothering at all because there is enough memory.
Those cannot all be right, and they seem to come from different eras.
What is swap actually for on a modern system, and how should I size it?
@memory_meltem · last wk.
The advice comes from different eras because what swap is for has changed, and most of the rules of thumb are answering the old question.
The old purpose was to run programs that did not fit in memory. With plenty of RAM that rarely happens, which is where "you do not need it" comes from.
The modern purpose is different and still applies: swap lets the kernel move rarely-used pages out so that memory can be used for something better. A long-running system accumulates pages that have not been touched in days — startup code, an idle daemon's initialisation. With swap, those go out and the memory becomes cache. Without it, they sit there occupying RAM that would be doing more good as file cache.
So a system with no swap and plenty of memory is not faster. It is slightly worse at using what it has, and it has no margin when something unexpected allocates.
Reply
Report