If your server is always reporting low memory, and often because of insufficient memory to cause the service to be forced to kill, without increasing physical memory, enable swap area as virtual memory is a good choice, I purchased the Digitalocean VPS 512M memory is not enough , fortunately, the use of a VPS hen SSD, the normal read and write speed is above 300mb/s, the performance improved after the swap enabled, especially in the processing of large memory-consuming script
Create swap principle:
1. The swap size created should be larger than the actual physical memory capacity, but not too large to avoid wasting hard disk space.
2. If the memory IO requests are frequent, and the single swap zone IO queue waits too long, you can create several swap zones more.
3. In principle, priority is created on the device with the fastest IO speed.
To create a step:
1. Create a blank file for swap area hard disk storage.
12 |
#创建一个1个G的SWAP交换区空白文件dd If=/dev/zero Of=/swap bs=1m count=1024 |
Usually create physical memory 2~2.5 times the size of the file as the swap area.
2. Using Mkswap format file as swap file system
12 |
Mkswap-f/swap#-f using files as swap swap areas |
3. Enable the swap file you just created
4. If necessary, you can set up auto-enable swap file swap area, modify/etc/fstab, add one line
1 |
/swap swap swap defaults 0 0 #启动即启用swap |
5. If you do not need to enable swap or need to adjust swap size, you can use the Swapoff command to turn off swap.
Delete the swap after closing swap, and if you need to resize the swap area, recreate it from the first section.
[Linux] Create and enable swap swap areas