48052ca0dd
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.
39 lines
919 B
Nix
39 lines
919 B
Nix
{ 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 = ''
|
|
How many milliseconds ksmd should sleep between scans.
|
|
Setting it to <literal>null</literal> 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
|
|
'';
|
|
};
|
|
};
|
|
}
|