Ubuntu Swap File
Posted: Mon Jun 06, 2016 6:09 pm
I have been puzzled for some time as to why Ubuntu will write to the swap file when there is plenty of RAM installed. I've discovered that writing to the swap file is controlled by the "swappiness" setting! By default, Ubuntu uses a swappiness value of 60 which means that when 40% of memory is used, the system will start swapping data from memory to the swap file. Here is some info you can use to check and/or change swappiness:
To check the swappiness value
cat /proc/sys/vm/swappiness
To change the swappiness value A temporary change (lost on reboot) with a swappiness value of 10 can be made with
sudo sysctl vm.swappiness=10
To make a change permanent, edit the configuration file with your favorite editor:
sudo nano /etc/sysctl.conf
Search for vm.swappiness and change its value as desired. If vm.swappiness does not exist, add it to the end of the file like so:
vm.swappiness=10
The more RAM your system has the lower the swappiness value can be. Possibly even "0" My production system with 16 GIG of RAM works well with a value of "10"
Save the file and reboot.
To check the swappiness value
cat /proc/sys/vm/swappiness
To change the swappiness value A temporary change (lost on reboot) with a swappiness value of 10 can be made with
sudo sysctl vm.swappiness=10
To make a change permanent, edit the configuration file with your favorite editor:
sudo nano /etc/sysctl.conf
Search for vm.swappiness and change its value as desired. If vm.swappiness does not exist, add it to the end of the file like so:
vm.swappiness=10
The more RAM your system has the lower the swappiness value can be. Possibly even "0" My production system with 16 GIG of RAM works well with a value of "10"
Save the file and reboot.