In the past, setting vm.swappiness
to 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 available
. From man free
:
available
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 vm.swappiness
to 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?
Apparently setting 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)?
vm.swappiness
should prevent overzealous swapping. – Sparhawk Jan 30 '19 at 05:50vm.swappiness
. – Sparhawk Jan 30 '19 at 09:07vm.swappiness = 10
(confirmed via/proc/sys/vm/swappiness
. However, after the latest kernel upgrade I see swap being used a lot more (when ~8GB of RAM is used on my 16GB laptop). I have also seen massive performance degradation.Another issue is, if you have an SSD, it is best for the life of the disk to minimize writes.
– Mario Camou Feb 08 '19 at 13:53vmstat 1
, are thesi
(swap in) andso
(swap out) metrics actually very active? – spuk Mar 21 '19 at 15:26htop
. I'm away at the moment, but I'll testvmstat 1
on Monday. – Sparhawk Mar 21 '19 at 23:00vmstat 1
show thatsi
andso
are indeed active, if fairly sporadic (max of ~600 and 64 respectively). – Sparhawk Mar 24 '19 at 20:53If you really don't want to use swap, you might just disable/remove it.
– spuk Apr 08 '19 at 20:09swapoff -a; swapon -a
to clear the swap, and performance is perfect. The system is on so I can ssh from home, but I leave swap on in case some process runs riot with memory and crashes the system. Regardingswappiness=0
it looks like you are right! It used to mean that, but has changed. I've edited the question to add more information. – Sparhawk Apr 08 '19 at 23:12atop
very useful. It includes a service you can enable to start automatically, which logs snapshots every ten minutes. – sourcejedi Apr 10 '19 at 20:13atop
; that seems useful. – Sparhawk Apr 11 '19 at 01:04