Swap or not?

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

That would be an extreme and a rare occurrence. It is possible, yes. But how probable?

But I do get your point. If it is possible that anything exists at all, rather than nothing, then everything is possible.

ps. I hadn’t really thought of swap as a philosophical issue…hmm… :thinking:

2 Likes

That would be my guess, but I figured, it’s easier to setup and I’m willing to buy another SSD is it fails withina couple of years. Let’s see if this whole thing holds any water.

2 Likes

Heh, sorry for digging up an old thread, but wanted to share my experience. I took the above advice and my system was very unstable, even with 32 gb of memory. Granted I’m not in the “typical use” category; I run over two dozen containers for development.

The problem manifested in my system massively bogging down and stuttering (choppy music playback, mouse cursor jumping around, etc). After about 20s, apps would terminate and everything would go back to normal.

It took me a while to put two and two together and that things were being OOM killed, and after adding swap (via a file), everything runs fine (and I can actually see the swap being used via top).

So for me, lesson learned, swap is easy, disk is cheap… just do it… :slight_smile:

You should set up a swap device whether or not you have a lot of memory. Swap isn’t just for OOM situations; it can actually help make RAM more efficient, and also (as it sounds you may have discovered) some applications map directly to swap even in situations where that is not ideal.

The article in post #2 of this thread is informative if you are interested: https://chrisdown.name/2018/01/02/in-defence-of-swap.html

This thread is an interesting read as well: https://unix.stackexchange.com/a/190521

If you have plenty of RAM, you can set up zram and use it as a swap device. It’s faster than a disk-based swap device and spares your disk unnecessary writes. https://wiki.archlinux.org/title/Zram

2 Likes