Get the App
SLTechnology News&Howtos  ›  Network Security  › 

How to create a swap file

Shulou Source: shulou.com Published: 2022-06-01 06:23:41 09月16日 Update

I have been in contact with this swap since I installed the system. As mentioned earlier, it is similar to the virtual memory of windows. The size of the partition is usually 2 times the size of memory. If your memory is more than 4G, then it seems unnecessary for you to divide 8G. 4G is enough for daily exchange. However, there are also situations where there is insufficient virtual memory. If you do, do you have to redistribute the disk? Of course not! Then let's add a virtual disk.

The basic idea is to set up swapfile, format it into swap format, and enable the virtual disk

# dd if=/dev/zero of=/tmp/newdisk bs=40K count=102400

Use dd to create a 4G file / tmp/newdisk, where if represents which file to read from, / dev/zero is a unique 0 generator under linux, of indicates which file to output, bs is the block size, and count defines how many blocks there are.

# mkswap / tmp/newdisk

The mkswap command is specifically formatted for partitions in swap format

# swapon / tmp/newdisk enable the virtual disk

Use the free command to view system memory and virtual memory usage, and the-m option is viewed in the form of M. You can see the current system's. And swapon is to enable our newly created swap file, and then use free to check and find that there is more than 400m.

# swapoff / tmp/newdisk

We can also use swapoff to close the enabled swap file.

Easy to use, artifact.

Tags: Memory file format disk system command size situation necessary insufficient representative that is form idea time generator artifact easy to use contact generate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology MariaDB Microsoft MySQL