Live data from Hacker News

Debunking Zswap and Zram Myths

chrisdown.name

41–50 of 70 posts

Re: Debunking Zswap and Zram Myths

#41
A simpler alternative to OOM daemons could be enabling MGLRU's thrashing prevention: https://www.kernel.org/doc/html/next/admin-guide/mm/multigen...

I'm using it together with zram sized to 200% RAM size on a low RAM phone with no disk swap (plus some tuning like the mentioned clustering knob) and it works pretty well if you don't mind some otherwise preventable kills, but I will happily switch to diskless zswap once it's ready.

Re: Debunking Zswap and Zram Myths

#42
post #3

User here, who also acts as a Level 2 support for storage. The article contains some solid logic plus an assumption that I disagree with. Solid logic: you should prefer zswap if you have a device that can be used for swap . Solid logic: zram + other swap = bad due to LRU inversion (zram becomes a dead weight in memory). Advice that matches my observations: zram works best when paired with a user-space OOM killer. Bol…

> Many consumer SSDs ... under synchronous writes, will regularly produce latency spikes of 10 seconds or more Surely "regularly" is a significant overstatement. Most people have practically never seen this failure mode. And if it only occurs under a heavy write workload, that's not something that's supposed to happen purely as a result of swapping.

Online-upgrading a rolling distro with a browser running is enough to see it happen regularly.

Re: Debunking Zswap and Zram Myths

#43

Would be nice if zswap could be configured to have no backing cache so it could completely replace zram. Having two slightly different systems is weird. There's not really any difference between swap on disk being full and swap in ram being full, either way something needs to get OOM killed. Simplifying the configuration would probably also make it easier to enable by default in most distros. It's kind of backwards t…

> Would be nice if zswap could be configured to have no backing cache You can technically get this behavior today using /dev/ram0 as a swap device, but it's very awkward and almost certainly a bad idea.

And you can use a zram-backed ram0 if you're still undecided :D

Re: Debunking Zswap and Zram Myths

#44

With zram, I can just use zram-generator[0] and it does everything for me and I don't even need to set anything up, other than installing the systemd generator, which on some distros, it's installed by default. Is there anything equivalent for zswap? Otherwise, I'm not surprised most people are just using zram, even if sub-optimal. [0]: https://crates.io/crates/zram-generator

It's a handy tool, but it doesn't even give you a reasonable zram size by default and doesn't touch other things like page-cluster, so "I don't even need to set anything up" applies only if you don't mind it being quite far from optimal.

Re: Debunking Zswap and Zram Myths

#45
post #10

Is this advice also applicable to Desktops installations?

I get the impression that most desktop users enable zram or zswap to get a little bit more out of their RAM but there is never any real worry about OOM, not regularly anyway, so then (according to the principles laid out in the article) it shouldn't matter much.

On my workstation, I run statistical simulations in R which can be wasteful with memory and cause a lot of transient memory pressure, and for that scenario I do like that zswap works alongside regular swap. Especially when combined with the advice from https://makedebianfunagainandlearnhowtodoothercoolstufftoo.c... to wake up kswapd early, it really does seem to make a difference.

Re: Debunking Zswap and Zram Myths

#46
post #19

Would be nice if zswap could be configured to have no backing cache so it could completely replace zram. Having two slightly different systems is weird. There's not really any difference between swap on disk being full and swap in ram being full, either way something needs to get OOM killed. Simplifying the configuration would probably also make it easier to enable by default in most distros. It's kind of backwards t…

This is actually something we're actively working on! Nhat Pham is working on a patch series called "virtual swap space" ( https://lwn.net/Articles/1059201/ ) which decouples zswap from its backing store entirely. The goal is to consolidate on a single implementation with proper MM integration rather than maintaining two systems with very different failure modes. It should be out in the next few months, hopefully.

Very exciting, thanks!

Re: Debunking Zswap and Zram Myths

#47
Thank you for all your wonderful work, Chris! Just curious: is it feasible to eventually support sending the page clusters to backing swap in their compressed state to further reduce I/O? It's my understanding that the clusters get decompressed before getting sent to disk, which I presume is to simplify addressing.

Re: Debunking Zswap and Zram Myths

#48

Earlier quoted context omitted.

The better distros have it (ZRAM) enabled by default for desktops (I think PopOS and Fedora). In my personal experience every desktop Linux should use memory compression (except you have an absurd amount of RAM) because it helps so much, especially with everything related to browser and/or electron usage! Windows and macOS have it enabled by default for many years (even if it works a little different there).

I did an Archinstall setup this weekend, and that also suggested zram.

Because it's an easy solution esp. to a rather new installer: setting up swap on disk (partition or file, if file which file system, if partition w/o encryption, ...). Zram: install one additional package and forget.

See also the "zram on Fedora" section in the article.

Re: Debunking Zswap and Zram Myths

#49
Been using zram since it hit the kernel, with the same priorities "petard" and disk backed swap. I don't remember the details now, but zswap many years ago would not handle hibernation "well" (as well as it can get..), or not better than zram+distinct hibernation with -XXX priority. But zram definitely has some caveats with that setup and it will lead to disk cache being used and requiring manual flushing, for example after hibernation, because zram-generator (if you're using it) isn't ready yet on resume, from what I recall about it. This seems like such a neatly written post I'm going to try and go with zswap from now on.

Re: Debunking Zswap and Zram Myths

#50
You mean zswap part of cleancache? But that fell out of kernel completely, no? And zram gained support for backing device.

BTW most of zram tutorials get it wrong, you are supposed to manually mark idle pages and initiate writeback by periodically writing to /sys/block/zramX/idle and /sys/block/zramX/writeback . Otherwise zram will never ever write anything to backing device. It is documented in kernel docs, just that if you expect it to work automatically you might misread it.

And you can convert swap into such backing device, but then you don't do swapon on it (just remove it from fstab) nor it's necesary to format(mkswap) it.

Post reply on HN