In the past, setting
0 meant the system would only swap when RAM was totally full.
$ cat /etc/sysctl.d/99-sysctl.conf kernel.sysrq = 1 vm.swappiness=0 $ sysctl vm.swappiness vm.swappiness = 0
However, recently now this setting still allows swapping, even seconds after clearing swap with
sudo swapoff -a; sudo swapon -a. For example, after a few hours,
$ free -m total used free shared buff/cache available Mem: 32047 7914 325 1509 23807 22177 Swap: 1974 1974 0
Hence, I have 22177 MiB
Estimation of how much memory is available for starting new applications, without swapping.
However, my system is still swapping heavily, using 1974 MiB of swap space and slowing everything down.
I've also tried setting
1, with similar results. I've also tried different kernels, including the recent LTS 4.19.17-1, 4.19.16-1-lts, 4.19.15-1-lts, and the many other LTS versions, and the mainline 4.18.16.arch1-1. How can I prevent my system swapping unnecessarily?
vm.swappiness = 0 on newer versions of the kernel means it will not "initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone." I'm not sure what this "high water mark" is, but I have a lot of free memory! Another page suggests that the OOM killer will be invoked when this occurs (not swapping itself). Is it possible to prevent swapping unless there is no RAM, and prevent any OOM killing from occurring (unless both RAM and swap are full)?