this post was submitted on 02 Sep 2023
362 points (98.4% liked)

Linux

46794 readers
1135 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
362
ZRAM is insane (www.kernel.org)
submitted 11 months ago* (last edited 11 months ago) by [email protected] to c/[email protected]
 

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
[–] [email protected] 20 points 11 months ago (4 children)

Rolling out ZRAM to all my boxes right now! 🙃

Do you also tweak other settings for ZRAM? According to ArchWiki PopOS settled for the following settings:

vm.swappiness = 180
vm.watermark_boost_factor = 0
vm.watermark_scale_factor = 125
vm.page-cluster = 0

I am testing this settings right now and cannot say I experience a difference compared to the defaults.

[–] [email protected] 4 points 11 months ago (2 children)

vm.swappiness value should be between 0 and 100 IIRC.

[–] [email protected] 11 points 11 months ago (1 children)
[–] [email protected] 1 points 11 months ago

Yes. I stand corrected.

So the kernel memory management system wants to free up some RAM... it'll either kick stuff out of the page cache (this is the disk cache), or write some stuff out to swap. vm.swappiness determines "relative I/O cost" of swapping something out versus dropping some disk cache (i.e. how much you think it'll slow the system down.) Total value is 200, so default vm.swappiness=60 means page cache is 140 (200-60). 140/60=2.33, so it considers regular disk I/o to be about 2.33 times the speed of swap. Settings vm.swappiness=100 means swap and disk I/O are equally fast; on modern kernels, in case you had a fast swap system (like some auxillary RAM disk or optane ssds or something) you can even set vm.swappiness over 100 to say 150 to say swap is faster than your regular disk.

https://stackoverflow.com/questions/72544562/what-is-vm-swappiness-a-percentage-of

[–] [email protected] 1 points 11 months ago

I read several articles on this topic, and it seems there are urban legends and misunderstandings about setting vm.swappiness. The 180 was an experimental result from PopOS and Fedora people, and it only makes sense with ZRAM AFAIK. ... anyway, long story short, I ended up with the default of 60 after some testing. ;-)

[–] [email protected] 3 points 11 months ago

I don't really tweak much. I use the Debian default of 50 percent RAM used. For the NAS's I tell it to use lz4 as they're pretty weak cpu-wise.

[–] [email protected] 2 points 11 months ago* (last edited 11 months ago) (1 children)

Has anyone ever actually benchmarked vm.page-cluster = 0? Makes no sense to me to suggest a cpu is so bottlenecked that disabling read-ahead would actually help. If anything it would mitigate the decompression time if it guessed correctly as the work would already be done if left at the default of 3. Normally cpu is not bound when using zram because its quite low cpu anyway.

[–] [email protected] 2 points 11 months ago

For my own usage, I just enabled ZRAM, 50% with zstd and left all other options unchanged, which seems to be the conservative approach and more important: It works on my machines(TM).

I would love to see some benchmarks or even a structured run down about the available options and configurations.

[–] [email protected] 1 points 11 months ago* (last edited 11 months ago) (1 children)

zstd compression algorithm can be overkill depending of your use case. I'd try lz4 compression algorithm just to see if it sits well with you, since it's overally faster, less CPU intensive, than zstd at a possibly negligible compression rate.

[–] [email protected] 2 points 11 months ago

Have been using zstd for compression with ZRAM at least for my raspberry pi for years now, and I don't experience any CPU bottleneck in usual usage, but memory is really scarce, so I'll stick to it.

If I remember correctly, other people on reddit, from Fedora and PopOS did some benchmarks. Fedora defaults to lz4, AFAIK and PopOS to zstd.