Live data from Hacker News

Stop making swap partitions—use swap files instead

gist.github.com

191–200 of 256 posts

Re: Stop making swap partitions—use swap files instead

#191
post #68

Why use swap files when we could have swap directories? ;-) Sprite had (IMO) a really interesting solution to swap. Each host had a directory, referenced by its host ID under the `/swap` directory, and inside that directory, individual segments of virtual memory would be saved: https://github.com/OSPreservProject/sprite/blob/master/src/k... Sprite overcommited memory like a modern OS, and stored segments individually…

I love this kind of stuff. Great share

Re: Stop making swap partitions—use swap files instead

#192

Why do I still need swap space at all, be it a swap file or swap partition? I have 64GB of RAM and I don't overprovision it. WHY DO I HAVE TO CONSIDER SWAP in 2026?

Swap is not recommended on servers where responsiveness and determinism are more important than failure recovery of any one server.

Re: Stop making swap partitions—use swap files instead

#194

Or be a proper computer user and have a full drive on its own dedicated bus for swap. There is literally no point in time where a full swap drive is less performant or useful than swap directories or swap files (and swap files are a relic of the 90s when a single application would need gobs of virtual memory.) Funny watching someone advocate going back to something that sucked when we have far more performant hardwar…

I’m not advocating for anything but for distros to stop recommending swap partitions. I advocate for right-sizing your hardware to predicable workloads and not using swap at all. On your pet servers or desktops where the workload is experimental or wildly unpredictable, swap files make more sense over partitions.

Re: Stop making swap partitions—use swap files instead

#195
post #100
post #96

Typically I see admins create partitions as basically failure domains - if one fills up it doesn't explode things relying on the others. Wouldn't this be worse in that regard? If you end up accidentally filling up your entire disk, you can no longer swap. Vice versa, if you swap aggressively you could end up filling the disk and then break a running process.

Swapfiles are fixed size just like swap partitions. They do not grow and shrink arbitrarily as you swap more/less.

Oh I see so they’re reserved space regardless. That makes sense !

Re: Stop making swap partitions—use swap files instead

#196
post #106

> fallocate / chmod / mkswap Why not "mkswap --size ... --file ...", which does these three things and more? For instance, according to the mkswap man page, "[...] sets the nocow attribute for newly created files [...]" which is a detail that seems to be missing from this gist.

I wrote this years ago before LLMs made it easy to validate guesswork. I’ll update! Good call

LLMs are guesswork. You have to validate them, not the other way around.

Re: Stop making swap partitions—use swap files instead

#197

Earlier quoted context omitted.

This is called an oomkiller. The kernel has one but it kicks in very late and the kernel prefers to do page trashing instead of killing processes. systemd-oomd should be integrated in systemd, you can configure it to your liking and see if it improves your problem.

I wish there was an easy way to configure it to say "target user processes first, specifically java (or these days python)" as in my experience they are always the culprits. Processes owned by system accounts or root should be the last ones killed.

Similarly, in the past I have wished for the ability to exempt a process from the oomkiller. I've run servers where the top memory user was also the server's entire reason for existence, and if that process gets killed the server may as well be down. It would literally have been better for any other process to get killed, but it was always the application process because of the memory usage.

Re: Stop making swap partitions—use swap files instead

#198

Earlier quoted context omitted.

If you care about performance you shouldn't be running from swap period. Swap is just a safety net.

Swap actually helps with performance for the most part. Here's a good summary of what it actually does. https://chrisdown.name/2018/01/02/in-defence-of-swap.html TL;DR that swap shouldn't be seen as "spare RAM", but a mechanism for paging out anonymous pages, which is desirable in many circumstances in avoiding OOM situations and making memory management work better. It paradoxically typically reduces I/O thrashing.

It helps with performance by allowing your system to have more free physical RAM. And by free I mean for caches. It does this by moving data from inactive pages out of physical RAM. You shouldn't care about the peak bandwidth of zram vs. ordinary swap because latency matters more.

Re: Stop making swap partitions—use swap files instead

#199

Earlier quoted context omitted.

If you care about performance you shouldn't be running from swap period. Swap is just a safety net.

I mean, are you saying ‘but more RAM?’ because obviously yes that’s true but not a solution if you already own a laptop, and have you seen ram prices? Also swapping to a fast SSD isn’t like it used to be on spinning discs. I’ve been amazed how responsive Mac neo laptops are and they are swapping all the time.

I'm not saying to avoid swap. It is great at what it was designed to do. I only take issue with optimizing swap for bandwidth when it will never be able to keep up with RAM bandwidth. The MacBook Neo for example has 60 GB/s of RAM bandwidth but only 1.5 GB/s SSD bandwidth.

Re: Stop making swap partitions—use swap files instead

#200

[flagged]

This is one of the most anti-intellectual and unsuitable for HN comments I've ever seen.

You're proudly proclaiming your lack of desire to learn or discuss on a forum meant for those things.

Go to Reddit. That's the right place for you.

Post reply on HN