Why is the default swappiness 60? What would be the effect if I lower the swappiness value for my desktop PC?

Your premise is wrong. There is no 'good for servers' swapiness value.

Swapiness is the amount of swapping that is done, especially how aggressively you swap. For my servers the swappiness is close to zero, as I make damn sure they have memory enough for everything. There is no 'best for servers' value. there is 60, which is the default, and then there is "your value" which depends on usage and available memory.

If you have servers that sometimes use LOADS of memory, you could have them higher than default, but I would say that some servers (database servers?) might want to keep them way lower than a home computer would.


The swappiness value is scaled in a way that confuses people. They see it has a range of 0-100 so they think of percent, when really the effective minimum is around 50.

60 roughly means don't swap until we reach about 80% memory usage, leaving 20% for cache and such. 50 means wait until we run out of memory. Lower values mean the same, but with increasing aggressiveness in trying to free memory by other means.

The describe it pretty well at http://lwn.net/Articles/83588/


The swappiness setting is a tweak to the way Linux calculates the benefits/drawbacks to swapping in a particular scenario. A high swappiness will not cause the system to swap when it doesn't need to, and a low swappiness, providing you don't disable swapping completely, will not prevent your system from swapping when it absolutely has to.

The default swappiness of 60 or so is a very good compromise ensuring good performance of your system by ensuring it is not struggling too hard to allocate cache memory while there is unused allocated program memory.

Remember that if you have plenty of RAM for all your processes plus cache, which should usually be the case if you have plenty of physical RAM, swapping should not be an issue for you anyway. The preferred way to fix issues of too much swapping is to decrease RAM use by processes, and/or to increase physical RAM. Reducing swappiness will have a negative effect if what you really need is more RAM.

Please see the answer I wrote to a very similar question:

https://askubuntu.com/a/184221/54256

Excerpt:

Why most people recommend to reduce swappiness to 10-20?

Because most believe that swapping = bad and that if you don't reduce swappiness, the system will swap when it really doesn't need to. Neither of those are really true. People associate swapping with times where their system is getting bogged down - however, it's mostly swapping because the system is getting bogged down, not the other way around. It's true that there are certain times when swapping can have a noticeable performance penalty, but the system will have already factored that in to its decision to swap, and decided that not doing so would have a greater overall penalty in system performance or stability which may later become noticeable. Overall the default settings should result in the best overall performance and reliability. I'd recommend leaving it at the default.

...

Once you have used up enough memory that there is not enough left for a smooth-running cache, Linux may re-allocate some unused application memory from RAM to swap.

It doesn't do this according to a definite cutoff though. It's not like you reach a certain percentage of allocation then Linux starts swapping. It has a rather "fuzzy" algorithm. It takes a lot of things into account, which can best be described by "how much pressure is there for memory allocation". If there is a lot of "pressure" to allocate new memory, then it will increase the chances some will be swapped to make more room. If there is less "pressure" then it will decrease these chances.

Your system has a "swappiness" setting which helps you tweak how this "pressure" is calculated. It's normally not recommended to alter this at all, and I would certainly never recommend you alter it. Swapping is overall a very good thing - any occasional performance penalties are intended to be offset by a gain in overall system responsiveness and stability for a wide range of tasks. If you reduce the swappiness, you let the amount of cache memory shrink a little bit more than it would otherwise, even when it may really be useful. You therefore risk slowing down your computer in general, because there is less cache, while memory is being taken up by applications that aren't even using it. Whether this is a good enough trade-off for whatever specific problem you're having with swapping is up to you. If you go further than this and actually disable swapping, you risk system instability in the event that the system runs out of memory for processes.

What is happening when the system is bogged down and swapping heavily?

A lot of the time people will look at their system that is thrashing the disk heavily and using a lot of swap space and blame swapping for it. That's the wrong approach to take. If swapping ever reaches this extreme, it means that your system is extremely low in memory and the swapping is the only thing keeping it from crashing or killing processes randomly. Without swapping, in this situation, processes will crash and die. The swapping is a symptom of a deeper problem. In a system with enough memory for all its tasks, swapping only ensures that memory is utilised in efficient ways, dealing out memory to the cache over dormant processes where it sees it will be worth it. In a system where swapping is relentlessly thrashing the disk, it's not swapping's fault.

When choosing what is to be swapped to disk, the system tries to pick memory that is not actually being used - read to or written from. It has a pretty simple algorithm for calculating this that chooses well most of the time.

...

But how can swap speed up my system? Doesn't swapping slow things down?

The act of transferring data from RAM to swap is a slow operation, but it's only taken when the kernel is pretty sure the overall benefit will outweigh this. For example, if your application memory has risen to the point that you have almost no cache left and your I/O is very inefficient because of this, you can actually get a lot more speed out of your system by freeing up some memory, even after the initial expense of swapping data in order to free it up.

Feel free to read the whole post at https://askubuntu.com/a/184221/54256

Tags:

Swap