2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hardware.ksm;
|
|
|
|
|
|
|
|
in {
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ])
|
|
|
|
];
|
|
|
|
|
|
|
|
options.hardware.ksm = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "Linux kernel Same-Page Merging";
|
2020-04-24 23:36:52 +00:00
|
|
|
sleep = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
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
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
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
|
2021-03-09 03:18:52 +00:00
|
|
|
'' + optionalString (cfg.sleep != null)
|
|
|
|
''
|
|
|
|
echo ${toString cfg.sleep} > /sys/kernel/mm/ksm/sleep_millisecs
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|