The swappiness parameter controls the logical functions of the kernel to forward processes out of physical memory and onto the swap. safe side caution : 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.
swappiness can have a value of between 0 and 100
swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache
The default setting in Ubuntu is swappiness=60. Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation. A value of swappiness=10 is recommended, but feel free to experiment.
The Linux kernel provides a flexibility to set how we can control the swap file is used, called swappiness.
root@ubuntu:~$ cat /proc/sys/vm/swappiness 60
As I have 8 GB of RAM I would like to turn that down to 10 or 15. The swap file will then only be used when my RAM usage is around 80 or 90 percent. To change the system swappiness value, open
/etc/sysctl.conf as root. Then, change or add this line to the file:
vm.swappiness = 10
Reboot the system for the change to take effect.
You can also change the value while your system is still in running mode using root shell :
You can also clear your swap by running
swapoff -a and then
swapon -a as root instead of rebooting to get the same effect.
To calculate your swap Formula:
free -m (total) / 100 = A A * 20 root@ubuntu:/home/one# free -m total used free shared buffers cached Mem: 8192 2262 5930 0 389 865 -/+ buffers/cache: 903 3047 Swap: 8191 0 8191
so total is 8192 / 100 = 81.92 * 20 = 1638
So what it mean is that when 20% (1638 MB) out of 8192 memory is left then it will start using swap.
Source : help of ubuntu’s swapfaq
This article is contributed by RootLinuxBlog. If you like RootLinuxBlog and would like to contribute, you can submit an article using contact us from. See your article appearing on the RootLinuxBlog main page and help other Techies.
Please write comments if you found any error with the above article would really help us to serve you a better way. Thank you…