I dug out my old Asus Zenbook (UX305CA) and refurbished it: gave it a good cleaning, replaced the thermal paste, installed a new battery, upgraded the SSD, and did a clean install of Ubuntu 24.04 (don’t judge; everything else in my house is still Debian and/or OpenWRT).

The only thing I can’t upgrade is the memory since it’s soldered on. It’s got 8 GB which hasn’t really been a limit given my use cases, but since I’m in upgrade mode, I was thinking of running it with zram configured.

I just setup zram and gave it 50% of the physical memory as a starting point, set vm.swappiness to 140, and am using zstd as the compression algorithm.

Haven’t noticed much difference, so there doesn’t seem to be much CPU performance penalty even on this low-spec CPU (base clock 900 MHz lol). zramctl shows it’s got 726 MB swapped to it currently which is compressed to 126 MB. Not bad! The only thing I haven’t done yet is set the power profile to “Power Saver” - if there are going to be noticeable performance penalties, that’s probably when it will show up.

I’ve only ever used zram on Raspberry Pis and on an old netbook, so I’m not sure if using it on a machine with an otherwise usable amount of RAM is even worth it.

Thoughts and/or suggestions for a better config?

  • Chewy@discuss.tchncs.de
    link
    fedilink
    arrow-up
    10
    ·
    13 hours ago

    I’m using zram on all my systems, be it 4GB or 16GB. Usually swap is empty, so there’s no compressing for the CPU to do anyway. If a RPI is capable of ZRAM, your PC won’t break a sweat.

    ZSTD is really fast. I’m using btrfs compression too, and don’t notice any performance impact either.

  • potatoguy@potato-guy.space
    link
    fedilink
    arrow-up
    5
    ·
    12 hours ago

    Zram is good, i would use lz4 as a compression method, it uses a lot less CPU than zstd and compression makes it around 50% bigger than compressed using zstd (50% compression vs 33% compression on zstd). So on CPU bound scenarios, it holds better than on zstd in my opinion. Same on btrfs, it feels a lot faster on lzo than on zstd.

  • who@feddit.org
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    12 hours ago

    I suspect zram’s swap device only consumes RAM when it actually contains swapped pages, but I don’t know for sure. Can anyone link an authoritative statement on this?

    I use it on a 32 GiB workstation, also with PERCENT=50 and ALGO=zstd in Debian’s /etc/default/zramswap, and vm.swappiness=60. This is its only swap device. I like that it avoids needless SSD wear and painfully slow interactivity during large compile and compression jobs.

    Is it worth it on your system, which has only 2 CPU cores? If your memory-intensive workloads compress well, then I would think yes, for the same reasons that I like it. If you find your CPU struggling with it, you could always change to a lighter compression algorithm.

    On the other hand, if your memory-intensive tasks don’t compress well, then no, I would not expect it to be a good use of your CPU.

    You’ll never know until you try it. I suggest checking the output of zramctl when running tasks that create memory pressure.

    • Admiral Patrick@dubvee.orgOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      21 minutes ago

      I suspect zram’s swap device only consumes RAM when it actually contains swapped pages, but I don’t know for sure. Can anyone link an authoritative statement on this?

      I’m wondering the same. I haven’t read anything authoritative, but it definitely seems like it only consumes the RAM it’s using. Otherwise, it wouldn’t be able to create block devices that exceed the physical memory. I started to wonder when I had it set to 50% (4 GB) and gave it a stress test. The 4 GB it allocated filled up but was compressed to just about 1 GB, so I thought “surely this isn’t wasting 3 GB of RAM to hold 1 GB of pages.”

      The guidelines I’ve read seem like there’s some guesswork involved in the planning. Basically you can make the zram device as large as you want so long as the compressed data is less than the physical RAM (not all pages compress equally as you mentioned).

      I’ve since bumped it to 200% of system ram (16 GB), and I think that’s probably good enough for my use cases. I’m seeing about a 4:1 average compress ratio, so I could go higher, but 8 GB has been plenty usable up until now. :shrug: I also left the original swap file in place with a lower priority as a spillover (I’m not really missing the 4 GB of disk space that uses, so might as well keep it).

  • InnerScientist@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    13 hours ago

    How much ram were you using? With how little ram Linux uses in normal operation only some applications will make you feel a difference.

    • Admiral Patrick@dubvee.orgOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      13 hours ago

      I haven’t really watched usage since I dug it out and wiped it, but it mostly depends how many tabs I have open at a given time. It’s mostly used for web browsing, web apps, and basic productivity software (Thunderbird, Matrix, LibreOffice, etc).

      When I used it last in late 2022, it was typically using most of its memory (excluding filesystem cache) keeping a bunch of browser tabs open.

  • vividspecter@aussie.zone
    link
    fedilink
    arrow-up
    3
    arrow-down
    1
    ·
    edit-2
    12 hours ago

    I go even further and set the proportion to 100%, since ZSTD compresses so well (and the % is based on uncompressed usage).

    There are theoretically some cases where zram can be harmful, but in general I find it works reliably.

    • Admiral Patrick@dubvee.orgOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      12 hours ago

      Yeah, I’m still tweaking things and just kindof came to the same conclusion I need to bump it up.

      I was assuming that it thick-allocated the RAM for the compressed swap block device, but it seems to be dynamic now that I’ve read deeper into it. I just bumped it from 50% to 350% (basically one extreme to another).

      • Rimu@piefed.social
        link
        fedilink
        English
        arrow-up
        3
        ·
        edit-2
        12 hours ago

        On my 8 GB laptop I had it at 100% for a while and it slowed my laptop down a lot. At 50% it’s much happier.

        I can’t remember the compression method, ymmv

  • dgdft@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    12 hours ago

    No notes — I’d do the exact same thing based on your description. You can always unwind if CPU usage is too high under load.