sysctl中和swap相关的参数

1
2
➜  ~  sudo sysctl -a  | grep swap
vm.swappiness = 0

Swappiness is a Linux kernel parameter that controls the relative weight given to swapping out of runtime memory, as opposed to dropping pages from the system page cache. Swappiness can be set to values between 0 and 100 inclusive. A low value causes the kernel to avoid swapping; a higher value causes the kernel to try to use swap space.
取值说明:

1
2
3
vm.swappiness = 0,表示只有在避免OOM的时候才进行swap操作;(并不是关闭swap)
vm.swappiness = 60,系统默认值;
vm.swappiness = 100,系统主动的进行swap操作。

关闭swap

1
2
3
cat /proc/sys/vm/swappiness
sudo echo 0 | sudo tee /proc/sys/vm/swappiness
sudo swapoff/swapon -a

参考