Home>Article>Operation and Maintenance> What is swap in centos

What is swap in centos

WBOY
WBOY Original
2022-03-30 12:00:28 4816browse

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.

What is swap in centos

The operating environment of this article: centos 7 system, Dell G3 computer.

What is swap in centos

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

What is swap in centos

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.

What is swap in centos

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn