Swap space can swap out the RAM contents in case there is not enough RAM available. This swap space, representing a physical memory page, uses a special disk file or the top of a disk partition when the RAM is full. Swap space is optional if there is enough memory in the system. In that case, you can disable the Swap space. This tutorial looks at how to fully disable the Swap space on Linux.
How to Fully Disable the Swap Space on Linux
First, check if the Swap is on or off, and run the “swapon –s” from the shell interface. If the Swap is enabled, the command returns a non-empty output:
Or
Before fully disabling the Swap space, you must check the occupied memory. Through this, you can identify the partition which holds the Swap space in your system. You can use any of the following to check the Swap space:
Or
As you can see, the Swap space for the system is 2GB. Now, we need to fully disable the Swap space. To get more reliable information from the previous command, you can get the “/etc/fstab” file by opening it in any editor. Remember, you must open the file in the editor to completely disable the Swap space on Linux. Here, we open this file using the nano editor.
Now, convert the entire line to a comment by prepending it with the “#” (hashtag) symbol.
Save the file. Now, you can check your system’s Swap space through the free command:
You can see that the Swap space is free.
By running the “swapon –s” command, you will see that it no longer gives you any output, which means that the Swap space is fully disabled on Linux.
This is how you can fully disable the Swap space on Linux. If you want to disable a specific Swap partition, run the following “swapoff” command:
Use the following command to disable all Swaps temporarily:
Conclusion
Swap memory is a part of the system’s hard drive or other storage devices which is kept separately. Swapping (enabling swap space) greatly reduces the performance of your system. So, if your system has enough RAM, you can disable the Swap space. This tutorial explained how to fully disable the Swap space on Linux.
When there is a limited amount of RAM, disabling the Swap space can also have unintended consequences such as running out of memory. Disabling a Swap without any specific reason is not recommended. It is always slow compared to RAM, which is why using Swap space negatively affects the system performance.