In centos, swap means swap partition, which is virtual memory, used to expand temporary data when the physical memory is insufficient; you can virtualize part of the hard disk space into memory, use "free -m" The command can check the current swap space size.
The operating environment of this article: centos 7 system, Dell G3 computer.
SWAP is virtual memory, used to expand insufficient physical memory and store temporary data. It is similar to virtual memory in Windows. In Windows, only files can be used as virtual memory. Linux can use files or partitions as virtual memory.
First check the current memory and swap space size (default unit is k, -m unit is M):
# free -m
Here you can see the total The memory is 503M, and SWAP does not exist.
View swap information, including detailed information about files and partitions
# swapon -s
or
# cat /proc/swaps
If there is none, we need to manually add the swap partition. Note that OPENVZ architecture VPS does not support manual addition of swap partitions.
There are two options for adding swap space: add a swap partition or add a swap file. It is recommended that you add a swap partition; however, if you do not have much free space available, add a swap file.
Add swap file
1. Use the dd command to create a swap file
dd if=/dev/zero of=/home/swap bs=1024 count=1024000
This will create a /home/swap partition file , the size is 1G and can be doubled by itself.
2. Make it into a swap format file:
mkswap /home/swap
3. Then use the swapon command to mount this file partition to the swap partition
swapon /home/swap
Let’s use the free -m command to take a look , and found that there is already a swap partition.
But after restarting the system, the swap partition became 0 again.
Recommended tutorial: "centos tutorial"
The above is the detailed content of What is swap in centos. For more information, please follow other related articles on the PHP Chinese website!