2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.hardware.ksm;
|
|
|
|
|
|
|
|
in {
|
|
|
|
imports = [
|
2024-09-19 14:19:46 +00:00
|
|
|
(lib.mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ])
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
options.hardware.ksm = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "Linux kernel Same-Page Merging";
|
|
|
|
sleep = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
How many milliseconds ksmd should sleep between scans.
|
2022-08-12 12:06:08 +00:00
|
|
|
Setting it to `null` uses the kernel's default time.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.enable-ksm = {
|
|
|
|
description = "Enable Kernel Same-Page Merging";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-03-09 03:18:52 +00:00
|
|
|
script =
|
|
|
|
''
|
2020-04-24 23:36:52 +00:00
|
|
|
echo 1 > /sys/kernel/mm/ksm/run
|
2024-09-19 14:19:46 +00:00
|
|
|
'' + lib.optionalString (cfg.sleep != null)
|
2021-03-09 03:18:52 +00:00
|
|
|
''
|
|
|
|
echo ${toString cfg.sleep} > /sys/kernel/mm/ksm/sleep_millisecs
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|