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

How to modify server DNS address in Linux

DNS is a server used to resolve the backend IP of domain names. Linux, like Windows, has...

Simple Method for Setting Linux VPS System Synchronization Time and Time Zone

80% of VPS users may choose their preferred system directly after purchasing VPS, and then...

Requirements and usage suggestions for. app domain registration

.app域名是由Google推出的顶级域名(TLD),旨在提供安全的在线体验。作为.app域名的管理机构,Google要求所有.app域名都必须使用HTTPS来加密数据传输,以确保用户隐私和安全...

Nginx configuration using SSL certificate method

The difference between free certificates and paid certificatesFirstly, free SSL certificates come...

What is a. ai domain name? Is an AI domain worth registering? Can DNSHE register an AI domain name?

The. ai domain represents one of the most important innovations of humanity, artificial...