How to configure swappiness in Linux Memory Management?

38,327

Solution 1

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

Solution 2

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.

Solution 3

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.

Share:
38,327

Related videos on Youtube

GAD3R
Author by

GAD3R

Updated on September 18, 2022

Comments

  • GAD3R
    GAD3R over 1 year

    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?

  • techraf
    techraf about 8 years
    How does it answer "how to configure that to improve overall performance ?"
  • Keyshov Borate
    Keyshov Borate about 8 years
    @techraf updated the answer.
  • AReddy
    AReddy about 8 years
    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.
  • pkaramol
    pkaramol over 6 years
    Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?
  • Rui F Ribeiro
    Rui F Ribeiro over 5 years
    In VMs I do advise nonetheless changing it to 10 just in case.