Reduce swap usage
Mar 27, 2023 2m 0
vm.swappiness = 10
Reduce swap usage
Lower value of SWAPPINESS reduces swap usage. The OS only uses swap when the memory usage exceeds 90% (with SWAPPINESS=10)
$ SWAPPINESS=10 && if grep -qF "vm.swappiness" /etc/sysctl.conf; then echo $(grep -F "vm.swappiness" /etc/sysctl.conf); else echo "vm.swappiness = $SWAPPINESS" | sudo tee -a /etc/sysctl.conf; fi && sudo sysctl -p && sudo swapoff -a && sudo swapon -a
"""
swappiness can have a value between 0 and 100.
swappiness=0
:- Kernel version 3.5 and newer: disables swapiness.
- Kernel version older than 3.5: avoids swapping processes out of physical memory for as long as possible.
swappiness=1
: Kernel version 3.5 and over: minimum swappiness without disabling it entirely.swappiness=100
: Tells the kernel to aggressively swap processes out of physical memory and move them to swap cache.
"""
Reference: