Ubuntu 16.04 添加Swap分区

by Web全栈工程师 on 2016 年 04 月 07 日



sudo swapon --show
free -h
df -lh


sudo fallocate -l 1G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile

#enable the swap file, allowing our system to start utilizing it
sudo swapon /swapfile
sudo swapon --show
free -h


使用swapon 命令只对当前有效,重启之后,又变成原有的swap配置,所以需要将新的swap分区信息写入到配置文件里

sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab


cat /proc/sys/vm/swappiness

#a swappiness setting of 60 is not a bad value. For a server, you might want to move it closer to 0 or 10, but setting will persist until the next reboot
sudo sysctl vm.swappiness=10

# vm.swappiness=10 add to sysctl.conf
sudo nano /etc/sysctl.conf

cat /proc/sys/vm/vfs_cache_pressure
sudo sysctl vm.vfs_cache_pressure=50

sudo nano /etc/sysctl.conf

Comments on this entry are closed.

Previous post:

Next post: