In addition to sharing, all articles on the blog are also records: sharing VPS product and discount information, recording problems encountered during use, and solutions found on the Internet. When playing with Alibaba Cloud, I found that it did not have SWAP, so I wanted to add SWAP (swap partition) to it, so I have this recorded text.
Before starting, please note that the operation process of this article comes from: http://www.vpser.net/opt/vps-add-swap.html. A good VPS only operates this process and tries it on multiple VPS.
1. Enter the directory
cd /var/
2. Obtain the SWAP file block to be added (here, 1GB is taken as an example)
dd if=/dev/zero of=swapfile bs=1024 count=1038336
3. Create a SWAP file
/sbin/mkswap swapfile
4. Activate SWAP file
/sbin/swapon swapfile
5. Check whether the SWAP information is correct
/sbin/swapon –s
6. Add it to the fstab file to start automatically when the system boots.
echo "/var/swapfile swap swap defaults 0 0" >>/etc/fstab
You can also modify /etc/fstab in the above step, and add /var/swapfile swap swap defaults 0 0
at the end. Here is a screenshot of the whole process. The front and back of the picture can be compared with the size of SWAP. Because of this The test was performed on the XEN VPS of KVMLA, which has 512MB of SWAP, so it was added.

Conclusion
The above is just a process. If the VPS itself does not have a SWAP calling partition, it will definitely be beneficial to add one, such as Alibaba Cloud; however, if it has SWAP, adding too many SWAPs does not make much sense. Personally, I feel that SWAP is not It is appropriate to be greater than 2 times the physical memory. I have also encountered it on many VPSs. After all the memory is used for SWAP, the VPS becomes very stuck. Of course, the above are still my superficial personal opinions, maybe because I haven't optimized them well.
