zram as tmpfs replacement woes
adavidzh opened this issue · comments
Hi there,
I am trying to replace a tmpfs
ramdisk to store temporary (and highly compressible) data and zram-generator
looked like a really neat and organised way to do that.
TL;DR: Alma Linux 9 is installing zram-generator v0.3.2
, things do not work because of a missing dependency on BindsTo=tmp-zramdisk
, and I am wondering if the old version is the problem or a red herring.
Details follow:
I have rolled out
$ cat /etc/systemd/zram-generator.conf
[zram0]
zram-size = 80000 # in MB
mount-point = /tmp/zramdisk # must be created beforehand
fs-type = ext2 # simple, no frills, no CoW, no journaling, etc
options = X-mount.mode=1777
but it fails with
$ sudo systemctl daemon-reload
$ sudo systemctl start systemd-zram-setup@zram0.service
Failed to start systemd-zram-setup@zram0.service: Unit beforehand.mount not found.
I could not find much about this beforehand.mount
and I am not sure what it is supposed to be for.
I do see some unintuitive stuff in the service:
$ sudo systemctl cat systemd-zram-setup@zram0.service
# /usr/lib/systemd/system/systemd-zram-setup@.service
# SPDX-License-Identifier: MIT
# This file is part of the zram-generator project
# https://github.com/systemd/zram-generator
[Unit]
Description=Create swap on /dev/%i
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
After=dev-%i.device
DefaultDependencies=false
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/system-generators/zram-generator --setup-device '%i'
ExecStop=/usr/lib/systemd/system-generators/zram-generator --reset-device '%i'
# /run/systemd/generator/systemd-zram-setup@zram0.service.d/bindsto-mount.conf
# Automatically generated by /usr/lib/systemd/system-generators/zram-generator
[Unit]
BindsTo=tmp-zramdisk # must be created beforehand.mount
I am confused by:
- The mention to
Create swap on
whenmount-point
is provided, that I guess is "just" a template issue. Should there be a second template or a parametric template for whenmount-point
is used? - The whole second
[Unit]
withBindsTo=tmp-zramdisk
that I cannot find in units/systemd-zram-setup@.service.in.
I am running:
$ /usr/lib/systemd/system-generators/zram-generator -V
zram-generator 0.3.2
and I see that there is a v1.1.2
release. The 0.3.2
version comes from
$ dnf info zram-generator
Last metadata expiration check: 2:29:02 ago on Tue 07 Nov 2023 04:24:04 PM CET.
Installed Packages
Name : zram-generator
Version : 0.3.2
Release : 7.el9
Architecture : x86_64
Size : 1.0 M
Source : rust-zram-generator-0.3.2-7.el9.src.rpm
Repository : @System
From repo : appstream
Summary : Systemd unit generator for zram swap devices
URL : https://crates.io/crates/zram-generator
License : MIT
Description : This is a systemd unit generator that enables swap on zram.
: (With zram, there is no physical swap device. Part of the avaialable RAM
: is used to store compressed pages, essentially trading CPU cycles for memory.)
I am running
$ cat /etc/os-release
NAME="AlmaLinux"
VERSION="9.2 (Turquoise Kodkod)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="AlmaLinux 9.2 (Turquoise Kodkod)"
ANSI_COLOR="0;34"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
HOME_URL="https://almalinux.org/"
DOCUMENTATION_URL="https://wiki.almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"
ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
ALMALINUX_MANTISBT_PROJECT_VERSION="9.2"
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
With many difficulties i managed to find that
(a) https://build.almalinux.org/search?rpmName=zram-generator
⎇ c9-beta some tests failed some tests failed all tests failed all tests failed all tests failed
and (b) https://git.almalinux.org/rpms/rust-zram-generator
which has three different branches (two of which seemingly identical but with different SHAs), and none of them have a patch
Given this, it's rather obvious that if you said
mount-point = /tmp/zramdisk # must be created beforehand
and this generated
# /run/systemd/generator/systemd-zram-setup@zram0.service.d/bindsto-mount.conf
# Automatically generated by /usr/lib/systemd/system-generators/zram-generator
[Unit]
BindsTo=tmp-zramdisk # must be created beforehand.mount
then z-g should've escaped the path. Thankfully, I think this is the only place this needs to be done.
Actually, 1.1.2 does escape it, and notes the other errors in your config:
$ ZRAM_GENERATOR_ROOT=$PWD target/release/zram-generator $PWD/dest
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/usr/lib/systemd/zram-generator.conf.d'
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/usr/local/lib/systemd/zram-generator.conf.d'
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/etc/systemd/zram-generator.conf.d'
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/run/systemd/zram-generator.conf.d'
Error: zram0 zram-size
Caused by:
UnparsedTokensRemaining("# in MB")
but removing that, I see
$ ZRAM_GENERATOR_ROOT=$PWD target/release/zram-generator $PWD/dest
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/usr/lib/systemd/zram-generator.conf.d'
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/usr/local/lib/systemd/zram-generator.conf.d'
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/etc/systemd/zram-generator.conf.d'
Scanning directory '/home/nabijaczleweli/code/systemd-zram-generator/run/systemd/zram-generator.conf.d'
Creating unit file tmp-zramdisk\x20\x23\x20must\x20be\x20created\x20beforehand.mount (/dev/zram0 with 80000MB)
$ find dest/
dest/
dest/systemd-zram-setup@zram0.service.d
dest/systemd-zram-setup@zram0.service.d/bindings.conf
dest/local-fs.target.wants
dest/local-fs.target.wants/tmp-zramdisk\x20\x23\x20must\x20be\x20created\x20beforehand.mount
dest/tmp-zramdisk\x20\x23\x20must\x20be\x20created\x20beforehand.mount
$ find dest/ -type f -exec head -n99 {} +
==> dest/systemd-zram-setup@zram0.service.d/bindings.conf <==
# Automatically generated by /mnt/filling/store/nabijaczleweli/Rust-target/release/zram-generator
[Unit]
BindsTo=tmp-zramdisk\x20\x23\x20must\x20be\x20created\x20beforehand.mount
==> dest/tmp-zramdisk\x20\x23\x20must\x20be\x20created\x20beforehand.mount <==
# Automatically generated by /mnt/filling/store/nabijaczleweli/Rust-target/release/zram-generator
[Unit]
Description=Compressed Storage on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
Requires=systemd-zram-setup@zram0.service
After=systemd-zram-setup@zram0.service
[Mount]
What=/dev/zram0
Where=/tmp/zramdisk # must be created beforehand
Options=X-mount.mode=1777
so this is already fixed in 2f2d5fb, and is thus a duplicate of #101.
Thanks for the low latency!
I moved all the comments and the problem is gone:
$ cat /etc/systemd/zram-generator.conf
[zram0]
zram-size = 80000
# in MB
mount-point = /tmp/zramdisk
# automatically created
fs-type = ext2
# simple, no frills, no CoW, no journaling, etc
options= X-mount.mode=1777
$ sudo systemctl daemon-reload
$ sudo systemctl start systemd-zram-setup@zram0.service
$ sudo systemctl cat systemd-zram-setup@zram0.service
# /usr/lib/systemd/system/systemd-zram-setup@.service
# SPDX-License-Identifier: MIT
# This file is part of the zram-generator project
# https://github.com/systemd/zram-generator
[Unit]
Description=Create swap on /dev/%i
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
After=dev-%i.device
DefaultDependencies=false
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/system-generators/zram-generator --setup-device '%i'
ExecStop=/usr/lib/systemd/system-generators/zram-generator --reset-device '%i'
# /run/systemd/generator/systemd-zram-setup@zram0.service.d/bindsto-mount.conf
# Automatically generated by /usr/lib/systemd/system-generators/zram-generator
[Unit]
BindsTo=tmp-zramdisk.mount
$ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle 4G 1.3M 25.7K 132K 32 /tmp/zramdisk
I somehow thought that inline comments were purged.
Now I have to figure out why DISKSIZE
is 4G
regardless of what I put in zram-size
...
Now I have to figure out why
DISKSIZE
is4G
regardless of what I put inzram-size
...
It's the old version using old options. 😅
All good!
All is almost good.
Since 0.3.2
does not support options=
the mount is only writable by root
, an annoyance.
I have opened a request for bumping the version of zram-generator
in AlmaLinux 9. Let's see how that goes.
Thanks again for the quick turnaround.
I see that zram-generator
rpm hasn't been updated beyond v0.3.2 on EL9.
Not sure why, but there might be an upstream issue that was never resolved.
Not sure what the issue is.