https://www.cnblogs.com/yeungchie/

swappiness

This control is used to define how aggressive 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.

所以当 swappiness 值越大时,系统使用 swap 分区的策略越“激进”。

查看 swappiness

cat /proc/sys/vm/swappiness
# 60

或者

sysctl vm.swappiness
# vm.swappiness = 60

这个值在 DSM 上默认是 60,当你的物理内存足够大时,可以适当改小。

我给的内存是 20G,对于 NAS 来说够够的了,所以我改成 1

临时修改

sysctl -w vm.swappiness=1

永久修改

  • 修改文件 /etc/sysctl.conf
vm.swappiness=1 # 修改或添加这一行参数
  • 激活
sysctl -p

清空 swap 分区

swapoff -a # 关闭所有 swap 分区
swapon -a  # 激活所有 swap 分区