Swappiness is a tweakable setting that controls how often the swap file is used, provided by The Linux kernel.
Zero setting of A swappiness means that the disk will be avoided unless you run out of memory (absolutely necessary), while a swappiness setting of 100 means that programs will be swapped to disk almost instantly.
The default swappiness of Ubuntu system is 60, meaning that the swap file will be used fairly often if the memory usage is around half of RAM.
Checking Swappiness
You can check your own system's swappiness value by running this command on terminal:I@blogger_you:~$ cat /proc/sys/vm/swappiness 60 (result)
If you have 4 GB of RAM, you can turn that down to 10 or 15. The swap file will then only be used when your RAM usage is around 80 or 90 percent.
Change Swappiness Value
To change the system swappiness value, open /etc/sysctl.conf as root.I@blogger_you:~$ sudo gedit /etc/sysctl.conf
Then, change or add this line to the file:
vm.swappiness = 10
Reboot for the change to take effect
Also, you can change the value while your system is still running with this command:
sysctl vm.swappiness=10
you can also clear your swap by running
swapoff -aand then
swapon -aas root instead of rebooting to achieve the same effect.
What is swappiness
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.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
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.
** Swappiness of 100 does not make programs get swapped out immediately, nor does a value of 60 or 90 mean swap gets used when ram is 60 or 90% full. It is a ratio of preference for stealing pages from cache vs. swapping things out to free up some memory when there isn't enough. A low value will strongly prefer stealing pages from the cache, and a high value strongly prefers to try and swap pages out. The setting only has any effect once memory is (nearly) all used, and the kernel has to choose how to free some up.
** By decreasing swappiness, you increase the chance of a program not to be swapped out, but at the same time decrease the size of disk cache, which can make disk access slower. So the effects of this setting on the actual performance are not that straightforward. You're welcome to experiment of course but the defaults are set by people who understand enough in the subject.
Add Comments