Live data from Hacker News

Debunking Zswap and Zram Myths

chrisdown.name

31–40 of 70 posts

Re: Debunking Zswap and Zram Myths

#31
post #10

Is this advice also applicable to Desktops installations?

The better distros have it (ZRAM) enabled by default for desktops (I think PopOS and Fedora). In my personal experience every desktop Linux should use memory compression (except you have an absurd amount of RAM) because it helps so much, especially with everything related to browser and/or electron usage!

Windows and macOS have it enabled by default for many years (even if it works a little different there).

Re: Debunking Zswap and Zram Myths

#32

With zram, I can just use zram-generator[0] and it does everything for me and I don't even need to set anything up, other than installing the systemd generator, which on some distros, it's installed by default. Is there anything equivalent for zswap? Otherwise, I'm not surprised most people are just using zram, even if sub-optimal. [0]: https://crates.io/crates/zram-generator

Kernel arguments are the primary method: https://wiki.archlinux.org/title/Zswap#Using_kernel_boot_par...

Snag: I had issues getting it to use zstd at boot. Not sure if it's a bug or some peculiarity with Debian. Ended up compiling my own kernel for other reasons, and was finally able to get zstd by default, but otherwise I'd have to make/add it to a startup script.

Re: Debunking Zswap and Zram Myths

#33
post #23

Earlier quoted context omitted.

echo 1 > /sys/module/zswap/parameters/enabled It's in TFA.

enabling != configuring. Are you saying this is all that's necessary, assuming an existing swap device exists? That should be made clearer. Edit: To be extra clear. When I was researching this, I ended up going with zram only because: * It is the default for Fedora. * zramctl gives me live statistics of used and compressed size. * The zswap doc didn't help my confusion on how backing devices work (I guess they're any…

[deleted]

Re: Debunking Zswap and Zram Myths

#34
post #10

Is this advice also applicable to Desktops installations?

The better distros have it (ZRAM) enabled by default for desktops (I think PopOS and Fedora). In my personal experience every desktop Linux should use memory compression (except you have an absurd amount of RAM) because it helps so much, especially with everything related to browser and/or electron usage! Windows and macOS have it enabled by default for many years (even if it works a little different there).

I did an Archinstall setup this weekend, and that also suggested zram.

Re: Debunking Zswap and Zram Myths

#35
>They size the zram device to 100% of your physical RAM, capped at 8GB. You may be wondering how that makes any sense at all – how can one have a swap device that's potentially the entire size of one's RAM?

zram size applies to uncompressed data, real usage is dynamically growing (plus static bookkeeping). Most memory compresses well, so you probably want to have zram device size even larger than physical RAM.

Re: Debunking Zswap and Zram Myths

#36

With zram, I can just use zram-generator[0] and it does everything for me and I don't even need to set anything up, other than installing the systemd generator, which on some distros, it's installed by default. Is there anything equivalent for zswap? Otherwise, I'm not surprised most people are just using zram, even if sub-optimal. [0]: https://crates.io/crates/zram-generator

[deleted]

Re: Debunking Zswap and Zram Myths

#38
There is one more feature that zram can do: multiple compression levels. I use simple bash script to first use fast compression and after 1h recompress it using much stronger compression.

unfortunately you cannot chain it with any additional layer or offload to disk later on, because recompression breaks idle tracking by setting timestamp to 0 (so it's 1970 again)

https://gist.github.com/Szpadel/9a1960e52121e798a240a9b320ec...

Re: Debunking Zswap and Zram Myths

#39
> It only really makes sense for extremely memory-constrained embedded systems

Even "mildly" memory constrained embedded systems don't use swap because their resources are tailored for their function. And they are typically not fans [1] of compression either because the compression rate is often unpredictable.

[1] Yes, they typically don't need fans because overheating and using a motor for cooling is a double waste of energy.

Re: Debunking Zswap and Zram Myths

#40
post #23

Earlier quoted context omitted.

echo 1 > /sys/module/zswap/parameters/enabled It's in TFA.

enabling != configuring. Are you saying this is all that's necessary, assuming an existing swap device exists? That should be made clearer. Edit: To be extra clear. When I was researching this, I ended up going with zram only because: * It is the default for Fedora. * zramctl gives me live statistics of used and compressed size. * The zswap doc didn't help my confusion on how backing devices work (I guess they're any…

It doesn't really need any config on most distros, no.

That said, if you want it to behave at its best when OOM, it does help to tweak vm.swappiness, vm.watermark_scale_factor, vm.min_free_kbytes, vm.page-cluster and a couple of other parameters.

See e.g.

https://makedebianfunagainandlearnhowtodoothercoolstufftoo.c...

https://documentation.suse.com/sles/15-SP7/html/SLES-all/cha...

I don't know of any good statistics script for zswap, I use the script below as a custom waybar module:

  #!/bin/bash
  stored_pages="$(cat /sys/kernel/debug/zswap/stored_pages)"
  pool_total_size="$(cat /sys/kernel/debug/zswap/pool_total_size)"
  compressed_size_mib="$((pool_total_size / 1024 / 1024))"
  compressed_size_gib="$((pool_total_size / 1024 / 1024 / 1024))"
  compressed_size_mib_remainder="$((compressed_size_mib * 10 / 1024 - compressed_size_gib * 10))"
  uncompressed_size="$((stored_pages * 4096))"
  uncompressed_size_mib="$((uncompressed_size / 1024 / 1024))"
  uncompressed_size_gib="$((uncompressed_size / 1024 / 1024 / 1024))"
  uncompressed_size_mib_remainder="$((uncompressed_size_mib * 10 / 1024 - uncompressed_size_gib * 10))"
  ratio="$((100 * uncompressed_size / (pool_total_size + 1)))"
  echo "$compressed_size_gib.$compressed_size_mib_remainder"
Post reply on HN