You can set the swappiness to 0.The Linux documentation says:
"This control is used to define how aggressive (sic) the kernel will swap memory pages. Higher values will increase aggressiveness, lower values decrease the amount of swap. A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone.
The default value is 60."
Note that setting swappiness to 0 does not completely eliminate swap, it still swaps under conditions.
But is swap a problem? Just some swapped-out pages that are hardly used deserve to be swapped out, I think. To see if swap is a problem, run vmstat 60
for a while and look at the si
and so
columns. You'll probably see that they are 0 most of the time. Also, your column swpd
will probably not change much. That would mean that the swapping is not a problem.
Is you have enough memory for what you are doing and you absolutely do not want any use of swap space for some exotic reason, swapoff
the swap-space.
Note that, if you have system freezes, with these parameters, it is unlikely to be caused by swapping. Unless, of course four si
and so
columns in the vmstat
output are high.
--edit--
Your vmstat
output suggests that there are a few pages swapped out. That is not something to worry about; there is no big swapping going on. Certainly not enough to cause system freezes.
swapd
is zero, so no swap use at that time. A measurement at times when you're doing things on the system would be more helpful. – Ljm Dullaart Aug 13 '22 at 15:51mmap(MAP_POPULATE)
which prefaults the pages). So normally allocation succeeds, and more physical memory is needed only when a program writes to that allocated memory. If there isn't enough swap + RAM, the kernel has to kill something (OOM killer). – Peter Cordes Aug 13 '22 at 22:55