Setting swapiness for linux servers

Hi All,

es suggesting to set vm.swapiness=1 .but when i checked in linux (redhat) swapiness contains default value is 60.
so can we make this one as 1 please suggest me can we change 60 to 1 if we changed what is the effect on server.

Thanks
phani

Reducing the swappiness parameter to 1 will mean that the kernel will try it's best to not use swap at all. If it does end up using swap, you've got severe memory pressure on your system. If your system is dedicated to running ES, there is no reason not to make this change. If you run other services on the system (which you shouldn't) in addition to ES, you can try using mlockall to lock ES into memory, but ultimately this is only mitigating one area of resource contention on the system.

Is there any difference performance wise between using mlockall parameter vs tuning vm.swapiness? From readme in mlockall-agent (which I assume is what ES uses? didn't actually check... GitHub - lucidworks/mlockall-agent: Java Agent for using mlockall in any java application)

Author writes:

In an ideal world, any performance critical java application would be run
on dedicated hardware with swap disabled -- but people don't always get
to run their software in an ideal world. So this agent fills in the gaps.

Is that just in reference to using/not using dedicated hardware, or is there some other downside?

Yes, there is a huge difference. With mlockall, you are ensuring that the memory used by Elasticsearch never gets swapped to disk. With vm.swappiness=1 there is still a chance that the memory used by Elasticsearch will get swapped to disk.

Ideally, you should use mlockall, but if you can't for some reason, you should adjust vm.swappiness.

1 Like

Right I should have clarified - is there any difference between mlock and disabling swap at OS level (not even vm.swapiness = 0 but actually disabled).

Although technically, there is no difference to your program (all programs are essentially locked to RAM if there is no swap to use), there is a big difference to the OS. Having even a small amount of swap and setting vm.swappiness=1 can be useful for the whole OS.

Again, you should use mlockall for ES and leave swap on your server.

1 Like