Monday, May 11, 2015

Adjust swappiness to improve responsiveness

I bought 16GB RAM recently for my desktop ( http://xatierlike.blogspot.tw/2015/04/ramdisk-for-chromium.html ). But sometimes the system is still a bit slow for me.

The reason is the high usage of the swap filesystem. The size of swap will go to over 1GB sometimes.

(for example)
$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        5.0G        158M        1.0G         10G        9.1G
Swap:          1.9G        1.2G        612M

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk
├─sda1   8:1    0    28G  0 part /
├─sda2   8:2    0   1.9G  0 part [SWAP]
└─sda3   8:3    0 901.7G  0 part /home

According to Arch wiki: https://wiki.archlinux.org/index.php/Swap


Swappiness
The swappiness sysctl parameter represents the kernel's preference (or avoidance) of swap space. Swappiness can have a value between 0 and 100, the default value is 60. Setting this parameter to a low value will reduce swapping from RAM, and is known to improve responsiveness on many systems.

Sample usage:

# current swappiness
$ cat /proc/sys/vm/swappiness
60

# same as above
$ sysctl vm.swappiness
vm.swappiness = 60

# set it to 10
$ sudo sysctl vm.swappiness=10
vm.swappiness = 10

# unload old swap
$ sudo swapoff -a && sudo swapon /dev/sda2

# set the swappiness value permanently,
/etc/sysctl.d/99-sysctl.conf
----------------
vm.swappiness=10


Okay, now my system is back to flying.

No comments:

Post a Comment