When-to-swap asks: I have heard that changing the swappiness of my system will improve performance. How does this work and what is a good setting for swappiness?
DistroWatch answers: Let us imagine for a moment that on our Linux system we have one large pool of memory and this pool is divided into two parts. One part of the memory pool is our machine’s RAM. RAM is very fast and in high demand, but there usually isn’t a lot of it. The other part of the memory pool is called swap space. Swap space resides on the hard disk which is slow and typically in low demand.
In an ideal situation we would have lots of RAM and everything we need, applications and files, would stay in RAM where it would be accessed amazingly quickly. However, since RAM is relatively small and the hard disk relatively large, not everything we need will fit into RAM. This means the Linux kernel needs to make some tough choices. When the operating system starts to run out of room in RAM should the Linux kernel keep copies of files in memory and send the applications we are using into the slower swap space? Or should the kernel keep our programs in memory and drop files that it has copied into memory for quick access? It’s a puzzle. Some applications will benefit from having files stored in RAM, but all processes (especially desktop programs we want to have respond quickly) will benefit from being kept in RAM too. Really, we want to rely on accessing the disk (and swap space) as little as possible.