How to Permanently Disable Swap in Linux? - GeeksforGeeks (2024)

Last Updated : 08 Oct, 2021

Summarize

Comments

Improve

Swapping or swapping space is a physical memory page placed at the top of a disk partition or a special disk file that is used to expand a system’s RAM as the physical memory fills up. Inactive memory pages are often dumped into the swap area when no RAM is available, using this method of expanding RAM resources. However, swap space is much lower in transfer speeds and access time compared to RAM, due to the spinning speed of standard hard disks.

Reserving a small partition for swapping will significantly increase access time and speed transfer compared to conventional HDD on newer machines with fast SSD hard drives, but the speed is still lower than RAM memory. Some say that it is appropriate to set the swap space to twice the amount of computer RAM. However, swap space should be set to 2 or 4 GB on systems with more than 4 GB of RAM.

If your server has sufficient RAM memory or does not need the use of swap space or your device output is significantly reduced by swapping, you can consider disabling the swap field.

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

free -h 

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

How to Permanently Disable Swap in Linux? - GeeksforGeeks (1)

Next, check for TYPE=”swap” line after the blkid command to define the swap partition, as shown in the screenshot below.

blkid

How to Permanently Disable Swap in Linux? - GeeksforGeeks (2)

check swap partition type

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

lsblk

How to Permanently Disable Swap in Linux? - GeeksforGeeks (3)

Search Confirm Swap Partition

Run the below command to deactivate the swap area after you have identified the swap partition or file.

swapoff /dev/mapper/centos-swap 

Or disable all swaps from /proc/swaps.

swapoff -a 

To check if the swap area has been disabled, run the free command.

free -h

How to Permanently Disable Swap in Linux? - GeeksforGeeks (4)

Disable Swap Partition

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

vi /etc/fstab

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

mount -a

After a system reboot, the commands presented at the beginning of this tutorial should be issued to indicate that the swap area in your system has been completely and permanently disabled.

free -hblkid lsblk 

In simple ways or the other step:

If you really want to disable swapping (note: this is not suggested, even if you’re pretty sure there’s more than enough physical RAM), follow these steps:

  • Run swapoff -a: this will immediately disable the swap.
  • Remove any swap entry from /etc/fstab.
  • Get the system rebooted. Ok, if the swap is gone. If it’s still here for some reason, you have to remove the swap partition.
  • Repeat steps 1 and 2 and, after that, use fdisk or parted to delete the (now unused) swap partition. Use great caution here: removing the wrong partition would have devastating results!


Please Login to comment...

How to Permanently Disable Swap in Linux? - GeeksforGeeks (2024)
Top Articles
Colour perception and taboos in Japan.
How To Use Promotion Codes To Drive Sales (2023) - Shopify Australia
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Sen. Emmett Berge

Last Updated:

Views: 6077

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Sen. Emmett Berge

Birthday: 1993-06-17

Address: 787 Elvis Divide, Port Brice, OH 24507-6802

Phone: +9779049645255

Job: Senior Healthcare Specialist

Hobby: Cycling, Model building, Kitesurfing, Origami, Lapidary, Dance, Basketball

Introduction: My name is Sen. Emmett Berge, I am a funny, vast, charming, courageous, enthusiastic, jolly, famous person who loves writing and wants to share my knowledge and understanding with you.