diff options
author | Janne Heß <janne@hess.ooo> | 2022-04-21 19:54:50 +0200 |
---|---|---|
committer | Janne Heß <janne@hess.ooo> | 2022-08-31 13:24:32 +0200 |
commit | 3284f4fa19597828c778b1cc0b79cc1f6d06fef9 (patch) | |
tree | e09998c5da06f3586394444a28e4ca5723ff14ce /nixos/tests/systemd-oomd.nix | |
parent | bacac7cf54bdfdb41091a506dd1b158da08a2d78 (diff) |
nixos/systemd-oomd: Add a new module + test
Diffstat (limited to 'nixos/tests/systemd-oomd.nix')
-rw-r--r-- | nixos/tests/systemd-oomd.nix | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nixos/tests/systemd-oomd.nix b/nixos/tests/systemd-oomd.nix new file mode 100644 index 0000000000000..f0b5a5f8e01ab --- /dev/null +++ b/nixos/tests/systemd-oomd.nix @@ -0,0 +1,37 @@ +import ./make-test-python.nix ({ pkgs, ... }: + +{ + name = "systemd-oomd"; + + nodes.machine = { pkgs, ... }: { + systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = "1s"; # makes the test faster + # Kill cgroups when more than 1% pressure is encountered + systemd.slices."-".sliceConfig = { + ManagedOOMMemoryPressure = "kill"; + ManagedOOMMemoryPressureLimit = "1%"; + }; + # A service to bring the system under memory pressure + systemd.services.testservice = { + serviceConfig.ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero"; + }; + # Do not kill the backdoor + systemd.services.backdoor.serviceConfig.ManagedOOMMemoryPressure = "auto"; + + virtualisation.memorySize = 1024; + }; + + testScript = '' + # Start the system + machine.wait_for_unit("multi-user.target") + machine.succeed("oomctl") + + # Bring the system into memory pressure + machine.succeed("echo 0 > /proc/sys/vm/panic_on_oom") # NixOS tests kill the VM when the OOM killer is invoked - override this + machine.succeed("systemctl start testservice") + + # Wait for oomd to kill something + # Matches these lines: + # systemd-oomd[508]: Killed /system.slice/systemd-udevd.service due to memory pressure for / being 3.26% > 1.00% for > 1s with reclaim activity + machine.wait_until_succeeds("journalctl -b | grep -q 'due to memory pressure for'") + ''; +}) |