this post was submitted on 02 Sep 2023
335 points (98.3% liked)

Linux

48092 readers
1383 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
335
ZRAM is insane (www.kernel.org)
submitted 1 year ago* (last edited 1 year ago) by wolf@lemmy.zip to c/linux@lemmy.ml
 

I got a cheap netbook style laptop for traveling some weeks ago (HP Stream 11" with 4 GB of RAM and a N4120). Didn't expect much more from this hardware than opening a few browser tabs and doing some retro gaming via Steam.

Shared RAM with graphics card means that 3.64 GB of RAM are effectively usable for the OS. This was even too little RAM to open a handful of tabs w/o having tabs being unresponsive for seconds sometimes in a very annoying way. Another thing which made trouble was the Wifi - I guess it went into power saving, was swapped and didn't load fast enough to provide a good experience. (Of course I wasted an hour checking for Wifi drivers/support.)

In short: Even for my low expectations for this laptop it was an underwhelming experience.

First step was to look at my vm.swappiness and set it to 10, which already helped, but still the machine had hiccups and annoying timeouts.

In a last, desperate effort I enabled ZRAM on the laptop... and literally WTF: Saying it is a night and day difference doesn't do the experience justice. Typing this words now on the Stream, which I use exactly the same way as my much more beefy other machines (my next worst computer has 8G of RAM and an Intel Core i3), browsing with 10 open tabs, e-mail client open on another virtual desktop... it is crazy, it makes the Stream fun to use and I use it at home for everything which isn't heavily CPU/IO bound.

What surprised me the most: No hiccups, no timeouts and it even fixed the Wifi issues on this little machine. Didn't expect this would be possible, especially with a N4120 and 3.64 GB of RAM.

In short, my laptop changed from not even reaching my low/realistic expectations to being my favorite technical purchase of the last years, thanks to ZRAM.

Besides making this a ZRAM appreciation post, I really want to spread the word about it. Especially for old hardware and limited RAM situations, IMHO it should be the first thing which comes to mind/is recommended.

Fedora and PopOS use it by default, so it is well tested and should IMHO again, be a default at least for desktop setups.

Give it a try - supposedly it even improved the experience on much more beefy computers for gaming etc.

you are viewing a single comment's thread
view the rest of the comments
[–] henfredemars@infosec.pub 23 points 1 year ago (2 children)

If you like ZRAM, make sure you also enable MG-LRU and consider using ZSWAP with z3fold allocator instead because it's capable of dumping older compressed pages to swap file whereas ZRAM, once full, is simply bypassed until pages in the store are freed.

I do number crunching on memory constrained systems. MG-LRU improves the efficiency of page reclaim, and ZSWAP interacts much more nicely if you have a swap file also.

[–] wolf@lemmy.zip 8 points 1 year ago (1 children)

Thank you for your advice. Right now my setup works so I'll try to not waste my entire weekend playing with technology, but if I need further tweaks in the future I'll look into ZSWAP.

One question: Do you know why Fedora and PopOS decided for ZRAM and against ZSWAP? As I wrote already somewhere else: I did choose ZRAM for it being default in Fedora, which gave me some trust that people better informed/experienced choose ZRAM over ZSWAP.

[–] henfredemars@infosec.pub 7 points 1 year ago (1 children)

Totally understandable. I have done the wasting of weekends just to go back to where I started.

I think that ZRAM has a simpler implementation and has a history of being more widely used whereas ZSWAP is only recently seeing more usage as a default. I suspect it's in the interest of stability and because the implementation is better characterized.

With that said, MG-LRU is not enabled by default for the same reason, but it has a big impact such that it's the default on newer Android devices. Stability is a relative term.

[–] wolf@lemmy.zip 2 points 1 year ago

Thank you very much for the write up! I'll have to investigate more about ZSWAP. Have a nice weekend!

[–] blackbrook@mander.xyz 1 points 1 year ago (1 children)

This is a theoretical advantage of ZSWAP over ZRAM, but when I researched it, every real world comparison I found seemed to find that ZRAM performed better even when this advantage should have come into play.

[–] henfredemars@infosec.pub 1 points 1 year ago (1 children)

I'd be very interested in references to that research so I can improve the performance of my memory constrained systems.

[–] blackbrook@mander.xyz 1 points 1 year ago (1 children)

Sorry, it's been a while since I read this stuff and I don't have the links. The state of web searching these days sucks and I can't easily find them.

One bit I remember was that a lot of the concern about LRU inversion in ZRAM that might make ZSWAP look preferable is out of date since the addition of a writeback option to ZRAM. I also remember people claiming that ZRAM had an advantage in being multithreaded.

FWIW I find this three year old answer saying the kswapd that ZSWAP uses is single threaded but there is a patch to make it multithreaded that significantly improves it's performance. No idea if this is out of date.

[–] henfredemars@infosec.pub 1 points 1 year ago

Yes, I researched this, and I can't tell if one of those patches to enable multithread compression was accepted. Considering that zswap is making it into some default configurations of big distros, I would hope that they'd do some testing, but I can't say for sure.