Error enabling ZRAM

Hello Everyone.

I am trying to enable ZRAM on my device by referring to the methods as described by @flyingcakes here :

The issue is that while loading the zram. error is displayed of timed out.

Also, the config file is now changed a bit as well.

I followed the following steps :

Install zram-generator
sudo pacman -S zram-generator


Find example config file
find / -name "zram-generator.conf.example"



Copy example config
sudo cp /usr/share/doc/zram-generator/zram-generator.conf.example /etc/systemd/zram-generator.conf


Edit the config using nano
sudo nano /etc/systemd/zram-generator.conf


Create new device units
systemctl daemon-reload


Enable zram as swap
systemctl start /dev/zram0

Also, here is the config file :

http://0x0.st/oS8i.conf

Also,

deweshk@HomeDesktop:~
➤ sudo systemctl status /dev/zram0 
[sudo] password for deweshk: 
â—Ź dev-zram0.device - /dev/zram0
    Follows: unit currently follows state of sys-devices-virtual-block-zram0.device
     Loaded: loaded
     Active: active (plugged) since Thu 2022-06-23 11:55:44 IST; 25min ago
      Until: Thu 2022-06-23 11:55:44 IST; 25min ago
     Device: /sys/devices/virtual/block/zram0

Jun 23 11:55:44 HomeDesktop systemd[1]: Found device /dev/zram0.

deweshk@HomeDesktop:~

➤ zramctl
NAME       ALGORITHM DISKSIZE  DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram1 lzo-rle     271.9M  132K    2K   68K       4 /run/compressed-mount-point

But, on HTOP, the changes are not visible.

What should be the steps that I should follow ?

1 Like

His method worked for me a few weeks back.

You can also refer the arch wiki article on this.

On Arch Wiki there is written about enabling ZRAM temporarily on device with 32 Gb or higher, but my device is 1/10th of it.

image

Seemingly, there are some new options in the config file. Like this one:

# Write incompressible pages to this device,
# as there's no gain from keeping them in RAM
writeback-device = /dev/zvol/tarta-zoot/swap-writeback

which errored out on me. Not having time at the moment to dig into it, I commented out that option and Zram started working as expected.

1 Like

Read this:
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. The following resources provide information on how to use it:

zram-generator(8)
zram-generator.conf(5)

“The generator will be invoked by systemd early at boot”, so usage is as simple as creating the appropriate configuration file(s) and rebooting. A sample configuration is provided in /usr/share/doc/zram-generator/zram-generator.conf.example. You can also check the swap status of your configured /dev/zramN devices by checking the unit status of the systemd-zram-setup@zramN.service instance(s).

1 Like

While rebooting, the process got stuck for 80-90 seconds, and yielded the timed out message.

As you can see, ZRAM is enabled according the aforementioned output, but it is not visible. I had also rebooted the device twice.

sudo swapon -s

?

Nothing.

deweshk@HomeDesktop:~
➤ sudo swapon -s
[sudo] password for deweshk: 
deweshk@HomeDesktop:~

Then something is not quite right. You should be seeing something like:

Filename				Type		Size		Used		Priority
/dev/zram0                             partition	4194300		0		100

in the output.

This is my conf if it can help
# 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 size of the zram device, as a function of MemTotal, both in MB.
# For example, if the machine has 1 GiB, and zram-size=ram/4,
# then the zram device will have 256 MiB.
# Fractions in the range 0.1–0.5 are recommended.
#
# The default is "min(ram / 2, 4096)".
zram-size = min(ram / 10, 2048)

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

# By default, file systems and swap areas are trimmed on-the-go
# by setting "discard".
# Setting this to the empty string clears the option.
options =

# Write incompressible pages to this device,
# as there's no gain from keeping them in RAM
#writeback-device = /dev/zvol/tarta-zoot/swap-writeback

# The following options are deprecated, and override zram-size.
# These values would be equivalent to the zram-size setting above.
#zram-fraction = 0.10
#max-zram-size = 2048


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

# Size the device to a tenth of RAM.
#zram-size = ram / 10

# 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

It is almost same with exception of the fraction, which is z/7 on mine.

For testing sake, comment out the following line:

writeback-device = /dev/zvol/tarta-zoot/swap-writeback

:arrow_down:

# writeback-device = /dev/zvol/tarta-zoot/swap-writeback

and reboot.

1 Like
deweshk@HomeDesktop:~
➤ writeback-device = /dev/zvol/tarta-zoot/swap-writeback
fish: Unknown command: writeback-device
deweshk@HomeDesktop:~

You need to comment out that line in zram-generator.conf and then reboot.

Yes, it worked out, Thank you very much for help.

And, on other side, why did this issue caused ?

1 Like

I am not really sure.
I haven’t just had time to investigate it yet.
When setting up zram, I saw there was an error regarding that writeback device saying it was not found. So I just un-commented that and zram started working.

1 Like

Wow, thank you for sharing your insights regarding the issue. This will also help me in figuring out the troubles.

Also, would journalctl had showed cause ?

1 Like

I guess so.

Since zram didn’t get enabled when trying to setting it up, I checked:

systemctl --failed

and it revealed the error.

2 Likes

It means that I am able to learn few things, gradually. Thank you very much.

2 Likes

We are all on some place or other on a learning curve.
I found this forum a great place for learning things and hopefully get the chance to passing it on to others.

Also, the odd thing regarding this writeback device is that that there is no reference to it in

man zram-generator.conf

Nor what I could see on the project’s Github page.

Mine got installed on this system:

[2022-06-10T11:54:59+0200] [ALPM] installed zram-generator (1.1.2-1)

Previously, I hadn’t seen that option in the conf file.

Edit:

Looks like it was introduced in:

# Write incompressible pages to this device,
# as there's no gain from keeping them in RAM
writeback-device = /dev/zvol/tarta-zoot/swap-writeback

Not sure then if what is specified is the default why then it will error?
At any rate I don’t know then if it is on the users to modify it or not and how.
Maybe, later on, I make a post and ask the forum. Or perhaps someone who knows looking into this thread might be able to shed some light on this.

Edit:

Pebcak, as my username suggests, I missed this:

 writeback-device=

           Write incompressible pages, for which no gain was achieved, to the specified device under memory pressure. This corresponds to the /sys/block/zramX/backing_dev parameter.

           Takes a path to a block device, like /dev/disk/by-partuuid/2d54ffa0-01 or /dev/zvol/tarta-zoot/swap-writeback.

           If unset, none is used, and incompressible pages are kept in RAM.

in man zram-generator.conf :eyeglasses: :eyes:

2 Likes