1

I have set up a system that has 4 GB RAM with 1.5 GiB of zram. It also has zswap enabled. I don't have any swap partition on the secondary storage.

As I have noticed, the performance is good on my systems.

Is the zswap being used on zram? Can using zswap on zram lead to any performance issues?

15 Volts
  • 1,969
  • 2
  • 19
  • 34

2 Answers2

1

Zram and Zswap are two independent utilities.

Zram occupies part of memory with compressed pool(-s) which are used as in-memory swap devices. Zswap uses similar in-memory pool with compression but also can flush its content to swap file/partition.

So, you don't need Zswap since you have no swap. Just use Zram.

Paulo Tomé
  • 3,754
  • 6
  • 26
  • 38
Leonid
  • 11
  • 1
  • Could you add some info on the second question: "Can using zswap on zram lead to any performance issues?"? It does not seem to make sense to have a compressed memory buffer for a compressed memory swap, but the question is whether it even harms or whether zswap is smart enough to be noop if the swap space is a zram device. Otherwise, depending on kernel build options, one might even need to disable it actively via `zswap.enabled=0`, when aiming to use zram swap only. – MichaIng Mar 15 '23 at 13:04
1

As per this answer:

  • zswap is a swap-specific, compressed, RAM-based "pre-cache". zswap requires a separate swap device.
  • zram is a compressed, RAM-based block device (that can be used for swap).

I recommend against using both together. If you don't have disk-based swap, use only zram.

If you use both zswap and zram, I suspect the following will happen:

  1. When a page is swapped out, the page will be sent to zswap.
  2. zswap will compress the page.
  3. If the page compresses well, zswap will store the page.
  4. If the page compresses poorly, zswap will send the original (uncompressed) page to zram.
  5. zram will compress the page.
  6. zram will store the page.

In other words, some pages will be redundantly compressed twice. This will result in wasted CPU cycles.

Since both zswap and zram store compressed pages in RAM, there is no advantage to using both.

Also, since zram is not a "pre-cache", using zram with other swap devices will be less performant than using zswap (at least in certain situations as explained here).

mpb
  • 1,501
  • 1
  • 15
  • 23