375
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
[-] skullgiver@popplesburger.hilciferous.nl 80 points 1 year ago* (last edited 11 months ago)

[This comment has been deleted by an automated system]

[-] wolf@lemmy.zip 27 points 1 year ago

Thanks, great input.

I totally agree - ZRAM isn't magic and of course it will fall flat on its face for loads of encrypted, compressed or pure random data. In my limited day to day usage I just never hit that situation, so far.

Again, I fully agree, I wouldn't have expected that the N4120 works so well with ZRAM. For work I am forced to use a recent mac with loads of RAM. When just browsing the web/checking emails I don't feel any noticeable difference between the mac and the Stream for the CPU. (Of course, CPU/IO bound tasks are another story, and the display of the mac is in another league.) Usually I would consider myself to be quite sensitive to speed, I notice a real difference between using Gnome (with impatience etc. extensions) and Xfce, concerning the responsiveness of my desktop.

I'll check the BIOS settings, I expect the same as you. Not sure, if I will lower the reserved RAM for the iGPU, everything works fine at the moment and I want to try some light gaming on this machine.

[-] blackbrook@mander.xyz 2 points 1 year ago* (last edited 1 year ago)

I'm not going to remember the right terminology, but you can also configure it with a chunk of disk to stick files that it can't compress into so they don't end up clogging up your swapspace.

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

Not sure if you are referring to ZSWAP, which is backed by physical swap and writes uncompressable pages to the physical swap. ZRAM has AFAIK an option called WRITEBACK, which allows it to also use physical swap, but I didn't find that ZRAM is concerned if it can compress the page or not. (Grain of salt and if someone is more knowledgeable I happily be corrected.)

[-] blackbrook@mander.xyz 4 points 1 year ago* (last edited 1 year ago)

I'm talking about ZRAM and I did mean writeback.

"With CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page to backing storage rather than keeping it in memory."

From https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html

[-] wolf@lemmy.zip 1 points 1 year ago

Thank you.

One naive question, because it honestly confuses me:

Right now, my ZRAM swap space has a higher priority than my physical swap space. In my tests, this does what I would expect: It doesn't touch physical swap before the ZRAM is filled.

In my mind, it works like this: I should be better off, with this setup as long as my swapping always only touches the ZRAM.

If I configure writeback, does it mean that ZRAM could just write pages out before it is filled, because the algorithms decide the page is IDLE/does not compress. Additional it seems it could wear out my flash memory ("If there are lots of write IO with flash device, potentially, it has flash wearout problem so that admin needs to design write limitation to guarantee storage health for entire product life.").

In short, for me it looks like a worse option in my use case compared to the two separate swap partitions. Any thoughts?

[-] blackbrook@mander.xyz 2 points 1 year ago

As someone who has always been cautious about SSD writes (possibly overcautious/ paranoid? Idk, some seem to think it's not a concern with modern SSDs. But I haven't really spent any time researching recently.) I always like to have a hard disk as well as an SSD and I put my writeback device and any swap partitions there.

Sorry this probably isn't a helpful answer.

[-] wolf@lemmy.zip 1 points 1 year ago

No worries, SSDs/sd cards feel different when one grew up with hard disks.

Anecdotal: I am running Raspberrry Pis as home servers for nearly 10 years by now. In the beginning, the sd cards would die within a short period of time. (The first we months, perhaps year?)

I don't know if it is a combination of better tuning of Raspbian and improvements in the sd card technology, but I haven't had a problem with sd cards for at least 9 years now, and at least one Pi is running 24/7 at all times, with lots of IO. (Full disclosure: I am also over provisioning the Pis with big sd cards, to hopefully have better wear leveling.)

With SSDs I personally never experienced hardware failures, OTOH with the dropping prices I bought new ones and replaced the old ones regularly.

What I do nowadays on my machines:

  • ZRAM w/o writeback and a 2nd physical swap device (the physical swap is never touched, even in my low memory devices)
  • I set noatime mount option for all my SSD/sd card to decrease unnecessary reads/write
  • After a hard disk failure many years ago, my important data is backed up to other machines nearly continuously (that's the primary role of the 24/7 Pi)

Don't know if it is helpful, but I would recommend you to use noatime, experiment with ZRAM with zstd and see if your swap is touched at all and use BTRFS for checksums, to detect any trouble with your SSDs early on.

[-] ohmesocorny@discuss.online 2 points 1 year ago

On Raspberry Pi, a larger SD card helps spread out those writes. Alternatively, get a high endurance SD card which is made to handle more writes. Log2ram helps further by journaling logs in RAM then dumps them to your SD card once a day (or at configured interval)

Personally, I just boot my Pi from an SSD in a USB3 enclosure, with log2ram running - best of both worlds.

[-] wolf@lemmy.zip 1 points 1 year ago

Nice, thanks for the hint!

[-] severien@lemmy.world 7 points 1 year ago

Programs shouldn't get confused since RAM/swap is transparent for them.

this post was submitted on 02 Sep 2023
375 points (100.0% liked)

Linux

48097 readers
621 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