Live data from Hacker News

Stop making swap partitions—use swap files instead

gist.github.com

111–120 of 256 posts

Re: Stop making swap partitions—use swap files instead

#111
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 hardware today which makes most of the other stuff wholly irrelevant.

Re: Stop making swap partitions—use swap files instead

#114
post #2

Swap files are also much easier to set up than partitions if you're using full disk encryption.

For what it's worth(not much) On OpenBSD swap is always encrypted, With or without full-disk encryption. I don't know why linux always has to make the easy things hard.

Re: Stop making swap partitions—use swap files instead

#116

Earlier quoted context omitted.

... which then kills sshd, locking you out of being able to get in and do any recovery.

the system will restart sshd?

the system will kill whatever it damn well pleases. You can tune it with priorities to ask it to try to not kill that, and once it kills your sshd once, you'll probably configure it to exempt sshd from being OOM killed at all. That doesn't fix the memory pressure or hanging or stalling, but you'll at least be able to log into the box still instead of dragging out a serial cable.

Re: Stop making swap partitions—use swap files instead

#119

Earlier quoted context omitted.

> does anyone know why In a nutshell, overcommit. It's more or less broken by design but it's also incredibly practical so pretty much everyone does it. Couple that with the fact that it's difficult bordering on impossible to correctly determine the culprit. If you've got 16 GB RAM and the user launches 3 processes each of which attempts to use 8 GB who should you kill?

Notably windows doesn't use overcommit, and degrades much more gracefully under memory pressure. The biggest tradeoff is the amount of disk space consumed by a page file that also has to reserve space for unused pages that have been allocated but never been swapped in. On linux you can turn overcommit off, but there's too much software written around the assumption that overcommit is on

Windows also does a neat trick Linux lacks: automatically adding more swap, up to a limit. Systems with loads of RAM barely lose any storage to swap, but once they do get hit, they can get many gigabytes of swap space without user interaction. I believe macOS does it too, of course.

I'm sure there are many reasons why Linux can't do that by default, but it's a real shame.

Re: Stop making swap partitions—use swap files instead

#120
post #65
post #30

Earlier quoted context omitted.

If you want to share step-by-step, I’ll update the gist.

That’s my point, it’s different for each distro & partitioning setup, so I wouldn’t know what to share here. Having a swap partition makes it as easy as adding `resume=/dev/sdXYZ` or `resume=UUID=…` to your kernel parameters.

And using LVM for "partitioning" bypasses a lot of this silliness. Do 'lvcreate --contiguous' and you should be good to go if you're using most any non-toy initrd.

Given that every r/w filesystem you're going to use as your '/' on a Linux desktop or server supports online growing (and most support offline shrinking), it's nuts to me to hear people worrying about getting partition sizes correct. With LVM, if you get it wrong you just resize the LV and the filesystem it contains.

Hell, LVM makes swapping out disks a really easy online operation. [0] If you don't have nice hot-swap drive caddies, you might have to power off the box once to add in the new disks and again to remove the old ones, but all the data transfer can happen while the system is in use.

[0] Assuming the new and old disks have the same logical sector size, which they usually do.

Post reply on HN