diff --git a/nixos/modules/hardware/ksm.nix b/nixos/modules/hardware/ksm.nix index 0938dbdc110..829c3532c45 100644 --- a/nixos/modules/hardware/ksm.nix +++ b/nixos/modules/hardware/ksm.nix @@ -26,13 +26,13 @@ in { systemd.services.enable-ksm = { description = "Enable Kernel Same-Page Merging"; wantedBy = [ "multi-user.target" ]; - after = [ "systemd-udev-settle.service" ]; - script = '' - if [ -e /sys/kernel/mm/ksm ]; then + script = + '' echo 1 > /sys/kernel/mm/ksm/run - ${optionalString (cfg.sleep != null) ''echo ${toString cfg.sleep} > /sys/kernel/mm/ksm/sleep_millisecs''} - fi - ''; + '' + optionalString (cfg.sleep != null) + '' + echo ${toString cfg.sleep} > /sys/kernel/mm/ksm/sleep_millisecs + ''; }; }; } diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 02723f88c31..70405ab3e74 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -196,6 +196,7 @@ in keymap = handleTest ./keymap.nix {}; knot = handleTest ./knot.nix {}; krb5 = discoverTests (import ./krb5 {}); + ksm = handleTest ./ksm.nix {}; kubernetes.dns = handleTestOn ["x86_64-linux"] ./kubernetes/dns.nix {}; # kubernetes.e2e should eventually replace kubernetes.rbac when it works #kubernetes.e2e = handleTestOn ["x86_64-linux"] ./kubernetes/e2e.nix {}; diff --git a/nixos/tests/ksm.nix b/nixos/tests/ksm.nix new file mode 100644 index 00000000000..8f84b32020a --- /dev/null +++ b/nixos/tests/ksm.nix @@ -0,0 +1,22 @@ +import ./make-test-python.nix ({ lib, ...} : + +{ + name = "ksm"; + meta = with lib.maintainers; { + maintainers = [ rnhmjoj ]; + }; + + machine = { ... }: { + imports = [ ../modules/profiles/minimal.nix ]; + + hardware.ksm.enable = true; + hardware.ksm.sleep = 300; + }; + + testScript = + '' + machine.start() + machine.wait_until_succeeds("test $(