First, let’s introduce the role of swap. Generally, when we install the Linux operating system, the system will create a swap partition by default. Let's take a look at the usage of the swap partition on the server
# free -h total used free shared buff/cache available Mem: 992M 630M 68M 264K 293M 198M Swap: 1.0G 96M 927M
The swap partition size of the server is 1G. This swap partition is created by the system by default. We will increase the capacity of the swap partition on this basis later. .
The swap partition is called the swap partition. As a special hard disk space, it plays the role of memory. When the system memory is not enough, the system will store some of the data in the memory that will not be used temporarily into the swap partition. The advantage of using swap partitions is that hard drives are much cheaper than memory, so this is a very cost-effective way to increase system memory. However, if swap is used frequently, it will greatly affect the running speed of the system. Therefore, the best strategy for using swap partitions is to "prepare for use".
Next, let’s take a look at how to create a swap partition.
Build a swap partition through physical partition
First you need to partition it
Next, format it
mkswap /dev/sda5
Then open the new swap partition
At this point, the construction of the swap partition is completed. Unlike ordinary partitions, there is no need to mount the swap partition when building it. Just use the command swapon partition name.
Build a swap partition through files
The above method is suitable for unused remaining space on the disk. But if all the disk space is partitioned, how to create a swap partition? We can build a swap partition by making a large file. Although the disk space has been completely allocated, this method can be used as long as there is remaining space in any of the partitions.
Let’s create a large file
Next format it
Finally turn on swap Partition
Today I will introduce two methods to build a swap partition. Generally, the size of the swap partition is recommended to be within 2G. Remember that the role of the swap partition is when the memory is not enough. Use the hard disk space as memory temporarily.
The above is the detailed content of Introduce two methods to create memory swap space swap. For more information, please follow other related articles on the PHP Chinese website!