Live data from Hacker News

Stop making swap partitions—use swap files instead

gist.github.com

181–190 of 256 posts

Re: Stop making swap partitions—use swap files instead

#183

[flagged]

Also, this seems to be based on a email from 2005, about kernel version 2.4 and 2.6, and their differences. Things might have changed since then, and also depends on a lot of factors, not the least what filesystem you use. I'm not sure people should seriously follow advice that basically boils down to "do this always it's best". Better instead to make yourself informed about the tradeoffs, then make your own choice,…

This recommendation is based off the current implementation.

See:

https://github.com/torvalds/linux/blob/827751b699b79a6e56998...

https://github.com/torvalds/linux/blob/827751b699b79a6e56998...

The thread is quoted to show that they have been functionally equivalent for several decades and yet distros continue to push outdated recommendations.

Re: Stop making swap partitions—use swap files instead

#184

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

> If you have a small root partition, the default config

Of what distro? If you mean that the example code shows the swapfile directly under / , well of course you don't have to do it that way.

> With a partition, it's easier to put swap on a separate physical device, which is good for performance.

I think this is untrue on both counts. First, nobody is going to dedicate an entire physical device to swap, because the smallest storage devices you can get are enormous compared to the RAM they're trying to support. If the device is "separate" (from what, / ?) but still has other things on it, it's even less clear why this would matter for performance. But also it's trivial to put a swapfile on whatever device you want. It can be anywhere reasonably sane in the filesystem, you just give it a path.

> you can share a single swap partition between distros no problem

The file could go on whatever partition the distros can share. Maybe put it under /home or something. It's your system, the FHS is up to your own interpretation.

> And of course there's hibernation, as others have mentioned.

Why would that matter? You're expecting a file not to survive the low-power state?

Re: Stop making swap partitions—use swap files instead

#185
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.

Looks like this was added in util-linux 2.40. Works with btrfs correctly too! Added.

Re: Stop making swap partitions—use swap files instead

#186

Earlier quoted context omitted.

On x64 CPU for laptops the memory bandwidth is rather limited and a fast compressor like lz4 can saturate it. As the result latest SSD are faster then z-ram when using hardware encryption on SSD.

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.

Re: Stop making swap partitions—use swap files instead

#187

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

> If you have a small root partition, the default config Of what distro? If you mean that the example code shows the swapfile directly under / , well of course you don't have to do it that way. > With a partition, it's easier to put swap on a separate physical device, which is good for performance. I think this is untrue on both counts. First, nobody is going to dedicate an entire physical device to swap, because the…

GP is not presenting these as evidence for an approach, just notable facts that weren't initially obvious.

Re: Stop making swap partitions—use swap files instead

#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.
Post reply on HN