Zram-generator won't generate any zram device

I have been using zram through defining udev rules according to the instructions in ArchWiki. Inspired by a recent thread in the forum, I did away with them and installed zram-generator. I copied /usr/share/doc/zram-generator/zram-generator.conf.example to /etc/systemd/zram-generator.conf and edited it to read:

# This file is part of the zram-generator project
# https://github.com/systemd/zram-generator

[zram0]
# This section describes the settings for /dev/zram0.
#
# The maximum amount of memory (in MiB). If the machine has more RAM
# than this, zram device will not be created.
#
# "host-memory-limit = none" may be used to disable this limit. This
# is also the default.
host-memory-limit = 9048



# The fraction of memory to use as ZRAM. For example, if the machine
# has 1 GiB, and zram-fraction=0.25, then the zram device will have
# 256 MiB. Values in the range 0.10–0.50 are recommended.
#
# The default is 0.5.
zram-fraction = 0.5

# The maximum size of the zram device (in MiB).
#
# If host-memory times zram-fraction is greater than this,
# the size will be capped to this amount;
# for example, on a machine with 2 GiB of RAM and with zram-fraction=0.5,
# the device would still be 512 MiB in size due to the limit below.
#
# The default is 4096.
max-zram-size = 8192

# The compression algorithm to use for the zram device,
# or leave unspecified to keep the kernel default.
compression-algorithm = lzo-rle

I’m not sure if I have configured it correctly. Upon several reboots I can’t see any zram device in the ouput from swapon -s or free -h . If I have understood it correctly, one does not have to enable any service for this function:

The zram-generator package provides a systemd-zram-setup@.service unit to automatically initialize zram devices without users needing to enable/start the template or its instances.
Source

I don’t know what I am missing. I appreciate any hints/pointers to reolve this issue.
And btw, I have a swapfile in this system but that shouldn’t be any impediment for a zram device being initialized. Or…?

It should “just work”. Is it possible the udev rules you created before are getting in the way?

I removed them before starting out on zram-generator. I’ve got it just working in another system/machine without any glitches. That’s why I am a bit perplexed.

And how about the .cofig file above, are those values appropriate for a system with 16 GB memory?

I think this may be your problem:

Ok. Should I have left it unspecified or set it none?

I would set it to none.

1 Like

That was it! It’s working!

swapon -s 
     
Filename				Type		Size		Used		Priority
/swap/swapfile                          file		10485756	0		-2
/dev/zram0                              partition	7866364		0		100
 free -h 
               total        used        free      shared  buff/cache   available
Mem:            15Gi       812Mi        13Gi       8.0Mi       709Mi        13Gi
Swap:           17Gi          0B        17Gi

Thank you!

1 Like

As a side note, a recent topic here pointed that if you use zram combined with traditional swap, you need to to disable zswap or your zram will be underutilized.

1 Like

Thanks for pointing it out.! Sure, I took note of that in that thread and added zswap-enabled=0 to my kernel parameters. And I don’t have to regenerate grub.cfg nowadays! Feels great!

1 Like

:partying_face:

1 Like

If I am allowed to hijack this topic…

Should zram1 be removed?

$ swapon -s
Filename				Type		Size		Used		Priority
/dev/nvme0n1p3                          partition	9227464		0		-2
/dev/zram0                              partition	3777532		0		100
/dev/zram1                              partition	3777532		0		100
1 Like

You can have more than one. How much ram do you have?

I am not sure if I understand it correctly but there seems to be some differences between the two.
/dev/zram1 will apparently get mounted as a ext2 (by default) device into the file system instead of into RAM. This is from the example.config file:

[zram1]
# This section describes the settings for /dev/zram1.
#
# host-memory-limit is not specifed, so this device will always be created.

# Size the device to a tenth of RAM.
zram-fraction = 0.1

# The file system to put on the device. If not specified, ext2 will be used.
fs-type = ext2

# Where to mount the file system. If a mount point is not specified,
# the device will be initialized, but will not be used for anything.
mount-point = /run/compressed-mount-point

Seemingly you could both define the filesystem type and the mountpoint.

This is the example given at the Github page:

# /etc/systemd/zram-generator.conf
[zram1]
mount-point = /var/tmp

This will set up a /dev/zram1 with ext2 and generate a mount unit for /var/tmp.

With this activated, what do you get if you run:
lsblk -fs
?

I have 8 gigs of ram.

$ lsblk -fs
NAME      FSTYPE FSVER LABEL    UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
zram0                                                                               [SWAP]
zram1                                                                               [SWAP]
nvme0n1p1 vfat   FAT32 NO_LABEL 2218-9BA3                             493,3M     3% /boot/efi
└─nvme0n1                                                                           
nvme0n1p2 ext4   1.0            180cdfdd-3557-4ce8-bfcc-c5abc43b2883  107,9G    47% /
└─nvme0n1                                                                           
nvme0n1p3 swap   1              96ef776b-98cf-42a9-b213-7e7417fae936                [SWAP]
└─nvme0n1                                                                 

You’ve removed the latter part of your file? @pebcak

Yes, I did.

This my lsblk -fs

NAME      FSTYPE FSVER LABEL      UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
zram0                                                                                 [SWAP]
nvme0n1p1 vfat   FAT32            5C1D-26F4                             906.1M    11% /boot
│                                                                                     /efi
└─nvme0n1                                                                             
nvme0n1p2 btrfs        EnOS-gnome 0d19c35e-8b2b-4844-a2e6-359ae17575e1  915.6G     3% /swap
│                                                                                     /home
│                                                                                     /
└─nvme0n1

The second swap device is a file in a btrfs subvolume mounted at /swap.

Maybe @dalto could shed some light on the differences between /dev/zram0 and /dev/zram1.
To my un-initiated eye they look to be implemented differently. You don’t have a mountpoint parameter for zram0 in the config file. So I don’t know if it has any practical implications or not.

I don’t know for sure but I always assumed they were just examples of different ways you can configure zram-generator.

2 Likes

So, would I better remove the zram1 part?

As @dalto mentioned above, they are different configurations of zram-generator. Perhaps it’s neither better nor worse. I guess it’s up to you if you would like to have two zram devices or just one.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.