Over the past few weeks, the RAM (or system memory) usage on my workstation has increased due to a heavier workload across multiple workspaces. Largely due to an increased number of open web browser tabs as well as other applications spread across 8 other workspaces. With 16 GB of RAM on my system, lately I’ve… continue reading.
Over the past few weeks, the RAM (or system memory) usage on my workstation has increased due to a heavier workload across multiple workspaces. Largely due to an increased number of open web browser tabs as well as other applications spread across 8 other workspaces. With 16 GB of RAM on my system, lately I’ve… continue reading.
I’d love to hear how Zram works for you, especially if you’re trying it for the first time! For those who’ve already been using it, feel free to share your setup, tweaks, tips, and screenshots.
One thing I didn’t mention in the article was the dual-channel compromise when adding more RAM. My B550 has 4 RAM slots and I have 2×8GB running in dual-channel at, 3600MHz. If I add just 1 more 8 GB, my system will go into mixed dual/single-channel mode where the first 16 GB will be in dual-channel and the extra 8 GB will be in single-channel and potentially lose some performance.
To keep full dual-channel, the best approach would be to add 2 more 8 GB to make 32 GB (4×8GB) and keep the 3600MHz. But when you populate all 4 slots some boards will downclock the RAM to make it more stable, including mine, from reading they will drop to 3200Mhz, then there’s the Infinity Fabric Clock (FCLK) which I have set at 1800MHz.
In any case, before next reboot I will adjust my Zram config to use 25% (4 GB RAM) instead of 50%. I’ve been working on this article for the past week, during which I noticed that 8 GB of Zram was overkill. So instead, 12 GB RAM will be untouched, and 4 GB will be used for Zram swap.
EDIT (additional thoughts on this topic)
Regarding swappiness
The Arch Wiki recommends vm.swappiness=180 - I understand it, given how much faster Zram is compared to disk-based swap. However, I think a lower setting (< 100) also acknowledges the reality that Zram is still significantly slower than RAM itself.
While Zram offers a major speed advantage over traditional swap, it still introduces compression and decompression and CPU overhead, making it far from a perfect replacement for direct memory access.
I’ve also been experimenting with different values. Setting vm.swappiness=200
caused swap to Zram to kick in at ~85% memory usage.
At swappiness=10
, swap didn’t start until ~95% memory usage, which closer to the behavior I prefer.
This reinforces my preference for a low swappiness (10 - 50), keeping RAM usage prioritized before swapping. That said, I can see higher values (< 100) being useful for systems that struggle with memory pressure. Especially if there’s less than 8 GB of RAM installed.
100+ swappiness still seems a bit aggressive, to me, but it’s worth testing different values based on your workload.
What about Zswap?
Feature | ZRAM | Zswap |
---|---|---|
Best for | Desktop, many apps and browser tabs | Servers, gradual swap usage |
Visible in swapon ? |
Yes | No (hidden inside RAM) |
Acts as swap device? | Yes | No, compresses and sends to swap |
Delays OOM Killer? | ![]() |
![]() |
Works without disk swap? | ![]() |
![]() |
Compression Savings | ![]() |
![]() |
Performance on Chrome Tabs | ![]() |
![]() |
Zswap is a swap cache, not a swap device.
– It only compresses memory when swap is actually needed.
– For systems with fast SSDs or NVMe, Zswap can reduce disk swap writes while still letting the SSD handle overflow.
Zram on the other hand, creates a compressed swap space in RAM as a compressed block device.
– Some RAM is “reserved” for Zram, so less RAM is available for applications.
– However, because of compression (e.g. Zstd 3:1 or 4:1), you can store more data than the default allocated RAM.
– If you allocate 4GB to Zram, you don’t “lose” 4GB, you get extra up to 12GB extra.
Consider trying out vm.page-cluster=0 too, reference: “new zram tuning benchmarks” on the fedora Reddit, can’t post links here, yet.
Thanks, @stereomato Added that link for you. Also see: Trust Level System (Guide).
This morning, I’ve been benchmarking RAM vs. Zram vs. disk swap (NVMe).
I tried this out. I’m not really sure how well I’ll notice if this improves my machine’s performance but I enjoy learning about ‘tweaking’ and improving performance through configuration and similar methods.
Hopefully this info isn’t too sensitive but this is what I’m working with.
And here are my results. At least here are the outputs of the same commands in the original post!
My disk is a HDD. It can sometimes feel slow, it might take 8-10 seconds to load google chrome when I launch that and I can hear the disk spinning as data is retrieved. But that being said its not horrible. I can run minecraft Java, I tried some shaders and they ran very laggy (the game ran fine but the image was jumpy so maybe lag isn’t correct), I tweaked a lot of the performance video settings very low and It ran very smoothly but at that point, why even try to use shaders. So after I did that I thought, maybe this has more to do with my GPU than working memory anyways and also I do not know if I would need to allocate more RAM for minecraft after doing the zram/zswap tweaks for those to be able to take affect.
If this topic went way over my head and I’m confusing anyone, apologies! I at least appreciated this post and enjoyed the process of trying it out.
Nice! You probably won’t notice any improvement until you have exhausted memory and started swapping to Zram.
Since you are using a HDD there are some suggested kernel tweaks for your setup:
Change the Zram size to 2 GB instead of 4. (25% instead of 50%) Then make sure ALGO=zstd
because the higher compression is better. This will mean 6 GB RAM untouched, 2 GB that can store ~ 6 GB of in-memory zram swap. So the net effect will be 12 GB stored in memory before needing to swap to HDD.
Then tweak these:
vm.dirty_background_ratio = 5
vm.dirty_ratio = 10
vm.swappiness = 10
vm.vfs_cache_pressure = 100 #(default)
vm.dirty_expire_centisecs = 1500
vm.dirty_writeback_centisecs = 1500
vm.page-cluster = 0
vm.dirty_expire_centisecs
& vm.dirty_writeback_centisecs
Reduces large sudden writes by flushing dirty pages more frequently (15 seconds) in smaller batches, preventing big I/O spikes.
vm.page-cluster=0
Ensures that when swap is needed, pages are read in smaller chunks. (default 3, higher means more I/O)
These help to reduce large sudden writes by spreading them out more evenly, which is especially useful for HDDs to avoid I/O bottlenecks.
Also apply advice here:
Reduce logs they write frequently, etc. Be careful. Apply all of these at your own risk and responsibility.
I’ve been following the zram discussion for a while now. Never used zram, does it really do that much for everyday use or rather for special use cases (e.g. VMs)?
If you use more than 90% of installed RAM or, if you have non-zero value for swap “used” it’s worth checking out. If you have slowdowns and freezing during high swap “used” then it will improve that. Check the table above.
Okay, changes made. Advice appreciated, thank you. I will be giving the other article some time soon. It looks like there is some information there about nvmes and other resources, I think it will work out for me to test out these tweaks on this machine with the HDD. I think I can see how tweaks like this could help my other machine using nvme. I currently have 16G RAM on that machine, but I need to use as much as I can for a VM. After experimenting with this so far it made me think, I can maybe utilize this to maximize efficiency on my other machine since I want to use RAM as heavily as possible.
Recently I’ve been using even more RAM (20GB+ but only 16 GB installed). I know I should probably buy another stick of 8G RAM since there are 4 slots. But instead, I increased ZRAM further from 25% to 50% of total RAM. I wanted to see what happened and if it was slow. It was not any slower, but there was one big issue as mentioned below.
In any case, going back to where this started…
Original Setup (no ZRAM):
- 16 GB regular RAM (all available for system use)
- 1 GB swap disk partition
- Effective total memory = 17 GB (RAM + disk swap)
Next when I wrote this article, I used ZRAM at 25% (4 GB):
- 12 GB regular RAM (not used for zram)
- 4 GB zram block device, compressing data ~2:1
- Effective zram capacity = ~8 GB compressed swap
- Effective total memory = ~20 GB (RAM + zram swap)
Yesterday I tried ZRAM at 50% (8 GB):
- 8 GB regular RAM (not used for zram)
- 8 GB zram block device, compressing data ~2:1
- Effective zram capacity = ~16 GB compressed swap
- Effective total memory = ~24 GB (RAM + zram swap)
So about 24 GB total but only 8 GB of straight RAM. (not good) So this morning when I tired to resume for sleep/standby, no go! lol for obvious reasons.
So ZRAM is really only useful when you need about 15 to 25% more legroom.
Today I disabled and uninstalled ZRAM, and created 32 GB of file swap (overkill):
At the end of the year I’ll add a 3rd 8 GB mem stick and revert to the 1 GB swap partition, then add ZRAM 25% if I end up using more than 25 GB and face the original OOM/locking issue again.
After 2 days of uptime on my workstation, it looks like I could benefit from doubling my RAM:
Very cool. Thanks for sharing.
Heyo I’m using a huge file in my Ext4 partition as swap file. Are there any advantages using Zram instead a swap file? I remember my Fedora originally had 8gb Zram and I disabled it in favor one single swap file.
Honestly good question because if you asked that 2 months ago I would just flat out say yes: ZRAM is always better than plain file or disk partition swap.
Now, I would say it depends. If you have slow storage, like HDD or older SSDs, then yes it’s almost always better in every situation.
But if you have NVMe storage, realistically using NVMe backed swap (Hynix Platinum) I don’t notice any slowdowns in the least. However, on paper zram is still more efficient.
The problem is, if you are genuinely in need of a ram upgrade that is 1.5 to 2x current ram installed I would say swap space to NVMe works great because I hit a bug when using 50% of ram for zram where by the computer would freeze when trying to resume from sleep. I found the changes needed to solve that as it had something to do with the timing of the compression. But unless you have HDD or slow SSD I would say it’s best to just go with regular swap space until physical RAM upgrade.
That said, zswap can be a smart middle ground. It compresses pages in RAM before they hit your swap device, reducing writes and improving latency. Unlike zram, it doesn’t require a fixed RAM allocation and still uses your swap file or partition if needed. If you’re running into zram issues or want a flexible setup, zswap can quietly improve performance without the quirks of pre allocating blocks of your memory.