How to know if Zram is working?

Recently I re-installed my OS, I set no swap by during the installing so my /etc/fstab after installing was

UUID=37F6-3DC7                            /efi           vfat    defaults,noatime 0 2
UUID=756a4824-1c78-462d-8d48-2ab63126a26c /              btrfs   subvol=/@,defaults,noatime,compress=zstd 0 0
UUID=756a4824-1c78-462d-8d48-2ab63126a26c /home          btrfs   subvol=/@home,defaults,noatime,compress=zstd 0 0
UUID=756a4824-1c78-462d-8d48-2ab63126a26c /var/cache     btrfs   subvol=/@cache,defaults,noatime,compress=zstd 0 0
UUID=756a4824-1c78-462d-8d48-2ab63126a26c /var/log       btrfs   subvol=/@log,defaults,noatime,compress=zstd 0 0
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0

Then I installed a script from AUR

$ yay -S zramd
$ sudo systemctl enable --now zramd

And I commented the tmpfs partition in /etc/fstab file. After rebooting I run

$ swapon --show                    
/dev/zram0 partition   8G   0B  100

Supposedly everything is working fine so far, but I have a doubt about it. In my previous installation this Swap partition was almost always being used (between 500 MB and 4 GB aprox), but now it is almost always in zero by doing the same things like my previous installation. How can I be sure Zram is working properly?

Pdta: I’m using widget Simple Monitor (from KDE) to check status of cores, ram and swap.

Can you show output for cat /proc/swaps

I usually have btop up and running most of the time too, you can see it pretty easily (I also used zram to setup)

1 Like

you could use zram-generator and edit the zram-generator.conf to your needs.

sudo pacman -S --noconfirm zram-generator;sudo vim /etc/systemd/zram-generator.conf

zram-size = 512
compression-algorithm = zstd

check after reboot with
zramctl --output-all

$ cat /proc/swaps
Filename                                Type            Size            Used            Priority
/dev/zram0                              partition       8388604         0               100

How about trying :

sudo systemctl status /dev/zram0
$ sudo systemctl status /dev/zram0
● dev-zram0.device - /dev/zram0
    Follows: unit currently follows state of sys-devices-virtual-block-zram0.device
     Loaded: loaded
     Active: active (plugged) since Sun 2023-06-11 20:09:28 -05; 4h 32min ago
     Device: /sys/devices/virtual/block/zram0

zram is already activated.

zram does not use swap on physical disk, but it compresses swap cache into RAM.
It’s quite different from zswap.

If RAM size is less than 8GB, using zram would be a bad idea.

1 Like

If you are using SSD/ NvMe I doubt you need to use swap very much at all…

It depends on quality of SSD.

Many applications create their own caches and flush them on SSD more frequently than swap.
For example, many people use web browser that downloads multiple media / video streaming on SSD then delete them after watching. People do not notice any problem when using good quality SSD.

Using a swap on a good quality SSD is fine

In my experience it is highly beneficial on lower RAM machines. I use zram on 4GB machines, it is more useful there then on machines with more RAM.

The only time I would avoid zram is if your CPU is not fast enough to handle the compression. In those cases the compression overhead may cause performance to decrease.

Yes, that is an advantage.

There are other some disadvantages:

  • Zram would not support hibernation. (Maybe many people do not use hibernation).

  • Zram compresses work cache and swap cache into RAM alone, that’s more overhead than RAM and swap.

Sure but my comment was in reference to using zram with less than 8GB of RAM. The hibernation(suspend to disk) is true no matter how much RAM you have.

But the trade-off is that swap is so much higher performing. It all depends on your use case and workload. For me, the effective performance is much higher on zram with 4GB for my workload but it can be different someone else with a different workload.

My only point was that stating you need at least 8GB of RAM for zram to be a good option differs from my experience.

1 Like

@dalto , will this process be of any help to OP ?

swapoff /dev/zram0
zramctl --reset /dev/zram0
systemctl daemon-reload
systemctl start /dev/zram0

and then :

swapon --show

might show it working ?

The OP already has it working I think.

But since he told that it was not showing, so it reminded of my issue when ZRAM was activated but was not showing in both HTOP and System Monitor. So I thought this might be of help, as it helped me during that time.

Probably should ask the OP directly but it looks to me like it is showing up but doesn’t have any usage.

I searched from my archived pages, and there was almost same situation :

But I agree with you completely.

I just reinstalled zramd, I’m gonna monitor its status, but I have a question: I frequently use sleep, it’s OK with zramd?

I just uninstalled zramd and installed zram-generator, but after 1 hour (and some minutes) playing AoE4, well my Swap partition shows 0GB as used, so weird :roll_eyes:

that sounds like normal because it’s in memory.