From ed0a29c88dfe32f3121474ce5cad7df02e28c2cc Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 26 Feb 2021 13:06:18 +0100 Subject: [PATCH 1/2] nixos/test/ksm: add simple test --- nixos/tests/all-tests.nix | 1 + nixos/tests/ksm.nix | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 nixos/tests/ksm.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index bf094dbe984..625eb54403d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -195,6 +195,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..8feccbe6df5 --- /dev/null +++ b/nixos/tests/ksm.nix @@ -0,0 +1,22 @@ +import ./make-test-python.nix ({ pkgs, ...} : + +{ + name = "ksm"; + meta = with pkgs.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 $( Date: Fri, 26 Feb 2021 21:37:33 +0100 Subject: [PATCH 2/2] nixos/ksm: remove udev-settle dependency The sysfs file /sys/kernel/mm/ksm/run seems to be available as soon as the kernel has started, so no point in waiting for udev to "settle". If for some reason it doesn't, we let the unit fail explicitly. --- nixos/modules/hardware/ksm.nix | 12 ++++++------ nixos/tests/ksm.nix | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) 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/ksm.nix b/nixos/tests/ksm.nix index 8feccbe6df5..8f84b32020a 100644 --- a/nixos/tests/ksm.nix +++ b/nixos/tests/ksm.nix @@ -1,8 +1,8 @@ -import ./make-test-python.nix ({ pkgs, ...} : +import ./make-test-python.nix ({ lib, ...} : { name = "ksm"; - meta = with pkgs.lib.maintainers; { + meta = with lib.maintainers; { maintainers = [ rnhmjoj ]; };