swap阈值设定1, 查看当前系统swap阈值
[email protected]~$ cat /proc/sys/vm/swappiness
60
内存在使用到100-60=40%的时候,就开始出现有交换分区的使用
swappiness=0表示最大限度使用物理内存,然后才使用swap空间,
swappiness=100表示积极使用swap分区,并且把内存上的数据及时的搬运到swap空间里面
2, 永久设定
[email protected]~$ sudo -s
[[email protected] chunli]# echo "vm.swappiness = 10" >> /etc/sysctl.conf #永久修改
[email protected]~$ sudo sysctl -p
[email protected]~$ cat /proc/sys/vm/swappiness
10
3, 临时设定
[email protected]~$ sudo sysctl vm.swappiness=10 #临时修改
创建swap分区文件[email protected]~$ dd if=/dev/zero of=swapfile bs=1M count=4096
[email protected]~$ mkswap swapfile
启用交换分区
[email protected]~$ sudo swapon swapfile
[email protected]~$ free -mt
total used free shared buffers cached
Mem: 497 490 6 0 19 247
-/+ buffers/cache: 224 272
Swap: 6111 0 6111
Total: 6609 490 6118
关闭交换分区
[email protected]~$ sudo swapoff swapfile
[email protected]~$ free -m
total used free shared buffers cached
Mem: 497 488 8 0 19 247
-/+ buffers/cache: 221 275
Swap: 2015 0 2015
永久设置,开机自动mount
vim /etc/fstab
/swapfile swap swap defaults 0 0