How to Permanently Disable Swap in Linux


Swapping or 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.

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 more magnitudes lower than RAM memory. Some suggest that the swap space should be set as twice the amount of machine RAM. However, on systems with more than 4 GB or RAM, swap space should be set between 2 or 4 GB.

In case your server has sufficient RAM memory or does not require the use of swap space or the swapping greatly decreases your system performance, you should consider disabling the swap area.

Before actually disabling swap space, first you need to visualize your memory load degree and then identify the partition that holds the swap area, by issuing the below commands.

Look for Swap space used size. If the used size is 0B or close to 0 bytes, it can be assumed that swap space is not used intensively and can be safety disabled.

Check Swap Space

Next, issue following blkid command, look for TYPE=”swap” line in order to identify the swap partition, as shown in the below screenshot.

Check Swap Partition Type

Again, issue the following lsblk command to search and identify the [SWAP] partition as shown in the below screenshot.

Search Confirm Swap Partition

After you’ve identified the swap partition or file, execute the below command to deactivate the swap area.

Or disable all swaps from /proc/swaps

Run free command in order to check if the swap area has been disabled.

Disable Swap Partition

In order to permanently disable swap space in Linux, open /etc/fstab file, search for the swap line and comment the entire line by adding a # (hashtag) sign in front of the line, as shown in the below screenshot.

Disable Swap Partition Permanently

Afterwards, reboot the system in order to apply the new swap setting or issuing mount -a command in some cases might do the trick.

After system reboot, issuing the commands presented in the beginning of this tutorial should reflect that the swap area has been completely and permanently disabled in your system.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Monitor Per Process Bandwidth in Linux

Linux echo Commands

Linux ls Command

Find Which Process Using Port in Linux

Linux Top Command Examples and Usage

Check Hardware and System Information in Linux

6 thoughts on “How to Permanently Disable Swap in Linux”

The “free -h” commands must be executed when the system is under heavy load. Otherwise, it does not provide the information necessary to determine whether a swap partition or space is needed. When executed on an idling system, the command will only tell you the size of the swap partition and that it is not being used. It’s like running the “top” command on an idling system to see the CPU Load. It will show the CPU Load to be negligible.

I agree with S. Daniels on the use of GParted. It not only provides a visual representation of your disks but also can delete your swap partition and recover that space by moving and/or resizing other partitions. Using the command line to accomplish your tasks may be ‘leet’ and cool but it is also dangerous to the health of your system. Using GParted prevents misspelling or use of incorrect CLI commands, as well as the use of incorrect options which can result in making the drive unusable.

These instructions are rather outdated for any linux with a desktop:MATE, xfce, Gnome or KDE/Plasma. Firstly, the program Gparted very nicely displays swap size, location and UUID. “blkid”, especially on a dual-boot or system with multiple OSes is just going to display a lot of confusing and unhelpful entries.

The KDE partitioner is inferior, but adequate. The centos-swap is fairly specific to CentOS Linux, this should be explained in the article. A swap file can also be used in place of a dedicated partition, this should also be mentioned.

“Vi” is very much overkill for editing fstab. “Vim” is easier than “vi” for newbies in every case, and “pico /etc/fstab” or “nano /etc/fstab” are more appropriate here.

Finally, for José , 30GB is seriously wrong. I suspect he somehow changed a data or system partition into a swap partition. He can “manage flags in Gparted” to inspect it for contents.

I’m just a hobbyist, but have nearly 20 years experience, since a Debian bootable CD, the first Linux installation disk that did not need a floppy to boot, came out in 2000.