Linux performance: why you should almost always add swap space
- The SWAP space is for data that is very rarely used. Pushing stuff there is made when the system is idle and has low CPU cost.
Mon Aug 28 11:51:33 2017 - permalink -
- Having a SWAP area can prove useful even on hosts having plenty of RAM, since it frees some RAM for frequently-used data.
- Without SWAP, highly stressed hosts may, when their RAM is full, use the Out-Of-Memory Killer (OOM-Killer), with undesired effects. Indeed, the OOM-Killer targets the most RAM-hungry processes. However, this shouldn't happen on a properly monitored host.
==> having / not having SWAP space (as well as having GB of RAM) is not the silver bullet of server performance. You'll have to understand what's going on, get metrics, act accordingly and check metrics.
Amount of swap (empiric method) :
RAM < 4GB : 1.5x RAM
4GB < RAM < 8GB : 1x RAM
8GB < RAM < 16 GB : 0.5x RAM
RAM > 16 GB : 8GB (SSD) or 4GB (rotating HDD)
==> Linux lets you decide whether you want it or not to use the swap space, so configure the swap space during the OS install, configure it, and you'll be able to disable/tune it later.