summary refs log tree commit diff
path: root/nixos/modules/hardware/ksm.nix
blob: ba7a1c12169f2de8a3c4ca64170e3e6a2face100 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{ config, lib, ... }:

with lib;

let
  cfg = config.hardware.ksm;

in {
  imports = [
    (mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ])
  ];

  options.hardware.ksm = {
    enable = mkEnableOption "Kernel Same-Page Merging";
    sleep = mkOption {
      type = types.nullOr types.int;
      default = null;
      description = lib.mdDoc ''
        How many milliseconds ksmd should sleep between scans.
        Setting it to `null` uses the kernel's default time.
      '';
    };
  };

  config = mkIf cfg.enable {
    systemd.services.enable-ksm = {
      description = "Enable Kernel Same-Page Merging";
      wantedBy = [ "multi-user.target" ];
      script =
        ''
          echo 1 > /sys/kernel/mm/ksm/run
        '' + optionalString (cfg.sleep != null)
        ''
          echo ${toString cfg.sleep} > /sys/kernel/mm/ksm/sleep_millisecs
        '';
    };
  };
}