Live data from Hacker News

Stop making swap partitions—use swap files instead

gist.github.com

211–220 of 256 posts

Re: Stop making swap partitions—use swap files instead

#211
post #152
post #139

Earlier quoted context omitted.

It does not need it at all. I’ve run a million+ hosts with no swap. You need to be really disciplined about memory allocations (us cgroups) and ok with what happens if you run out (something in that cgroup dies). But there is no “housekeeping “ that requires it.

This comes up every time swap is mentioned. Even if you have plenty of ram, having swap can help with performance. Why? Because the OS can page rarely used or seemingly downright unused dirty pages to swap, freeing up precious RAM for caches. I'd hazard a guess that especially if you run a ton of containers this can help, as there's probably a lot of memory getting dirtied on initialization of containers and their pr…

Something I've never understood is why, say, 60GB RAM + 4GB swap is supposed to be faster than 64GB RAM + no swap. Or why 64GB RAM + 4GB swap is supposed to be faster than 68GB RAM.

I get the hibernation argument, but not the arguments implying swap is always better.

Actively using 60GB RAM and moving 4GB of unused pages to swap (60+4), is somehow faster than actively using 60GB RAM and keeping unused pages in the remaining 4GB RAM (64+0)?

EDIT: If you prefer more round numbers, feel free to replace them with "32GB RAM + 32GB swap" and "64GB RAM + no swap" respectively.

Re: Stop making swap partitions—use swap files instead

#212

Earlier quoted context omitted.

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.

How does a swap file vs swap partition change things in OOM situations?

Re: Stop making swap partitions—use swap files instead

#213

Earlier quoted context omitted.

"Hug", not bug. Referring to a site (presumably under OP's control) crashing due to increased traffic from HN.

But how are they going to fix the hug?

Buying more instances to serve it, I presume.

Re: Stop making swap partitions—use swap files instead

#214
post #152

Earlier quoted context omitted.

This comes up every time swap is mentioned. Even if you have plenty of ram, having swap can help with performance. Why? Because the OS can page rarely used or seemingly downright unused dirty pages to swap, freeing up precious RAM for caches. I'd hazard a guess that especially if you run a ton of containers this can help, as there's probably a lot of memory getting dirtied on initialization of containers and their pr…

Something I've never understood is why, say, 60GB RAM + 4GB swap is supposed to be faster than 64GB RAM + no swap. Or why 64GB RAM + 4GB swap is supposed to be faster than 68GB RAM. I get the hibernation argument, but not the arguments implying swap is always better. Actively using 60GB RAM and moving 4GB of unused pages to swap (60+4), is somehow faster than actively using 60GB RAM and keeping unused pages in the re…

I’m not sure I understand. In your equations, why is swap taking away from RAM? It’s purely additive.

Say you have 64GB of RAM, of which 4GB are dirty pages that are never, or at least very rarely, accessed. With 64GB RAM + 4GB swap, you filled up your swap with them and have 64GB RAM left to use actively. With 64GB RAM + 0GB swap, you only have 60GB RAM left to use actively.

Re: Stop making swap partitions—use swap files instead

#215
post #45

Oh, the irony of: echo "/swapfile none swap defaults 0 0" >> /etc/fstab If we are going full modern, why not create a Systemd unit? ( https://www.freedesktop.org/software/systemd/man/latest/syst... ) if you need more info. If you didn't know this: /etc/fstab is not used directly after the pivot. Systemd parses it, creates units for every record in it, and that's what gets executed in reality. I can't imagine why woul…

[flagged]

This single comment of yours has in my eyes made your entire post worthless.

SystemD has single-handedly consolidated and streamlined Linux administration. I think valid criticism is useful, but calling it malware is a non-sequitur.

Re: Stop making swap partitions—use swap files instead

#216
.. and often the only solution for a VM/hosted machine. It gives you a flexibility you otherwise not have, expand/shrink when needed; a partition is static/fixed in place. Often used them, and still do; `dd of=/swapfile if/dev/zero bs=1M count=1024`/`mkswap`, and `swapon`.

Re: Stop making swap partitions—use swap files instead

#217
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]

On Bazzite I had to use a swapfile and disable zram to have hibernation working

Re: Stop making swap partitions—use swap files instead

#218

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…

Ceph still does this. In fact it migrated the other way - it used to use a file, and now wants a partition.

It needs an LVM partition (logical volume) because it's vertically integrated, and they are more flexible than traditional partitions.

Re: Stop making swap partitions—use swap files instead

#219

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…

was this before mmap(2)?

mmap makes database performance worse, not better, because it makes all I/O blocking.

Re: Stop making swap partitions—use swap files instead

#220
post #212

Earlier quoted context omitted.

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.

How does a swap file vs swap partition change things in OOM situations?

One traditional reason to prefer a swap partition was that the filesystem driver might have to allocate memory. I think swap files bypass the filesystem driver, though - getting the block extents and then accessing the block device at those locations, instead of accessing the file.
Post reply on HN