Linux increases swapfile swap space

To increase swap space, you need to complete the following steps:

  1. Create a swap partition file: Use ddthe command to create a swap file of a specified size, for example, to create a swap file with a size of 1GB, you can use the following command:
sudo dd if=/dev/zero of=/swapfile bs=1G count=1

In the above command, ifthe parameter specifies the input file, ofthe parameter specifies the output file, bsthe parameter specifies the block size, and countthe parameter specifies the number of blocks. You can adjust these parameters according to your needs.

  1. Set swap file permissions: Use chmodthe command to set swap file permissions, for example:
sudo chmod 600 /swapfile

In the above command, 600permission means that the swap file can only be read and written by the owner.

  1. Format the swap file: Use mkswapthe command to format the swap file, for example:
sudo mkswap /swapfile
  1. Enable swap file: swaponEnable the swap file using the command, for example:
sudo swapon /swapfile
  1. To set up auto-mounting at startup: Edit /etc/fstabthe file and add the following lines:
/swapfile   none    swap    sw    0   0

This will make the system automatically mount the swap file on boot.

It should be noted that using swap space will affect the performance of the system because it is much slower than physical memory, so it is recommended to use swap space only when necessary. The best solution is to increase the physical memory to solve the low memory problem.

Guess you like

Origin blog.csdn.net/qq_22815083/article/details/131060366