Updated 28 Feb 2014
Linux swap * Swap partition sizing * Swappiness
Linux has two forms of swap space: the swap partition and the swap file. The swap partition is an independent section of the hard disk used solely for swapping; no other files can reside there. The swap file is a special file in the filesystem that resides amongst your system and data files.
You will recognise the swap partition if you installed Linux and configured the disk partitions yourself. Almost all Linux installations will have a swap partition on the hard disk.
Linux also supports a swap file that you can create, prepare, and mount in a fashion similar to that of a swap partition. The advantage of swap files is that you don't need to find an empty partition or repartition a disk to add additional swap space.
To see what swap space you have, use the command swapon -s.
When creating a swap partition, a rule of thumb is as follows:
The Linux 2.6 kernel added a new kernel parameter called swappiness to let administrators tweak the way Linux swaps. It is a number from 0 to 100. In essence, higher values lead to more pages being swapped, and lower values lead to more applications being kept in memory, even if they are idle.
The default value for swappiness is 60. If swappiness is much increased, application response time drops. This is because the system has to swap the recently activated application back from the hard disk into RAM. On the other hand, if swappiness is much reduced, you may end up with hundreds of megabytes of untouched RAM that could be used for other things.
The following temporarily sets the swappiness value to 10:
Edit /etc/sysctl.conf to permanently change swappiness by adding this line: