is a change to
automatically create a zram device on memory-constrained systems. It is
implemented using 'zram' package, which uses a service unit and two
bash scripts to implement the starting and stopping of the zram device.
I wanted to explore an alternative approach, using a systemd generator ,
to create (or not) the unit to create the zram device. The advantages are:
- lower footprint (a custom binary instead of a shell script using
grep, awk, and whatnot)
- completely invisible if the memory limits are not met, no "skipped" units
- minimalistic: the unit just creates the device, but tells
systemd-modules-load.service to actually load the module,
and creates a .swap unit for the device, so it will be managed by systemd
in the usual fashion.
Systemd generators are often written in C, to keep them mean and lean, but
C is not an attractive option for many people. We have wanted to explore
the approach of writing generators in Rust. zram-generator doubles as a
proof-of-concept and example of a simple-yet-not-trivial systemd generator
Without further ado: upstream project , fedora package review .
Many thanks to Igor Gnatenko and Martin Sehnoutka for reviews of the code.
It works like this:
1. /usr/lib/systemd/zram-generator runs, checks if we have less memory than the limit
2. /run/modules-load.d/zram.conf is created to have "zram" module loaded
3. /run/systemd/generator/swap-create(a)zram0.service is created, it'll
4. /run/systemd/generator/dev-zram0.swap is created, and added to swap.target
5. swap.target is pulled in by systemd, the config from items 2, 3, 4 is
Comments, ideas, reviews of the package, etc, are very much welcome.
I think this might be used to replace the 'zram' package, but it's too early