In this article we will learn How to Permanently Disable Swap in Linux. Swap space represents a physical memory page that lives on top of disk partition or a special disk file used for extending the RAM memory of a system when the physical memory fills up.
Introduction
Using this method of extending RAM resources, inactive memory pages are frequently dumped into the swap area when no RAM is available. However, do to the spinning speed of classical hard disks, swap space is way lower in transfer speeds and access time compared to RAM.
On newer machines with fast SSD hard disks, reserving a small partition for swapping can greatly improve access time and speed transfer compared to classical HDD, but the speed is still lower than RAM memory. Some suggest that the swap space should be set as twice the amount of machine RAM. In case your server has sufficient RAM memory or does not require the use of swap memory, you should consider disabling the swap memory.
Run the following command to check the Swap Memory of your system:
free -mh
Now See the Swap details and if the Used memory is 0. It means that Swap memory is not being used in your system.
Use the following command to identify the swap partition:
blkid
As you can see in the Output of blkid in above picture “/dev/mapper/cl-swap” is the Swap Area.
Disable Swap in Linux
Also, Use the following command to look swap partition:
lsblk
Deactivate the swap area identified above using the following command:
swapoff /dev/mapper/cl-swap
You can also disable All swap Areas using the following command:
swapoff -a
Now, run the following command to check if the Swap is disabled.
free -mh
To permanently disable Swap memory remove the swap line from /etc/fstab file as shown below:
nano /etc/fstab
Remove the following line:
/dev/mapper/cl-swap none swap defaults 0 0
Now reboot your system using the following command:
reboot
After reboot, run the following command to apply new settings:
mount -a
So, Swap Memory is successfully disabled from your system.