Aliyun host CentOS virtual memory (swap)

1. Add a swap file size to 2G
By default, of=/swapfile swapfile paper created in the/var/directory.
If I create a/opt/image/directory, all of the following in the/swapfile should be changed to/opt/image/swap
# dd if=/dev/zero of=/swapfile bs=1k count=2048000
2. creating a SWAP file
# mkswap /swapfile
3. activate the SWAP file
# swapon /swapfile
4. see SWAP information is correct
# swapon -s
5. Add to the fstab file to automatically start when the system boots
Note that there is a swapfile file default path is used, that is,/var/swapfile. If your swapfile file is not in the above operation the/var/directory, modify the following/var/swapfile should accordingly to set write.
# echo “/var/swapfile swap swap defaults 0 0” >> /etc/fstab
6. check 2G swap partition using command free entry into force
# free -m
Or, check the meminfo file
# grep SwapTotal /proc/meminfo
7. release the SWAP file
# swapoff /swapfile
8. Remove SWAP files
# rm -fr /swapfile