Swappiness

From Sysadmin

Jump to: navigation, search

The swappiness parameter was added to the Linux kernel in version 2.6. This parameter has a value in the range 0-100 and effects how aggressively the kernel will swap. A system will a swappiness of 0 will still swap, but it will only swap on demand. In order to prevent a Linux system from swapping at all it is necessary to disable all swap spaces with swapoff -a.

The memory available to systems has grown more quickly than application demand for memory. In the 1980s and 1990s systems could be expected to swap during normal utilisation as demand often exceeded available memory. Today the memory available to systems is often sufficient for their regular needs. As a result systems often swap less than they did in the past.

A lower swappiness value will mean that applications are more likely to remain in memory while the system will have less memory allocated to file buffers and disk cache. A high swappiness value will result in applications being more likely to be swapped out but with more memory available for file buffers and disk cache.

Set the value by adding a line like this to /etc/sysctl.conf:

vm.swappiness=50

Rerun sysctl:

sysctl -p

Like any value added through sysctl, this change becomes availble to the system immediately and no reboot is necessary.

Recommended Values

Server classProposed Swappiness
Application Server
Database Server (Oracle)0
Database Server (Postresql)0
Database Server (MySQL using InnoDB)0
Database Server (MySQL using MyISAM)100
File Server
Personal tools