[SOLVED] How to disable swap permanently?

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
GNULinux

[SOLVED] How to disable swap permanently?

Post by GNULinux »

i want to completely disable swap from my system

i know that for temporary disabling i can do sudo swapoff -a

but i want to know how can i permanently disable swap(i know its not wise idea but the thing is that my swap is slowing my pc)

thanks in advance
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
jjp2145-oldtimer
Level 3
Level 3
Posts: 157
Joined: Wed Oct 02, 2019 11:43 am

Re: How to disable swap permanently?

Post by jjp2145-oldtimer »

Probably swapoff, then edit out a line of your fstab, and then delete your swapfile.

Please post the results of:

Code: Select all

swapon -show

Code: Select all

cat /etc/fstab
Someone is probably going to ask for an

Code: Select all

inxi -Fxxxz
Have you considered decreasing the swappiness value as an alternative to making do with swap altogether? Please also post:

Code: Select all

cat /proc/sys/vm/swappiness
If you need sudo to edit it, back it up first. If I tell you to edit something with sudo and forgot to tell you to back it up, back it up anyway. sudo cp backup or cat > backup.txt.
phd21
Level 20
Level 20
Posts: 10104
Joined: Thu Jan 09, 2014 9:42 pm
Location: Florida

Re: How to disable swap permanently?

Post by phd21 »

Hi GNULinux,

I just read your post and the good replies to it. Here are my thoughts on this as well.

It would help to know more about your system setup. If you run "inxi -Fxzd" and "lsusb" from the console terminal prompt, highlight the results, copy and paste them back here, that should provide enough information.

It is probably not a good idea to disable the swap system unless your computer has a lot of system memmory ram. The newer Linux systems switched from a swap partition to a swap file which can be adjusted or disabled. As was also suggested, check and adjust the swappiness value.

Easy Linux Tips Project: Speed Up your Mint!
https://easylinuxtipsproject.blogspot.c ... -mint.html

These links have good information on swap management

How To Add Swap Space on Ubuntu 20.04 | DigitalOcean
https://www.digitalocean.com/community/ ... untu-20-04

How to Add Swap Space on Ubuntu 20.04 | Linuxize
https://linuxize.com/post/how-to-add-sw ... ntu-20-04/

How to Disable Swap in Linux
https://linuxhandbook.com/disable-swap-linux/

Change Swap Size in Ubuntu – Linux Hint
https://linuxhint.com/change_swap_size_ubuntu/

How to Create and Adjust Swap Space in Ubuntu 20.04
https://bitlaunch.io/blog/how-to-create ... ntu-20-04/

Adding and Managing Ubuntu 20.04 Swap Space – Answertopia
https://www.answertopia.com/ubuntu/addi ... wap-space/

Hope this helps ...
Phd21: Mint 20 Cinnamon & KDE Neon 64-bit Awesome OS's, Dell Inspiron I5 7000 (7573, quad core i5-8250U ) 2 in 1 touch screen
ThaCrip
Level 5
Level 5
Posts: 987
Joined: Sat Dec 07, 2019 12:13 pm

Re: How to disable swap permanently?

Post by ThaCrip »

Like I am sure many around here probably know, as a general rule it's unwise to outright disable swap. it's unlikely to slow your system in general since if you got at least 8GB of RAM (which just about anyone who really uses their computer should have at the least) and are not doing nothing TOO RAM heavy, the swap file usage will be minimal enough not to have any noticeable performance hit.

but just speaking for myself... I got 16GB of RAM(I was on 8GB of RAM from May 2012 til like Sep or so of 2020) as with the swap file in it's default state (i.e. seems to default to 2GB) I tend to stay under 1% or so even after several days and maybe even weeks of uptime which would be about 20MB max given the standard 2GB swap file and writing that little of data, especially with modern SSD's is unlikely to be noticeable. when I was using 8GB of RAM I want to say my swap file might have gotten to around 20% or so at times but even here I can't say I noticed any obvious performance hit in day-to-day use.

so unless you really have a specific reason/need to disable the swap file. I suggest you just leave it as is and don't worry about it since things are probably just all around safer as they are with the swap enabled ;)

p.s. I think the majority (if not the vast majority) of people will probably find 8GB or 16GB of RAM to be the sweet spot (and is likely what most people have to unless they got a pretty old system or something really souped-up/custom-built) as if you got at least 8GB of RAM your going to have a smooth experience as even with ones browser, with quite a few tabs open running for several days or longer, it's not too easy to blow through 8GB of RAM and gives you a bit of a buffer there to work with. but if you got 8GB of RAM or less I definitely would avoid disabling the swap file. I would probably not even slightly consider it until you have at least 16GB of RAM, if not more.
MainPC: i5-3550 (undervolted by -0.120v (CPU runs 12c cooler) /w stock i3-2120 hs/fan) | 1050 Ti 4GB | 16GB (2x 8GB) DDR3 1600Mhz RAM | Backups: AMD E-300 CPU (8GB RAM) / Athlon X2 3600+ CPU (@2.3GHz@1.35v) (4GB RAM) | All /w Mint 21.x-Xfce
linux-rox
Level 10
Level 10
Posts: 3334
Joined: Sun Jul 19, 2020 9:17 pm

Re: How to disable swap permanently?

Post by linux-rox »

GNULinux wrote: Sat Jan 09, 2021 11:53 am i know its not wise idea but the thing is that my swap is slowing my pc
All disabling swap is going to do is cause out-of-memory errors. For an understanding of how swap works, see this article.

What you should be doing is figuring out why swap is being used, then fix that problem.
User avatar
dandv
Level 1
Level 1
Posts: 44
Joined: Mon Dec 24, 2012 9:18 pm

8GB ought to be enough for everyone, eh?

Post by dandv »

ThaCrip wrote: Sat Jan 09, 2021 4:06 pm if you got at least 8GB of RAM your [sic] going to have a smooth experience as even with ones[sic] browser, with quite a few tabs open running for several days or longer, it's not too easy to blow through 8GB of RAM and gives you a bit of a buffer there to work with.
LOL. Let's not make these kinds of generalization. People have different work patterns. Browsers are notorious memory hogs, esp. Chromium.

I routinely run out of 16GB of RAM.
linux-rox wrote: Sun Jan 10, 2021 12:02 am What you should be doing is figuring out why swap is being used, then fix that problem.
That's unrealistic. You can almost never fix the memory usage patterns of other applications. And advice like "close tabs" is not a real fix for the problem.
Petermint
Level 9
Level 9
Posts: 2979
Joined: Tue Feb 16, 2016 3:12 am

Re: How to disable swap permanently?

Post by Petermint »

Some applications are really messy with memory. I close them after use to free up the memory. Occasionally there is one you have to reboot. Swap,on SSD, keeps you going until you can easily reboot.

When walking to a new beach, driving, and at the end of the day, I shut down instead of hibernate. With SSD, both shutdown and boot are fast. If someone has problems with swap and cannot fix the application, extra memory, SSD, and the occasional reboot are nicer than having applications crash or the OS locking up.

You could also experiment with swapiness to reduce swapping. I find the current default is the best setting.

Some swapping of memory only moves out code pages from when programs start up. If the result is lower memory usage, you could use the spare memory to load temporary files into memory, something that will often save you more time than you lose from a tiny bit of swap. :idea:
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: 8GB ought to be enough for everyone, eh?

Post by MrEen »

dandv wrote: Mon Jan 11, 2021 9:46 pm
linux-rox wrote: Sun Jan 10, 2021 12:02 am What you should be doing is figuring out why swap is being used, then fix that problem.
That's unrealistic. You can almost never fix the memory usage patterns of other applications. And advice like "close tabs" is not a real fix for the problem.
Can't fix is generally true, but if a certain app is causing the issue, a replacement app might be the fix for the OP.

And on that note, GNULinux, you could try running top in the terminal to see what is hogging the memory. Look under the %MEM column.
linux-rox
Level 10
Level 10
Posts: 3334
Joined: Sun Jul 19, 2020 9:17 pm

Re: 8GB ought to be enough for everyone, eh?

Post by linux-rox »

dandv wrote: Mon Jan 11, 2021 9:46 pm
linux-rox wrote: Sun Jan 10, 2021 12:02 am What you should be doing is figuring out why swap is being used, then fix that problem.
That's unrealistic. You can almost never fix the memory usage patterns of other applications.
Assuming the OP's issue actually is a swap problem (not yet demonstrated), what he would be looking for is a memory leak. Surely you know that. The fact remains, if out-of-memory is the problem, disabling swap isn't going to fix it. That will merely cause the system to crash.
User avatar
zcot
Level 9
Level 9
Posts: 2828
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to disable swap permanently?

Post by zcot »

swap will slow the pc down, that is completely normal. The solution is not to disable swap but to disable the things that are causing swap to be used, meaning most of the time you simply have to back off, not open so many web pages or programs.

Many users use an SSD and this makes it to where even when swap is in use you don't really notice an obvious slowdown like you do when using an HDD.

Go ahead and give it a try, but with "intel core i3-7020u 4GB RAM 1TB Hard Disk" you will experience problems unless you change your habits to accommodate the hardware system.

Code: Select all

xed admin:///etc/fstab
put a # at the beinning of the line that says /swapfile or /swap. This will "comment out" that line, and the system will skip reading and processing that individual line at boot(later you'll remove the # to re-enable the swap). Save the file, reboot.

If you have an encrypted setup instead then you need to look in /etc/crypttab to comment out the swap line, and cryptswap in fstab.
GNULinux

Re: How to disable swap permanently?

Post by GNULinux »

zcot wrote: Mon Jan 11, 2021 11:09 pm swap will slow the pc down, that is completely normal. The solution is not to disable swap but to disable the things that are causing swap to be used, meaning most of the time you simply have to back off, not open so many web pages or programs.

Many users use an SSD and this makes it to where even when swap is in use you don't really notice an obvious slowdown like you do when using an HDD.

Go ahead and give it a try, but with "intel core i3-7020u 4GB RAM 1TB Hard Disk" you will experience problems unless you change your habits to accommodate the hardware system.

Code: Select all

xed admin:///etc/fstab
put a # at the beinning of the line that says /swapfile or /swap. This will "comment out" that line, and the system will skip reading and processing that individual line at boot(later you'll remove the # to re-enable the swap). Save the file, reboot.

If you have an encrypted setup instead then you need to look in /etc/crypttab to comment out the swap line, and cryptswap in fstab.
yeah i know thats why i rather reduced swappiness and it worked :D
ThaCrip
Level 5
Level 5
Posts: 987
Joined: Sat Dec 07, 2019 12:13 pm

Re: 8GB ought to be enough for everyone, eh?

Post by ThaCrip »

dandv wrote: Mon Jan 11, 2021 9:46 pm
ThaCrip wrote: Sat Jan 09, 2021 4:06 pm if you got at least 8GB of RAM your [sic] going to have a smooth experience as even with ones[sic] browser, with quite a few tabs open running for several days or longer, it's not too easy to blow through 8GB of RAM and gives you a bit of a buffer there to work with.
LOL. Let's not make these kinds of generalization. People have different work patterns. Browsers are notorious memory hogs, esp. Chromium.

I routinely run out of 16GB of RAM.
Sure, but it's not a stretch to make the claims I did as a general guideline with the 8GB and 16GB of RAM since it's pretty safe to say those are pretty common RAM configurations for many people, give or take a little. many people will be able to easily work with 8GB and 16GB of RAM configurations even though, obviously, I can't speak for everyone.

or I could say this... it's probably pretty safe to say that most people don't have more than 16GB of RAM. this right here says a lot and gives my claim more credibility.

either way, even with 8GB of RAM with a browser for example (especially Firefox since we all know Chrome is a RAM hog), unless one is doing pretty extreme stuff, that's going to be easily 'good enough' for most people browsing websites as long as they don't have a boatload of tabs open and leave their browser running for several days or longer etc.

p.s. I should have mentioned that Firefox is generally less of a RAM hog than Chrome is as I think Firefox is a better overall choice than Chrome is, especially in regards to RAM usage. so I should have been a bit clearer here in that I was mainly referring to Firefox which is the default browser in Mint.
MainPC: i5-3550 (undervolted by -0.120v (CPU runs 12c cooler) /w stock i3-2120 hs/fan) | 1050 Ti 4GB | 16GB (2x 8GB) DDR3 1600Mhz RAM | Backups: AMD E-300 CPU (8GB RAM) / Athlon X2 3600+ CPU (@2.3GHz@1.35v) (4GB RAM) | All /w Mint 21.x-Xfce
User avatar
darkstrike
Level 5
Level 5
Posts: 798
Joined: Fri Jun 03, 2011 5:56 am
Location: Mahone Bay, Nova Scotia, Canada

Re: [SOLVED] How to disable swap permanently?

Post by darkstrike »

Making a late reply to this thread - I found it while trying to fully disable Swap on my mother's laptop. I just wanted to say that I know it's 'unwise' to fully disable swap, but I just want to say that I don't fault anybody for fully disabling it as I've seen cases where it helps things run BETTER.

Case in point, on mom's laptop - a Core i7 Toshiba with 8GB or 12GB of RAM (I think it's 8GB if memory serves, but I might've upgraded it) and an SSD.

8GB should be overkill for her needs as all she really uses it for is email. web browsing, Youtube, posting things on Kijiji and Facebook marketplace and playing simple games (like Aisleriot Solitaire, etc).

I know a swap partition or swap file can cause premature SSD wear if swappiness is set high, so I have the swappiness set to '1' on her laptop....but even still, sometimes I'll look at the System Monitor on it and the swap file will somehow be at 38%, say, even though the RAM is only at something like 55%. Sometimes it gets so high the calls for swap are so great that the machine will slow down TREMENDOUSLY or even freeze...despite the fact the RAM is not fully used. I'm blaming this on the browser as she often leaves it running, even though she only has usually a max of like 6 tabs open at once. Some of them are Kijiji which often has a lot of ads on screen and I sometimes wonder if it's these Kijiji tabs that are at fault.

Long story short, for some reason, despite her Swappiness being set to '1' swap still gets into use excessively and freezes her machine once every week or two despite the fact the RAM is not totally used up. My own laptop also with a Core i7 and 12GB of RAM routinely has 20+ tabs at once in Firefox, plus Discord, TeamViewer and Steam with 60-80% RAM use...BUT, I have swap FULLY disabled on it and I have not had my machine freeze even ONCE in almost a year.

And no, her machine is not freezing for another reason....it's not overheating, I've fully swapped out the RAM with completely different sticks (it used to have 6GB and this problem occurred then too), it's a fresh install of Mint 20.2 that is only a month or two old and it's got a brand new Samsung 870 EVO 500gb SSD that is also only a month or two old.

Anyway, just my $0.02 from my experiences. I'm actually going to disable the swap file on her laptop tonight and see if it makes a difference in her freezing issue! Wish me luck! :)
Image
Image
SimonPeter
Level 5
Level 5
Posts: 579
Joined: Tue Jul 13, 2021 5:13 am

Re: [SOLVED] How to disable swap permanently?

Post by SimonPeter »

darkstrike wrote: Tue Sep 21, 2021 9:33 am Some of them are Kijiji which often has a lot of ads on screen and I sometimes wonder if it's these Kijiji tabs that are at fault.

Anyway, just my $0.02 from my experiences. I'm actually going to disable the swap file on her laptop tonight and see if it makes a difference in her freezing issue! Wish me luck! :)
Use uBlock Origin ( https://github.com/gorhill/uBlock ) for better adblocking in your browser (Firefox, Chromium, Chrome, Edge).
Locked

Return to “Beginner Questions”