Configuring Swap partition under Linux

1. Open swapthe partition

  1. Create a new special file for swappartitioning
dd if=/dev/zero of=/data/swap bs=1024 count=8388616

注:The size of this file is count的大小乘以bs大小, the size of the above command is 8GB

  1. Use mkswapthe command to make the newly created file above into a swap partition.
mkswap /data/swap
  1. View kernel parametersvm.swappiness

If vm.swappinessit 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.confthe file

  1. Enable swap functionality for this swap partition
swapon /data/swap   
echo "/data/swap swap swap defaults    0  0" >> /etc/fstab

2. Close swapthe partition

// 临时关闭
swapoff /data/swap   
swapoff -a >/dev/null

// 永久关闭
vi /etc/fstab
-- 注释掉swap

Guess you like

Origin blog.csdn.net/Laputa_Castle/article/details/117774079
Recommended