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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The swappiness setting is working as intended. Increasing swappiness doesn’t cause the system to prefer swap to anything else; increasing swappiness 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. Setting swappiness 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.
Method 2
Solution is to increase vm.watermark_scale_factor (great article on this topic)
sudo sysctl -w vm.watermark_scale_factor=1000 should have the effect that you’re looking for :
When free memory goes below 10% (where 10 := watermark_scale_factor / 100), the kernel will wake kswapd and will thus swap out memory pages to the swap (or discard cache pages, this actually depends on vm.swappiness) until free memory goes up to 20%
Useful reference : https://www.kernel.org/doc/Documentation/sysctl/vm.txt
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0