Running Out of RAM on Linux? Add Zram Before Upgrading!

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. :grin: 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
Prevents OOM Killer? :white_check_mark: Yes, keeps more data in RAM :white_check_mark: Yes, keeps more data in disk swap
Works without disk swap? :white_check_mark: Yes (disk swap can be removed) :cross_mark: No, requires traditional swap
Compression Savings :white_check_mark: Can use full RAM for compressed swap :white_check_mark: Yes, compresses pages for swap
Performance on Chrome Tabs :white_check_mark: Keeps inactive tabs in compressed swap :white_check_mark: Reduces swap pages size on disk

Zswap is a swap cache, not a swap device.

– It only compresses memory when swap is actually needed.
– Zram always reserves memory upfront, Zswap only uses memory dynamically as swap pages are created.
– 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.