Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using 12.04 LTS and can sudo sysctl to set swappiness to 10, but adding vm.swappiness=10 to sysctl.conf doesn't work for me - after I reboot, swappiness still reports 60 (default)

I'd like to be able to reduce swaps to my SSD, but can't find a way to do so except manually per session. Modifying sysctl.conf seems to work for most - can anyone advise what I need to check / change to make it work for me too, please?

share|improve this question

2 Answers 2

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.

share|improve this answer
  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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.