Why is swappiness=10 recommended?
Solution 1:
swappiness=0
will wait to swap until it is absolutely necessary. Setting a moderate value like swappiness=10
will cause pages to be swapped from memory to disk somewhat more readily. This can prevent the need to swap a lot at once; such a need can introduce annoying delays.
In addition, often a process runs but does nothing for an extended time. Many daemons (background services) behave this way. You may have a background application that is left unused for a while. And these days some applications are implemented as multiple processes, like Chromium and Google Chrome, where each tab has a separate process behind it (not a separate thread, but a separate process). Setting swappiness
to a value like 10 makes it so these background tasks that are not being actively used are swapped to memory even when they could remain crammed in RAM. Then when a more actively used process needs to allocate more RAM, it can do so more quickly.
In conclusion, allowing processes to be swapped from RAM to disk earlier than necessary often confers a performance benefit and lower latencies when a process allocates memory. This is at the expense of the time it takes to swap the processes back. But this is usually done much less frequently than a process in active use allocates and releases memory, so the trade-off is often worthwhile.