Swappiness

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Swappiness is a Linux kernel parameter that controls the relative weight given to swapping out of runtime memory, as opposed to dropping pages from the system page cache. Swappiness can be set to values between 0 and 100 inclusive. A low value causes the kernel to avoid swapping; a higher value causes the kernel to try to use swap space. The default value is 60; setting it higher will increase performance of "hot" processes at the cost of making a return to inactive "cold" ones take a long pause, while setting it lower (even 0) may decrease response latency. Systems with more than adequate RAM for any expected task may want to drastically lower the setting.[1]

Value Strategy
vm.swappiness = 0 Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, when free memory will be below vm.min_free_kbytes limit, but in later versions this is achieved by setting to 1.[2]
vm.swappiness = 1 Kernel version 3.5 and over, as well as Red Hat 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.[3]
vm.swappiness = 60 The default value.
vm.swappiness = 100 The kernel will swap aggressively.

With kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over, it is likely better to use 1 for cases where 0 used to be optimal.[4]

To temporarily set the swappiness in Linux, write the desired value (e.g. 10) to /proc/sys/vm/swappiness using the following command, running as root user:

# Set the swappiness value as root
echo 10 > /proc/sys/vm/swappiness

# Alternatively, run this 
sysctl -w vm.swappiness=10

# Verify the change
cat /proc/sys/vm/swappiness
10

# Alternatively, verify the change
sysctl vm.swappiness
vm.swappiness = 10

Permanent changes are made in /etc/sysctl.conf via the following configuration line (inserted, if not present):

vm.swappiness = 10

References[edit]

  1. ^ Andrews, Jeremy (2004-04-29). "Linux: Tuning Swappiness". kerneltrap.org. Archived from the original on 2013-05-24. Retrieved 2018-01-03. 
  2. ^ "Documentation/sysctl/vm.txt". 2017-11-29. Retrieved 2018-01-03. 
  3. ^ "Tuning Virtual Memory". Red Hat Enterprise Linux 6: Performance Tuning Guide. RedHat. 2017-12-20. Retrieved 2018-01-03. 
  4. ^ Tariq, Ovais (2014-04-28). "OOM relation to vm.swappiness=0 in new kernel". Retrieved 2018-01-03. 

External links[edit]