Using ZRAM on a laptop with 8 GB RAM. Worth it or waste of CPU?
Using ZRAM on a laptop with 8 GB RAM. Worth it or waste of CPU?
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.
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.
I go even further and set it to 100%, since ZSTD compresses so well (and the % is based on uncompressed usage).
There are theoretically some cases where ZSTD can be harmful, but in general I find it works reliably.
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).
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
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.
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).
I just checked that 32GiB system that runs zramswap at PERCENT=50, and free -h is reporting 27GiB available. I think that confirms my suspicion.
So, I don’t think there’s any significant down side to running zramswap even if your system never needs to swap. :)
I have some Linux installed on my x240, Mini PC, and 12th Gen Intel Core i3 laptop with ZRAM without any issues.
Here are screenshots of the dual boot Linux on my old Mini PC, Celeron with 8GB RAM and 500GB HDD