[Linux] create and enable swap Swap

Reprinted: https://www.cnblogs.com/zsummer/p/4808422.html


If your server is always reported out of memory, and often because of lack of memory caused service to be forced to kill it, without increasing the physical memory, enabled swap swap as virtual memory is a good choice, I purchased DigitalOcean VPS 512M memory basic enough, but fortunately VPS hen using SSD, normal read and write speeds are 300MB / s or more, enable the swap after the performance improved a lot, especially in dealing with the script memory consumption

Founding principles swap:
swap swap size should be greater than 1. Create a capacity size of the actual physical memory, but not too large, so as to avoid waste of hard disk space.
2. If the memory IO request frequent, and single swap swap IO queue wait too long, you can create several multi-exchange swap area.
3. In principle priority created on the fastest IO device.

Creating steps:
1. Create a blank hard disk storage file with the swap swap.

1
2
Create a G # 1 is empty SWAP swap file 
dd if = / dev / zero of = / swap bs = 1M count = 1024

Creating physical memory is typically 2 to 2.5 times the size of the file as a swap area.

2. Use mkswap file format for the swap file system

1
2
-f mkswap / swap 
# -f use as a swap file swap

3. Enable Swap file you just created

1
swapon /swap

4. If it is necessary to set a power-enabled automatically swap file exchange, modify / etc / fstab, increase his

1
/ Swap swap swap defaults 0 0 # swap boot that is enabled

5. If no enable swap or adjust the size of the swap, the command may be used to close swapoff swap.

1
swapoff /swap

After closing delete the corresponding swap swap swap swap files to delete, such as the need to adjust the size of the swap exchange zone, starting from the first part can be re-created.


Published 140 original articles · won praise 28 · views 180 000 +

Guess you like

Origin blog.csdn.net/qq_16097611/article/details/79825944