Swap Memory and Swapiness

Last modified: 
Tuesday, April 21st, 2015

What is Swapiness

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.

  1. swappiness can have a value of between 0 and 100
  2. swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
  3. swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache

Source: SwapFaq [https://help.ubuntu.com/community/SwapFaq]

Config and Command

Get the Swapiness Value

cat /proc/sys/vm/swappiness

Temporarily Change Swapiness

# Run as root...
sysctl vm.swappiness=10

Permanently Edit Swapiness

# Run as root..
vim /etc/sysctl.conf

Edit (or add) the following line to suit.

vm.swappiness = 60

Refresh Swapiness Without Reboot

# Run as root...
/sbin/sysctl -p

Large Mysql Caches May Migrate into Swap

High swapiness settings may cause large mysql caches to migrate into swap cache. See MySQL Swapping to Disk (2009) [http://www.incutio.com/blog/2009/11/27/mysql-swapping-resolution].


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.