1. Open swap
the partition
- Create a new special file for
swap
partitioning
dd if=/dev/zero of=/data/swap bs=1024 count=8388616
注:
The size of this file iscount的大小乘以bs大小
, the size of the above command is 8GB
- Use
mkswap
the command to make the newly created file above into a swap partition.
mkswap /data/swap
- View kernel parameters
vm.swappiness
If
vm.swappiness
it is 0, adjust it to 30 or 60 according to actual needs.
cat /proc/sys/vm/swappiness
sysctl -a | grep swappiness
sysctl -w vm.swappiness=60
注:
If you want to make permanent changes, edit/etc/sysctl.conf
the file
- Enable swap functionality for this swap partition
swapon /data/swap
echo "/data/swap swap swap defaults 0 0" >> /etc/fstab
2. Close swap
the partition
// 临时关闭
swapoff /data/swap
swapoff -a >/dev/null
// 永久关闭
vi /etc/fstab
-- 注释掉swap