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.

  • henfredemars@infosec.pub
    ·
    10 months ago

    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
      hexagon
      ·
      10 months ago

      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
        ·
        10 months ago

        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
          hexagon
          ·
          10 months ago

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

    • blackbrook@mander.xyz
      ·
      10 months ago

      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
        ·
        10 months ago

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

        • blackbrook@mander.xyz
          ·
          10 months ago

          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
            ·
            10 months 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.

  • selokichtli@lemmy.ml
    ·
    edit-2
    10 months ago

    Some years ago I needed to use more than 100 GB RAM in a 32GB RAM computer, repeatedly. zRAM and swapping in a SSD made the whole thing bearable. In the pandemic, RAM was expensive and I was broke.

  • Rescuer6394@feddit.nl
    ·
    edit-2
    10 months ago

    Isn't zswap enabled by default?

    having zram + swap on disk isn't the same as having zswap + swap on disk? the difference should be only that zram show as a swap device while zswap does not.

    having only zram, you are still confined by the total ram you have. idk how the average compression ratio is, but you can gain 1.5x ram max. to get more, you need a physical swap device.

    is there an advantage of using zram instead of zwap? when you still have a physical swap with lower priority.

    bonus question: What if I use all 3 of them? would this just be redundant?

    • TheWoozy@lemmy.dbzer0.com
      ·
      10 months ago

      I used zram + swap for years. I dedicated 25% of my memory to zram. The problem is that zram would get filled with infrequently used data, and disk swap would get the frequently used data. Once that happens everything slows down.

      Zswap tries to fix that be creating a compressed swap buffer in memory. Older/less used data will get written to disk, but fresh/frequently used data will stay in the compressed ram buffer. That's my understanding, at least. I don't remember how to query Zswap usage stats.

    • wolf@lemmy.zip
      hexagon
      ·
      10 months ago

      I am using Debian 12 and I am pretty sure zswap is not enabled by default.

      With zstd the compression ratio is better than 3 in all experiments I saw. (Of course you won't get this numbers for random/encrypted data). Right now I have 12MB compressed to 2MB via ZRAM (fresh reboot) which is a factor of 6.

      So, taking 3 as factor learned from others and my experience, with 1.8 GB of ZRAM I can store 5.4 GB of memory, adding the 1.8 GB of usual RAM, I end up with 7.2 GB of RAM which is double my 3.6 GB RAM I started with. (All this is backed by 4 GB of physical SWAP.)

      Sorry, I cannot really answer your questions concerning zswap vs ZRAM, I just follow the herd and trust that the Fedora people usually have good reasons for their technical choices and are deploying ZRAM by default for several years now.

      • neo [he/him]
        ·
        10 months ago

        zstd

        Just btw, while zstd's compression ratio might be stronger, it will not be as fast as something like lzo-rle. When it comes to RAM you will definitely want to prefer speed unless you have a strict space usage requirement.

        • wolf@lemmy.zip
          hexagon
          ·
          10 months ago

          A valid point and hard to find an objectively right answer (I searched for some information regarding this topic and found for example [this](https://www.reddit.com/r/Fedora/comments/mzun99/new_zram_tuning_benchmarks/ thread on reddit).

          In my totally not scientific benchmark of running my backup script with time, LZ4 clearly outperformed ZSTD and no ZRAM at all, when I was generating some CPU load in the background. (LZ4 was 14% faster compared with ZSTD, 19% faster compared to no ZRAM).

          I am thinking about switching to LZ4 or even lzo-rle for some time and observe, if I hit the physical swap. If not, I hope to get some speed advantage and perhaps a few minutes longer battery life.

    • spiffeeroo@programming.dev
      ·
      10 months ago

      Arch and RHEL enable zswap by default. Regular x86_64 Ubuntu and Debian do not have zswap nor zram enabled by default.

    • secret301@sh.itjust.works
      ·
      10 months ago

      For me zram made my system more responsive but the oomd didn't really count it as more ram so sometimes things would get killed earlier than I'd want. ZRAM + regular swap fixed this unless an application was getting really greedy. I kinda wanna try all three now

      • Rescuer6394@feddit.nl
        ·
        edit-2
        10 months ago

        check if zswap is already enabled:

        zgrep CONFIG_ZSWAP_DEFAULT_ON /proc/config.gz

        https://wiki.archlinux.org/title/zswap

  • sapient [they/them]@infosec.pub
    ·
    edit-2
    10 months ago

    How does this compare to zswap. For me, if you still want a swap device on a real disk, this might be better? Idk >.<

    Edit: arch has zswap enabled by default https://wiki.archlinux.org/title/Zswap - someone below says it is better if you have zswap when you already have a swap device :)

    • Atemu@lemmy.ml
      ·
      10 months ago

      You don't want to combine zram swap and physical swap. When zram swap is full, you'll get LRU inversion because it won't ever evict from zram swap.

      Either zram-only or physical+zswap.

    • wolf@lemmy.zip
      hexagon
      ·
      10 months ago

      Sorry, just a user myself and because ZRAM is default on Fedora and was easy to setup on Debian, I am just using it.

      On the Stream, I have a 4G physical swap partition as a backup, though. AFAIK the physical partition will be utilized by ZRAM when needed. (ZRAM simply has higher priority swap).

  • ohmesocorny@discuss.online
    ·
    10 months ago

    Thanks wolf@lemmy.zip !

    Thanks to your post and plenty of config tutorials, I've got this set up on my Oracle Free Tier VPS running Ubuntu. It has recently been struggling hard with 1GB ram, requiring reboot. The difference with zram enabled... WOW.

    I haven't been able to get zram working on my Ubuntu VPS with another provider though - search results suggest that some providers don't allow swap.

    • wolf@lemmy.zip
      hexagon
      ·
      10 months ago

      My pleasure, happy my post inspired you and thank you for your kind words! :-)