[ubuntu]ubuntu set virtual memory

First check whether you have added virtual memory or check the current status of virtual memory by running the following command:

free -mh

Create swap partition:

sudo mkdir /swap

cd /swap

sudo dd if=/dev/zero of=swapfile bs=1024 count=12582912

Among them, count is the memory size allocated by yourself. The above is 12GB. You can set it according to your own situation. The following is the recommended setting.

If you want to set it to 8GB you can set

sudo dd if=/dev/zero of=swapfile bs=1024 count=8582912

# bs is the size of the block, count is how many blocks are created
sudo dd if=/dev/zero of=swapfile bs=1M count=8196

# Modify permissions
sudo chmod 0600 swapfile

#Convert the generated file into a Swap file
sudo mkswap swapfile

#Activate file
sudo swapon swapfile

#Close the file
sudo swapoff /swap/swapfile
 

At this time, the swap partition has taken effect, but if you restart, you will find that the swap partition has not started automatically, so you need to add it
to the /etc/ fstab  file.

/swap/swapfile swap swap defaults 0 0

Guess you like

Origin blog.csdn.net/FL1623863129/article/details/133433771