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…?
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?
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.
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!
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.
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.
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.