11

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. What is the default setting and how to configure that to improve overall performance?

6

The Linux kernel provides a tweakable setting that controls swappiness

$ cat /proc/sys/vm/swappiness
60  

open /etc/sysctl.conf as root. Then, change or add this line to the file:

vm.swappiness = 10

for changing the swappiness value temporarily try this command:

$ echo 50 > /proc/sys/vm/swappiness
  • 1
    How does it answer "how to configure that to improve overall performance ?" – techraf Feb 25 '16 at 12:10
  • Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day. – Mongrel Feb 25 '16 at 12:22
  • 1
    Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect? – pkaramol Jan 15 '18 at 11:31
11

From Swappiness, Wikipedia

You could set this value in a virtual file /proc/sys/vm/swappiness The mentioned value will be deciding how the swap space should be used, below are the values with their intents.

vm.swappiness = 0   # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
vm.swappiness = 1   # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
vm.swappiness = 10  # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected. 
vm.swappiness = 60  # The default value.
vm.swappiness = 100 # The kernel will swap aggressively.

Although it actually depends upon the need too, if the physical memory available is sufficient, there may not be a great need of swap space, in Layman's terms there won't be a need of changing the default value of 60.

  • @techraf updated the answer. – Keyshov Borate Feb 25 '16 at 12:15
  • 1
    In VMs I do advise nonetheless changing it to 10 just in case. – Rui F Ribeiro Oct 30 '18 at 17:38
2

In RedHat/CentOS the default value is 60.
"In order to improve performance" is very broad term. What performance are you trying to improve?

Do you have issues with low memory?
Does your system SWAP when there's still free memory/cached memory?

In Linux free RAM = wasted RAM, so almost all free memory is used for disc caches.
There are cases with swappiness=60 where pages in memory are moved to SWAP if they haven't been accessed for extended time periods, no matter you have unallocated RAM.
Moving some memory pages to SWAP is not necessary a bad thing.

Please shed some more light on your issue for more detailed answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.