ZRAM compresses memory pages in RAM instead of swapping to disk; the algorithm sets the trade between CPU time and memory saved.
The default on most modern distributions is lzo-rle: very fast, low CPU overhead, reasonable ratio. Confirm what is active — the bracketed entry is in use:
cat /sys/block/zram0/comp_algorithm
lzo [lzo-rle] lz4 lz4hc zstd
| Algorithm | CPU cost | Speed | Ratio |
|---|---|---|---|
lz4 | lowest | very fast | worst |
lzo-rle | low | very fast | medium |
lzo | low | fast | medium |
zstd | higher | slower | best |
lz4hc | high | slow | better than lz4 |
Pick lz4 when the CPU is weak or loaded and RAM is cheaper than cycles, lzo-rle for the default balance, zstd when memory is scarce and CPU is not.
Changing it at runtime:
echo lz4 | sudo tee /sys/block/zram0/comp_algorithm
Persistently, with systemd-zram-generator:
[zram0]
zram-size = ram / 2
compression-algorithm = lz4
Config lives at /etc/systemd/zram-generator.conf; the change needs a reboot. A poor ratio costs RAM — pages wait longer to be reclaimed — so lz4 suits a machine already swapping heavily.