Linux7.7 Method of Setting Switch Partition SWAP

  • 2021-07-09 09:45:58
  • OfStack

Swap partition of Linux system, that is, swap partition, is usually called virtual memory. The function of Swap space can be simply described as: when the physical memory of the system is not enough, it is necessary to release a part of the physical memory space for the current running program. Those freed spaces may come from programs that have not operated for a long time. These freed spaces are temporarily saved in Swap space, and when those programs are about to run, the saved data is restored from Swap to memory. In this way, the system always performs Swap exchange when the physical memory is insufficient. In fact, the adjustment of Swap is very important to the performance of Linux server, especially Web server. By adjusting the Swap, you can sometimes overcome the bottleneck of system performance and save the cost of system upgrade.

1. Create a swap partition file


[root@devsz wxadmin]# dd if=/dev/zero of=/opt/swapfile bs=1M count=4096 
4096+0 records in
4096+0 records out
4294967296 bytes (4.3 GB) copied, 20.789 s, 207 MB/s

2. Authorize documents


[root@devsz wxadmin]# chmod 600 /opt/swapfile

3. Formatting swap partitions


[root@devsz wxadmin]# mkswap /opt/swapfile 
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=bfe83644-0fa0-43f9-bf7e-69f9e24b391f

Step 4 Turn on swap partition


[root@devsz wxadmin]# swapon /opt/swapfile

5. View swap partition status


[root@devsz wxadmin]# free -m
       total    used    free   shared buff/cache  available
Mem:      3789    2682     208     280     898     586
Swap:     4095      0    4095
[root@devsz wxadmin]# 

Related articles: