Swap or not?

Werft den pösen Puben zu Poden!

رمي العانة الشريرة في القرون!

Ah!
:sweat_smile:

Completely agree. I just added another 8 gigs of ram to have 16 like I prefer and even with 8 gigs I rarely went over 2.5 used. Setup the system with no swap partition or file and I’m not noticing any performance decrease because of that choice.

4 Likes

I personally always swap. I only have laptops though. I use hibernate a lot. Swap = RAM. If it’s an HDD, it’s a partition, if it’s an SSD, it’s a file.

If it’s a desktop, it’s completely your call. Just remember, no swap, no hibernate.

3 Likes

Is there a reason for this? I’ve heard some stuff about a swap partition being harmful for SSDs (as opposed to a file), but is that something to be concerned about for, say, my laptop with 8GB RAM?

Yes, technically any write operation = bad for SSD = each write reduce it’s lifespan.

Personally i would not use swap for 8 Gb RAM, unless you need to hibernate or do something very heavy routinely…

With 4 Gb i would think about it maybe :upside_down_face:

1 Like

That’s pretty much how I think about swap. With 16 GB RAM, it’s unlikely you’ll ever need it in normal usage. And if you do happen to need it, making a swapfile is literally 10 seconds of work (and waiting maybe 5 minutes for dd to do its magic and copy zeroes to it). Or, if you don’t need swap, but are really paranoid about running out of memory, you can set up systemd swap.

If you want to hibernate, you need swap, of course. A swap partition is easier to setup for hibernation, but a swap file will always be more flexible.

I’ve got 5 GB of RAM on my laptop, and it needs swap. I made a 7 GiB swapfile for it, just so it can hibernate without any worries. It’s a bit wasteful, but I’ve got a 2 TiB HDD in it, so I don’t care.

But I do notice it writing to the swapfile from time to time, even in normal usage (when opening more than a couple of tabs in Firefox, for example). Not very often, and it rarely uses over 500 MiB of swap, but it does use it.

If it bothers you, try to override default (too aggressive in my opinion) settings:

  1. Reduce swappiness
    /etc/sysctl.d/99-sysctl.conf

    vm.swappiness=10
    
  2. Reboot

1 Like

It does not bother me, as it is really rare. But I did set swappiness to 10 on it a long time ago (when I was testing those performance tweaks by librewish). Didn’t notice any difference, to be honest :slight_smile:

1 Like

(hmm, my system’s currently set up to hibernate soon after closing the lid…)

In that case, is a swap partition any more detrimental than a swap file? I’d be inclined to try replacing my swap partition with a file if it’ll extend the lifetime of my SSD.

1 Like

It makes no difference for SSD’s longevity whether you write to a file or a swap partition. Writing is writing.

2 Likes

You may also want to read about Zram/zswap

3 Likes

I’m not really 100% sure to be honest. @keybreak said about what I’ve read, although I do don’t exactly understand it. Basically since you partition it it will always write to the exact same block which is fine on spinning rust, but not ideal for an SSD. Although I’m not sure why that wouldn’t also be true with a swap file,I don’t know. But that’s what i read on the internet, so I know it’s gotta be true, even if I don’t understand it.

1 Like

Looks like we’re not the only ones who can’t find a good answer :grin:

My other computer has a swap partition on a Samsung Evo 850 SSD. I’m going to leave it and see how long it goes before the HD fails. It’s been there since May 1, so I’ll let you know when it fails.

Well either way they’ll wear SSD about the same, coz however you look at it - it’s still a part of disk which physically writes, regardless if it is partition or file…

I doubt there is some drastic difference…

@fbodymechanic
Samsung SSDs are best ones, hopefully it will live for years and years :slight_smile:

3 Likes

Please correct me if I am wrong, but today’s SSDs will survive several hundred TBs (or more) worth of writing. For a swap partition/file that at any rate will seldom or rarely be used, I wouldn’t think there is so much to worry about the disk’s longevity. It very well might fail for other reasons than having a swap partition/file set up, hibernating included. I can’t see a scenario when a user hibernates so many times during a day and then writing many GB data to the disk each time. That is not my use case anyway.

1 Like

Depends on system / tasks at hand (for example if you use Android studio routinely :rofl: ), but to me it is just completely excluding most obvious possible point of failure - which is always good.

1 Tb may be way faster than you probably think, with some setups and use cases - you’d be surprised :wink:

For example after analyzing disk writes on Windows back in a day - i always disable Firefox’s disk cache (again, you’d be very surprised it’s daily writes), and you don’t really need it if you have enough RAM.

1 Like

At the end of the day, the use case is then a far more important factor when it comes to a disk longevity than the “evils” of a swap file/partition “per se”.

As an average user, who doesn’t strain my systems that much, I wouldn’t think swapping is something to worry about.

Actually, if I don’t think I need hibernation I set up an small amount of zram for just in case the kernel is in dire need to move some files out of the way.

1 Like

For the most part yes, but you know…
If you’re thinking about mitigation of risks :slight_smile:

Imagine that you left some program in the night and gone to sleep, on the next morning you see that it’s memory-leaking like crazy (think of Deepin for example :rofl: ) and you have additional i don’t know…30 Tb written by your swap :laughing:

  • Is it rare?
    Yes

  • Is it possible?
    Yes

Swap is for punks: “live fast - die young!” :upside_down_face:

P.S. Never trust robots :robot:

3 Likes