2015-04-01 19:55:49 +02:00
|
|
|
{ config, lib, ... }:
|
2019-07-05 23:39:58 +03:00
|
|
|
let
|
|
|
|
cfg = config.hardware.ksm;
|
|
|
|
|
2024-12-10 20:26:33 +01:00
|
|
|
in
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
2024-08-24 22:05:27 +02:00
|
|
|
(lib.mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ])
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
|
|
|
|
2019-07-05 23:39:58 +03:00
|
|
|
options.hardware.ksm = {
|
2024-08-24 22:05:27 +02:00
|
|
|
enable = lib.mkEnableOption "Linux kernel Same-Page Merging";
|
|
|
|
sleep = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.int;
|
2019-07-05 23:39:58 +03:00
|
|
|
default = null;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-07-05 23:39:58 +03:00
|
|
|
How many milliseconds ksmd should sleep between scans.
|
2022-07-19 15:05:45 +02:00
|
|
|
Setting it to `null` uses the kernel's default time.
|
2019-07-05 23:39:58 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:27 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2015-04-01 19:55:49 +02:00
|
|
|
systemd.services.enable-ksm = {
|
|
|
|
description = "Enable Kernel Same-Page Merging";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-02-26 21:37:33 +01:00
|
|
|
script =
|
|
|
|
''
|
2015-04-01 19:55:49 +02:00
|
|
|
echo 1 > /sys/kernel/mm/ksm/run
|
2021-02-26 21:37:33 +01:00
|
|
|
''
|
2024-12-10 20:26:33 +01:00
|
|
|
+ lib.optionalString (cfg.sleep != null) ''
|
2021-02-26 21:37:33 +01:00
|
|
|
echo ${toString cfg.sleep} > /sys/kernel/mm/ksm/sleep_millisecs
|
|
|
|
'';
|
2015-04-01 19:55:49 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|