ZRAM-GENERATOR(8)

πŸ’œ ZRAM-GENERATOR(8) β€” like, the system manager's manual bestie πŸ’œ

okay so this is the page for zram-generator, from the System Manager's Manual (section 8, iykyk) β€” strap in πŸŽ€


✨ NAME ✨

zram-generator β€” a systemd unit generator for zram swap devices 🌸


✨ SYNOPSIS ✨

/usr/lib/systemd/system-generators/zram-generator TARGET_DIR [2RGET_DIR 3RGET_DIR]
/usr/lib/systemd/system-generators/zram-generator --setup-device DEVICE
/usr/lib/systemd/system-generators/zram-generator --reset-device DEVICE

(and yes, 2RGET_DIR and 3RGET_DIR are literally written like that in the original, no cap β€” not a typo we invented, we're just passing it along fr fr 😭)


✨ DESCRIPTION ✨

so zram-generator is a generator that creates systemd units to format and use compressed RAM devices β€” either as swap or as a file system. that's the whole vibe πŸ’…

the generator gets invoked by systemd all early at boot, and then it does this:

  1. reads configuration files from {/etc,/lib}/systemd/zram-generator.conf[.d] β€” see zram-generator.conf(5) for the deets;
  2. generates systemd.swap(5) and/or systemd.mount(5) units into TARGET_DIR and connects them to swap.target or local-fs.target as appropriate;
  3. makes sure the zram module is loaded and creates the requested devices.

the generator does absolutely nothing if it's run inside a container (as determined by systemd-detect-virt(8) --container). like, it just clocks out πŸ«₯

the generator also understands the kernel command-line option systemd.zram. see zram-generator.conf(5) for details.

setting the ZRAM_GENERATOR_ROOT environment variable makes the generator run in test mode, in which case containerisation is ignored and step 3 is skipped. for the ramifications of ZRAM_GENERATOR_ROOT on config handling, see zram-generator.conf(5).


generated dev-zramN.swap units depend on systemd-zram-setup@zramN.service, which will:

  1. read configuration files from {/etc,/lib}/systemd/zram-generator.conf[.d] (see zram-generator.conf(5) for details);
  2. set the desired compression algorithm, if any β€” and if the current kernel doesn't understand the specified algorithm, a warning is issued, but execution continues (resilient queen πŸ‘‘);
  3. set the desired blockdev size and format it as swap with systemd-makefs(8).

generated path-to-mount-point.mount units depend on systemd-zram-setup@zramN.service. the effect is similar to what happens for swap units, but of course they're formatted with a file system πŸ’–

when the unit is stopped, the zram device is reset β€” freeing memory and allowing the device to be reused. recycling icon ✨

zram-generator implements systemd.generator(7).


πŸ¦‹ Applying config changes πŸ¦‹

this generator is invoked in early boot, and the devices it configures get created very early too, so the easiest way to apply config changes is to... simply reboot the machine πŸ™ˆ iconic, low-effort, works.

nevertheless, sometimes it may be useful to add new devices or apply config changes at runtime. applying new configuration means restarting the units, and that in turn means recreating the zram devices. which means:

file systems are temporarily unmounted and their contents lost, and pages are moved out of the compressed swap device into other memory. πŸ’€ like, be so serious before you do this.

if that's acceptable, systemctl restart systemd-zram-setup@zramN or systemctl restart systemd-zram-setup@* may be used to recreate a specific device or all configured devices. (if the device didn't exist, restart will create it β€” surprise, it's a feature πŸŽ€)

if the way the device is used (e.g. the mount point or file system type) is changed, systemctl daemon-reload needs to be called first to recreate systemd units. and if a device or mount point is removed from configuration, the unit should be stopped before calling daemon-reload. otherwise, systemd will not know how to stop the unit properly. no cap, order matters here fr fr 🌈


✨ REPORTING BUGS ✨

found a bug? tell on it here: https://github.com/systemd/zram-generator/issues πŸ›πŸ’…


✨ SEE ALSO ✨

also:


okay that's the whole page bestie, go configure some compressed RAM, you're gonna slay πŸ’–βœ¨πŸŒΈ

November 2024 β€” mwah, that's the date and this page is ZRAM-GENERATOR(8), signing off πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from