Rule of thumb / TL;DR:If your system only uses swap occasionally and keeping swap demand within ~20–30% of your physical RAM as zram is enough, ZRAM is the simpler and more effective option. But if swap use regularly pushes far beyond that, is unpredictable, or if your system has fast storage (NVMe), Zswap is the… continue reading.
Rule of thumb / TL;DR:If your system only uses swap occasionally and keeping swap demand within ~20–30% of your physical RAM as zram is enough, ZRAM is the simpler and more effective option. But if swap use regularly pushes far beyond that, is unpredictable, or if your system has fast storage (NVMe), Zswap is the… continue reading.
This article hopefully serves to balance the recommendation between both ZRAM and Zswap. At the very least, remove some of my previous bias.
The community discussion this was based on can be followed here:
As well as the related forum topics below the comments.
Quick reference for the settings and outcomes when using Zram and Zswap:
Metric (System with 16 GB or RAM) | 1.5:1 | 2:1 | 3:1 |
---|---|---|---|
Likely algorithm(s) at this ratio | LZ4 | LZO | Zstd |
ZRAM — 4 GB | |||
Max zram disksize (GB) | 4.00 | 4.00 | 4.00 |
Max uncompressed stored in zram (GB) | 4.00 | 4.00 | 4.00 |
Approx. RAM used by zram when full (GB) | 2.67 | 2.00 | 1.33 |
Resident RAM left for everything else (GB) | 13.33 | 14.00 | 14.67 |
Max uncompressed working set before any disk swap (GB) | 17.33 | 18.00 | 18.67 |
ZSWAP — pool cap 20% of RAM = 3.20 GB | |||
zswap pool cap (GB) @ 20% | 3.20 | 3.20 | 3.20 |
Max uncompressed cached in zswap (GB) | 4.80 | 6.40 | 9.60 |
Approx RAM used by zswap at cap (GB) | 3.20 | 3.20 | 3.20 |
Resident RAM left for everything else at cap (GB) | 12.80 | 12.80 | 12.80 |
Max uncompressed working set before any disk swap (GB) | 17.60 | 19.20 | 22.40 |
Notes
• ZRAM has a fixed uncompressed cap equal to its disksize. Actual RAM used by zram is allocated dynamically as pages are compressed and swapped out, not all at once when the device is initialized.
• ZSWAP also grows on demand up to its pool cap. When full, it starts evicting to the backing swap device.
Nice to see this empirical comparison. I haven’t dug into swapping alternatives much because it’s been an extremely rare event that any of my systems swap, especially the most current ones. It may be because I seldom run enough software concurrently to exceed the actual amount of real memory present, so the most that happens is that context switching alters which processes are active, but all in memory. On my favorite system i do allocate an ordinary swap file; I’ve never seen it active; still, these statistics are useful and undoubtedly valid for any system that’s running a lot of software, whether a laptop, desktop, or server.
Thanks for the details and for your honest assessment in the comparison of swapping techniques and technologies. I’ll definitely keep this in mind, especially if any inefficient use of resources is detected.