Zram: how to start using it

Hi, I found this thread https://discussion.fedoraproject.org/t/is-zram-always-installed/106516 and used some of the commands mentioned there. What I get is this:

$ sudo zramctl
[sudo] password for jan: 
[User: jan] @ [Server: Fedora] - [Directory: ~]
$ sudo swapon
[User: jan] @ [Server: Fedora] - [Directory: ~]
$ ls /dev/zr*
ls: cannot access '/dev/zr*': No such file or directory

In other words: nothing.
I then looked in a VM where I use Fedora 39 KDE upgraded to 40 and I do get results, so there it is working.
I then searched the internet to find a way how to enable zram and got different ways how to do so, nothing worked.
So now I come here and ask: how do I setup zram in a way that does work?

I had set this up on my server systems a long time ago and forgot the details.

I read this: Changes/SwapOnZRAM - Fedora Project Wiki
that told me that the default config in installed from package zram-generator-defaults.
That consists of one file /usr/lib/systemd/zram-generator.conf.
In that file it tells you where to config in /etc.

See if that gets you going.

2 Likes

Hello Barry,
Thank you for this answer. I had found the same website already but I didn’t really read it because of this:

Detailed Description
🔗 zram Basic function
The zram† device

I specifically mean the † symbol which tells me (or I must be completely wrong) this is no longer valid.

I compared my host system (where I have no swap) with the VM guest (which has swap) and I found this:

In both systems the /usr/lib/systemd/zram-generator.conf files are the same.
In my host system I have an empty /etc/systemd/zram-generator.conf file, where the guest system does not have the file.

I then deleted the file in the host en rebooted.
Now I do have 8GB of swap, which is half of my RAM.

Thank you again for this help. Have a great weekend.

On my system the /usr/lib/systemd/zram-generator.conf file contains this.

# This config file enables a /dev/zram0 device with the default settings:
# — size — same as available RAM or 8GB, whichever is less
# — compression — most likely lzo-rle
#
# To disable, uninstall zram-generator-defaults or create empty
# /etc/systemd/zram-generator.conf file.
[zram0]
zram-size = min(ram, 8192)

It is my understanding that the file /etc/systemd/zram-generator.conf file overrides the one under /usr/lib so an empty file there would disable creating the zram0 device and using zram swap.
Exactly as stated above with To disable, uninstall zram-generator-defaults or create empty /etc/systemd/zram-generator.conf file.

The same exact method of disabling swap on zram is noted in the page reference linked by Barry above.