Enable and use zRAM instead for swap

  • Kubuntu 24.04
    • Doesn’t use zram or zswap by default at all.
  • Ubuntu Desktop 24.04
    • Apparently also doesn’t use zram or zswap by default at all anymore!
  • Fedora 40
    • zram enabled by default. Places swap on zram, with the zram device set to 50% of RAM size. (Changes/SwapOnZRAM - Fedora Project Wiki) This mentions the device size is capped at 4 GB, however on my 16 GB VM the zram device is 8 GB so maybe they increased that. Algorithm used is lzo-rle, which is fast but doesn’t compress all that well.
  • Debian
    • Not enabled by default, no recommendations for size or algorithm, mentions using zram-tools or systemd-zram-generator for easier management of zram devices.
  • Arch Linux
    • Not enabled by default, documentation suggests creating a device half the size of available memory but mentions that making a device with a size equal to or larger than available memory is acceptable. Suggests using the zstd algorithm, which compresses better, and mentions that real-world use often shows a 3:1 compression ratio.
  • Manjaro
    • Not enabled by default, documentation suggests creating a device twice the size of available memory. Also suggests using the zstd algorithm.
  • Gentoo
    • Not enabled by default, documentation (which is very thorough) mentions a plethora of different sizes and algorithms and makes no effort to recommend any particular size or algorithm that I can tell. Also mentions the 3:1 compression ratio.

So really it’s all over the map. Personally, I’ve previously used a zram device equal to the size of my physical memory with lzo-rle compression, but recently have been experimenting with a zram device size of (physical memory size - 1 GB) * 3 with zstd to see how it goes. Personally I think using zstd rather than lzo-rle is a very good idea if we’re going to try using zram devices larger than physical memory, since it should compress better according to zram-config/README.md at main · ecdye/zram-config · GitHub

lzo-rle is the fastest with zstd having much better text compression.

I personally would shy away from supporting hibernation. It’s incompatible with Secure Boot, systems sometimes experience malfunctions when using it with Linux (maybe even oftentimes), and it requires that RAM contents be saved to disk either unencrypted or with a recoverable encryption key, which is a substantial reduction of security since now otherwise volatile data is now persistent.

1 Like