Live data from Hacker News

Stop making swap partitions—use swap files instead

gist.github.com

201–210 of 256 posts

Re: Stop making swap partitions—use swap files instead

#201

[flagged]

Respectfully, what a stubborn position to take. You don't want to listen to anyone else, and you don't want to be taught any new information about it that might change your mind.

Debian supports swap files and has information about setting them up in the Debian wiki, so I don't know why you're implying they've taken a stand on the issue.

Re: Stop making swap partitions—use swap files instead

#203

[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.

It's actually incredibly sensible not to just make changes to core OS settings unless you know what you're doing. There are good reasons not to use swap files, which become evident in OOM situations.

Re: Stop making swap partitions—use swap files instead

#204
post #189

There used to be a time when not only the OS required using partitions for optimum performace (swapfiles) but also applications. In the late 90s databases were regularly set up in a way to store their data on raw partitions. There were other types of applications too that required partitions but for databases it was really common. The practice really only died with OSes allowing apps to bypass the normal filesystem c…

If I recall correctly, Oracle best practices back in the day (waaaay back) was always put the DB on raw partitions, which caused us some issues with existing tooling. I've been fortunate enough to not have to pay attention to Oracle best practices in quite a while.

High performance databases still use raw I/O. You get much better control of data placement and write ordering, without filesystem confounders. With traditional spinning rust being replaced with SSDs and SMR it can be even more important.

You may even have different firmware on the disks / disk controllers for database disks.

Re: Stop making swap partitions—use swap files instead

#205
post #86

Use zram instead. This from crappy 8G RAM multimedia/browsing minipc I'm on right now. The SSD is quite slow and browser is memory hungry so it was an improvement from on disk swap. $ zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram0 zstd 3G 482.9M 86.7M 91.8M 4 [SWAP]

Zswap has improved to the point where it is now preferable over Zram.

https://linuxblog.io/zswap-better-than-zram/

There is a few other people documenting the same thing if you look around.

As far as Linux and swap goes, very generally speaking: if you don't have a application that specifically advises against having swap you are almost always better off with it.

If you don't end up using it then it costs you almost nothing. If you end up using it then it just makes your system more efficient because you are giving up performance for less used memory to make way for more used memory. Zswap sweetens the deal.

In the distant past having swap on a desktop was irritating because file system operations from nightly crons would end up pushing your applications into swap. Then when you go to use your desktop in the morning it will grid away at the disk until the memory was loaded back into main. This sort of behavior has been mostly solved for a couple decades now, but somehow the idea that "swap is bad and slow" still persists.

Re: Stop making swap partitions—use swap files instead

#206

Couple of things this didn't consider. * If you have a small root partition, the default config puts the swap file on there, wasting precious space. * With a partition, it's easier to put swap on a separate physical device, which is good for performance. * If you dual boot 2+ Linux distributions or installations on a single machine, as I do routinely, you can share a single swap partition between distros no problem.…

There are lots of very good reasons why running small root partitions on Linux desktops is a very bad idea.

The smart money is on a single large partition for home and root and everything else. This way you get 100% disk availability with zero extra effort and you get maximum performance. No need to shuffle disk space around with resizing partitions or thing volumes or anything like that.

Unless you have some sort of special use case were root partition can't be shared with root then on most desktop setups having a single large partition is the most straightforward way to do things.

Hibernation isn't really something really useful anymore. If people really really want it then I don't see why they shouldn't get it... but I really don't see the point.

Re: Stop making swap partitions—use swap files instead

#207

For a while since RAM sizes have gotten so big I would set up linux servers without swap at all. I figured what is a 2GB swap file going to do if the system has already exhausted 128GB of real RAM? I never saw any issues doing this, but I learned that linux ideally wants some swap space, which it will use for some kind of housekeeping stuff.

It just meant that you spent too much on servers. Either that or they could of been doing more.

Not a big deal. Being efficient isn't really all it is cracked up to be. Sometimes having a big server that sits mostly idle is a good trade off for what you want to accomplish.

Re: Stop making swap partitions—use swap files instead

#208

For a while since RAM sizes have gotten so big I would set up linux servers without swap at all. I figured what is a 2GB swap file going to do if the system has already exhausted 128GB of real RAM? I never saw any issues doing this, but I learned that linux ideally wants some swap space, which it will use for some kind of housekeeping stuff.

I have tried to forego swap because I had hoped that it would avoid swap thrashing, where performance goes into the toilet; I'd rather a process was killed but I could still access the system, than be unable to login to it. But I've found that even with no/little swap, the system can get into high memory pressure situations (even easier because it can't swap out unused pages of libraries and the like), and still go i…

In the distant past there was plenty of times I tried to fix dying web servers by logging in and restarting a rogue process or cleaning up a memory leak... only to have my SSH session and shell sessions being repeatedly killed by OOMs.

Not as big of a problem as it used to be. Both because OOM killer has gotten better and also web servers are such a commodity that remotely cycling them isn't going to cause a outage and is the quickest and cleanest way to get them back into production.

Re: Stop making swap partitions—use swap files instead

#209

Earlier quoted context omitted.

I have tried to forego swap because I had hoped that it would avoid swap thrashing, where performance goes into the toilet; I'd rather a process was killed but I could still access the system, than be unable to login to it. But I've found that even with no/little swap, the system can get into high memory pressure situations (even easier because it can't swap out unused pages of libraries and the like), and still go i…

The old rule of thumb used to be 2x actual RAM for your swap file/partition size. That's probably not right with today's RAM sizes but I'm not sure what the current rule is. I just go with the Ubuntu installer default but I don't know if that's just a fixed number or computed in some way from amount of RAM available.

Some of that was driven by people wanting hibernation to be reliable.

The other part was that it kinda matched the money you were spending on the machine.

The guy with 128MB of ram could likely afford to spend the extra disk space on a swap partition then the guy stuck with just 32MB.

Re: Stop making swap partitions—use swap files instead

#210

Earlier quoted context omitted.

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.

Obviously, running out of memory and resorting to swap (or other safety nets) is less than ideal.

But why reject taking apparently-free steps to soften the blow?

Is there some advantage in making sure that when the wall is hit, it is hit as hard as it possibly can be?

Post reply on HN