Setting swapiness means that virtual swap memory is not used until the physical memory gets full. To avoid this you can set swapiness value.
Linux system comes with a default of 60, meaning that the swap file will be used fairly often if the memory usage is around half of my RAM.
You can check your system's swappiness value by running:
[root@test ~]# cat /proc/sys/vm/swappiness
60
So If i have 4 GB of RAM, and I like to turn that down to 10 or 15. The swap file will then only be used when my RAM usage is around 85 or 90 percent.
To change the system swappiness value
vim /etc/sysctl.conf as root. Then, change or add this line to the file:
vm.swappiness = 10
Reboot for the change to take effect
You can also change the value while your system is still running
sysctl vm.swappiness=10
You can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect.
To calculate your swap Formula
free -m (total) / 100 = A
A * 10
[root@test ~]# free -m
total used free shared buffers cached
Mem: 3950 2262 1687 0 407 952
-/+ buffers/cache: 903 3047
Swap: 1953 0 1953
so total is 3950 / 100 = 39.5 * 10 = 395
It means that when 10 % 395 MB of ram left, then it start using swapiness.
Linux system comes with a default of 60, meaning that the swap file will be used fairly often if the memory usage is around half of my RAM.
You can check your system's swappiness value by running:
[root@test ~]# cat /proc/sys/vm/swappiness
60
So If i have 4 GB of RAM, and I like to turn that down to 10 or 15. The swap file will then only be used when my RAM usage is around 85 or 90 percent.
To change the system swappiness value
vim /etc/sysctl.conf as root. Then, change or add this line to the file:
vm.swappiness = 10
Reboot for the change to take effect
You can also change the value while your system is still running
sysctl vm.swappiness=10
You can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect.
To calculate your swap Formula
free -m (total) / 100 = A
A * 10
[root@test ~]# free -m
total used free shared buffers cached
Mem: 3950 2262 1687 0 407 952
-/+ buffers/cache: 903 3047
Swap: 1953 0 1953
so total is 3950 / 100 = 39.5 * 10 = 395
It means that when 10 % 395 MB of ram left, then it start using swapiness.
No comments:
Post a Comment