Answers:
Linux内核提供了可调整的设置来控制交换性
$ cat /proc/sys/vm/swappiness
60
/etc/sysctl.conf
以root身份打开。然后,将以下行更改或添加到文件中:
vm.swappiness = 10
要临时更改swappiness值,请尝试以下命令:
$ echo 50 > /proc/sys/vm/swappiness
sudo sysctl -p /etc/sysctl.conf
更改才能生效?
您可以在虚拟文件中设置此值。/proc/sys/vm/swappiness
所提到的值将决定交换空间的使用方式,以下是带有意图的值。
vm.swappiness = 0 # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
vm.swappiness = 1 # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
vm.swappiness = 10 # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected.
vm.swappiness = 60 # The default value.
vm.swappiness = 100 # The kernel will swap aggressively.
尽管实际上也取决于需求,但是如果可用的物理内存足够,则交换空间可能就不需要很大,按照Layman的说法,无需更改默认值60
。
swapoff -a
以重新开始很有用。serverfault.com/a/354384/203035