Linux Swap Space
You should almost always add swap space to Linux servers
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on physical drives, which have a slower access time than physical memory.
There are performance benefits when swap space is enabled, even when you have more than enough ram
If you don’t have enough memory, swap will be used quite often and noticeably more during any memory requirement spikes. If you don’t have enough memory and no swap space, this will often cause failure to allocate memory for requests needing more memory pages. As a last resort, the Kernel will deploy out-of-memory OOM killer to nuke high-memory processes (usually MySQL, java, etc.).
This article has a reference from Hayden James's Linux blog Why You Should Almost Always Add Swap Space.
For a more detailed look at Linux swap space, read the Swap Management and Page Frame Reclamation chapters from Kernel.org docs.
Last updated