Home > Article > Operation and Maintenance > What is linux swap partition
The Linux swap partition is the SWAP partition of Linux. It is a virtual memory partition under LINUX. Its function is to virtualize the disk space (that is, the SWAP partition) into memory for use after the physical memory is used up. The Linux swap partition functions similarly to the swap file of the Windows system, but it is a continuous disk space and is invisible to the user.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
The Linux swap partition is the SWAP partition of Linux.
Swap partition: SWAP is the virtual memory partition under LINUX. Its function is to swap the disk space (that is, SWAP partition) after the physical memory is used up. Virtually used as memory. It functions similarly to the swap file of the Windows system, but it is a contiguous disk space and is invisible to the user.
Features:
1. It is similar to the swap file of Windows system, but it is a continuous disk space and is not useful to users. visible.
2. Its speed is much slower than physical memory.
Two types of swap space can be created under Linux, one is the swap partition and the other is the swap file. The former is suitable for use with free partitions, and the latter is suitable for hard disk partitions without empty space, and the hard disk space has been allocated.
As a test engineer, if you are not familiar with the swap partition of the server, it is likely that the server performance is not optimized enough.
Or if you want to optimize server performance, you can check the size of the server swap and the speed of context switching between applications or the frequency of reading and writing, etc. to flexibly set the swap partition size. Here we make a preliminary discussion.
Linux swap partition: When a program requires more memory than the physical memory on the computer, whether it is Windows No matter whether it is Linux or Linux, the solution is to transfer the saved things to the "virtual memory" on the hard disk. Although the hard disk is much slower than the memory, at least the capacity is much larger. In addition, the operating system can also transfer some programs that have been inactive for a long time to virtual memory, leaving more main memory for needed programs and disk buffering.
When installing Linux, you generally need to carve out a partition as the "swap partition" of Linux and as the storage partition for virtual memory contents.
swapon -s This command can check the virtual memory of the current system. This command requires root to run.
Filename Type Size Used Priority /dev/sdb3 partition 1004052 0 -1
You can often see that the current swap partition is /dev/sda3, and the Type in column 2 shows partition. It means that this is a swap partition. So, are there other Types?
The swap file is the same as the swap partition. The size is fixed. For example, if you want a 1G swap file, you must first create one. For a 1G blank file, we use the dd tool to complete this task:
dd if=/dev/zero of=/swapfile bs=1024count=1048576
1048576 is the size of 1G expressed in KB. If you want a file of other sizes, just change this number.
The above command will create the swapfile file in the root directory. Then, we need to format it into the swap file format:
mkswap /swapfile
Then mount it and you can apply it immediately This swap file:
swapon /swapfile
You can run swapon -s to check it
Filename Type Size Used Priority /dev/sda3 partition 1004052 0 -1 /swapfile file 1048486 0 -2
There is an extra item, Type is file, it is indeed the swap file we created, and the system is already using it.
If you want to automatically mount this swap file when booting, then add the following sentence to /etc/fstab: /swapfile swap sw 0 0
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of What is linux swap partition. For more information, please follow other related articles on the PHP Chinese website!