设置SWAP
使用
free -m命令查看当前系统
Swap设置情况;
root@SunPma ~ # free -m
total used free shared buff/cache available
Mem: 981 73 807 0 99 787
Swap: 0 0 0
root@SunPma ~ # mkdir /swap
root@SunPma ~ # cd /swap
root@SunPma ~/swap # dd if=/dev/zero of=swapfile bs=1M count=2048
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 2.13948 s, 1.0 GB/s
root@SunPma ~/swap # chmod 0600 swapfile
root@SunPma ~/swap # mkswap swapfile
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=7a6f9b23-6de5-444d-bf08-0c67bc309317
root@SunPma ~/swap # swapon swapfile
root@SunPma ~/swap # free -m
total used free shared buff/cache available
Mem: 981 74 67 0 839 761
Swap: 2047 0 2047
注意:设置完成后的虚拟内存会在重新启动后失效;
如果需要永久生效,可以修改
/etc/fstab文件,在最后添加如下代码:
vi /etc/fstab
/swap/swapfile swap swap defaults 0 0
删除SWAP
使用
free -m命令查看系统
Swap设置情况;
root@SunPma ~ # free -m
total used free shared buff/cache available
Mem: 981 270 240 6 470 564
Swap: 1162 29 1133
root@SunPma ~ # cat /proc/swaps
Filename Type Size Used Priority
/swapfile file 1190340 29952 -2
root@SunPma ~ # swapoff /swapfile
root@SunPma ~ # rm /swapfile
root@SunPma ~ # vi /etc/fstab