swap partition is useful: Swap is when the physical memory is not enough to put the data into the swap, so swap plays a role in the virtual memory, in a sense, it is also an increase in memory space. The general swap partition is set when the system is installed, if you forget to swap partition when installing the system, it is OK, there is a remedy. Let's talk about how to add a swap partition after installing the system.
Scenario: After loading the system, the bitterness found no swap partition, and for the production server, this obviously does not work, so you need to add a swap partition.
1. First check the swap size
# free
Total used free shared buffers cachedmem: 3922944 158168 3764776 0 6948 37384-/+ buffers/cache: 113836 3809108Swap: 0 0 0
This is clearly shown as zero.
2. Create a swap partition with the DD command
# dd If=/dev/zero Of=/doiido/swap bs=1024 count=8388608
Calculation formula for count: count=size*1024 (SIZE in megabytes)
This creates a/doiido/swap partition file with a size of 8G
3. Format the newly created partition
# Mkswap /doiido/swap
4. Turn the newly created partition into a swap partition
# swapon /doiido/swap
Note: Closing the Swap partition command is: # Swapoff /doiido/swap
5. First check the swap size
# free
Total used free shared buffers cachedmem: 3922944 158168 3764776 0 6948 37384-/+ buffers/cache: 113836 3809108Swap: 8388608 0 8388608
6. Auto-mount swap on boot
# echo "/doiido/swap Swap swap defaults 0 0" >>/etc/fstab
So the swap partition is created
Centos/linux Adding a swap partition