Changing swappiness in sysctl.conf doesn't work for me

What I usually do is create a custom rule in /etc/sysctl.d/ instead of editing the main sysctl file. Change directory to sysctl.d and create your file:

cd /etc/sysctl.d/ 
sudo touch 60-my-swappiness.conf

Then run your favourite text editor:

sudo nano 60-my-swappiness.conf

Enter your value at the top of the file, for example, vm.swappiness = 10 (there must be spaces between swappiness and the value as shown).

As it recommends in the readme in /etc/sysctl.d/, run

sudo service procps start

for the system to read the new values and then reboot.

The reason why we use 60 at the start of the my-swappiness.conf is so that your custom rule overrides any other rules in the directory.

Check that you have the correct swappiness with

cat /proc/sys/vm/swappiness
10

This works for me, but there is more guidance on swap and swappiness in the Ubuntu guide if you need any more detailed information.


  1. See what the current value is for the swappiness setting:

    sudo cat /proc/sys/vm/swappiness (It should give a number of 60 here)

  2. Change the value to a lower number

    sudo sysctl -w vm.swappiness=5

  3. Check the value again.

    sudo cat /proc/sys/vm/swappiness (Now, it should give a value of 5 here)

  4. gksu gedit /etc/sysctl.conf

    Paste the following line on the text file that opened:

    vm.swappiness = 5

(You have vm.swappiness=10 when it should read vm.swappiness = 10)

  1. Reboot.

  2. Check the setting again to confirm the changes were made:

    sudo cat /proc/sys/vm/swappiness (Now, it should give a number 5 here)