We have a RHEL 7 machine, with only 2G of available RAM:
free -g
total used free shared buff/cache available
Mem: 31 28 0 0 1 2
Swap: 15 9 5
so we decided to increase the swappiness to the maximum with vm.swappiness = 100
in /etc/sysctl.conf
instead of 10, and used sysctl -p
to apply the setting.
After some time we checked the status again:
free -g
total used free shared buff/cache available
Mem: 31 28 0 0 2 2
Swap: 15 9 5
as we can see despite the new swappiness setting, we see from free -g
that the available RAM stays at 2G. Why? What is wrong here?
We expected to see 15G of used swap.
We also checked:
cat /proc/sys/vm/swappiness
100
so everything should work according to the new settings BUT free
shows the same situation. What is going here?
Best Answer
The
swappiness
setting is working as intended. Increasingswappiness
doesn’t cause the system to prefer swap to anything else; increasingswappiness
affects the balance between the page cache and swap. When the kernel needs to make physical memory available, it can discard generally use one of two strategies: it can discard pages from the page cache (since their content is on disk), or it can move pages to swap;swappiness
determines how much it favours one strategy over another. Settingswappiness
to 0 (the minimum) means the kernel will avoid swapping until it hits various high water marks, and evict pages from the page cache instead; setting it to 100 (the maximum) means the kernel will consider swapping and evicting the page cache equally.You’ll only see your new setting make a difference when the kernel needs more memory: you’ll see the amount of swap used increase before the amount of memory used in the cache decreases.
You can’t use
swappiness
to get the kernel to keep more memory available. Physical memory is always best used rather than left free, so the kernel has no incentive to pre-emptively free physical memory (increasing available memory).See the RHEL 7 performance tuning guide for more information.