[ Linux ] swap 分区优化

发布时间 2023-03-26 21:20:05作者: YEUNGCHIE

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 分区的策略越“激进”。这个值在 DSM 上默认是 60,当你的物理内存足够大时,可以适当改小。我给的内存是 20G,对于 NAS 来说够够的了。

临时修改

sysctl -w vm.swappiness=1

永久修改

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

清空 swap 分区

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