Linux adds Swap partition to solve memory shortage problem

preparation
Firstly, check if your system already has a Swap partition:
swapon -s
or
free -m
If no result is returned or the Swap column in free-m has a value of 0, it means that your system does not have a Swap partition.
Create SWAP partition
We can use the 'fall' command to create a 1GB Swap partition:
fallocate -l 1G /swapfile
If this command cannot be used, please install the utility Linux package:
apt install util-linux
Then set the permissions for this file:
chmod 600 /swapfile
Then activate the SWAP partition
mkswap /swapfile
swapon /swapfile
At this point, you can use the swap - s or free - m command to check if the Swap partition has been activated.
Set up auto start upon startup
We need to edit the file/etc/fstab and add the following content:
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
Great job done, use the free - m command to check if the Swap partition is correct:
Adjust the Swappiness value of the system kernel
Swapiness is a property of the Linux kernel that defines the frequency at which the system uses swap space. The value of Swapiness ranges from 0 to 100 (default is 60), with a low value causing the kernel to avoid swapping as much as possible, and a high value causing the kernel to use swap space more actively.
This value defaults to 60, and we can use the cat/doc/sys/vm/swappiness command to check the current value.
Usually we can change it to 10:
echo "vm.swappiness=10" >> /etc/sysctl.conf
Then use the sysctl - p command to make it effective.
Close Swap
Sometimes we need to close the Swap partition, you can use the following command:
Firstly, disable the Swap partition:
swapoff -v /swapfile
Then check/etc/fstab and delete the/swap file swap swap defaults 0 0 line.
Finally, delete the file/swap file:
rm /swapfile

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Several of the most common encryption and decryption methods

Encryption and decryption are the most commonly used data conversion methods in communication....

What types of websites are suitable for. ORG domain names ORG domain name suitable for scope sharing

If we are webmasters who built websites in the early days, we should know that COM, NET, and ORG...

How to change the root user password of Linux operating system

Changing the root user password of the Linux operating system is a critical operation, please...

Pagoda panel installation failure prompt "ModulaNotFoundError: No module named 'gevent'" troubleshooting and solutions

Recently, a customer reported that when installing the pagoda panel, they received a message...