From 64c17862866c75117159a8c360f09db851104350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 28 Mar 2026 08:08:17 +0100 Subject: [PATCH] nixos/zram-generator: do not restart on switch Restarting systemd-zram-setup@ does swapoff -> reset -> reconfigure -> swapon. This is undesirable: - swapoff can push a loaded system into OOM. - The reset races with udev still holding /dev/zramN open after swapoff; the kernel rejects it with EBUSY (disk_openers > 0), leaving the device initialized so ExecStart then fails to write comp_algorithm/disksize (systemd/zram-generator#226). The unit only "changes" because store paths in the drop-in churn, so just keep the device across switches. Actual config changes can be applied with a reboot or manual restart. --- nixos/modules/services/system/zram-generator.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/system/zram-generator.nix b/nixos/modules/services/system/zram-generator.nix index 7eb3fdda46d3..afdb8d86e831 100644 --- a/nixos/modules/services/system/zram-generator.nix +++ b/nixos/modules/services/system/zram-generator.nix @@ -36,7 +36,18 @@ in ]; systemd.packages = [ cfg.package ]; - systemd.services."systemd-zram-setup@".path = [ pkgs.util-linux ]; # for mkswap + systemd.services."systemd-zram-setup@" = { + path = [ pkgs.util-linux ]; # for mkswap + # Restart on switch does swapoff -> reset -> reconfigure -> swapon. + # Besides risking OOM when swap is in use, the reset races with udev + # still holding /dev/zramN open after swapoff: the kernel rejects the + # reset with EBUSY (disk_openers > 0), the device stays initialized, + # and the following ExecStart fails to write comp_algorithm/disksize + # (systemd/zram-generator#226). The unit only "changes" due to store + # path churn, so keep the device across switches; real config changes + # need a reboot or manual restart. + restartIfChanged = false; + }; environment.etc."systemd/zram-generator.conf".source = settingsFormat.generate "zram-generator.conf" cfg.settings;