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

so everything should work according to the new settings BUT free shows the same situation. What is going here?


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.

  • Stephen, you mention "setting swappiness to 100 means the kernel will always prefer swapping over discarding pages from the page cache". On the other hand Thomas Nyman's answer states setting swappiness to 100 should cause the swap and page cache priorities to be equal. Are you able to comment? Thanks – iruvar Mar 27 at 11:59
  • @iruvar thanks, my explanation was indeed incorrect. In practice the effect tends to end up being that the kernel prefers swapping, presumably because of the way it takes previous scanning results into account (I haven’t thought about it enough to say for sure), but the base priorities are indeed equal when swappiness is set to 100. – Stephen Kitt Mar 27 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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