nixos/ksm: add option sleep

This commit is contained in:
Izorkin 2019-07-05 23:39:58 +03:00
parent df738814d1
commit 8364ade833
2 changed files with 22 additions and 3 deletions

View file

@ -1,9 +1,24 @@
{ config, lib, ... }:
{
options.hardware.enableKSM = lib.mkEnableOption "Kernel Same-Page Merging";
with lib;
config = lib.mkIf config.hardware.enableKSM {
let
cfg = config.hardware.ksm;
in {
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" ];
@ -11,6 +26,7 @@
script = ''
if [ -e /sys/kernel/mm/ksm ]; then
echo 1 > /sys/kernel/mm/ksm/run
${optionalString (cfg.sleep != null) ''echo ${toString cfg.sleep} > /sys/kernel/mm/ksm/sleep_millisecs''}
fi
'';
};

View file

@ -241,6 +241,9 @@ with lib;
# binfmt
(mkRenamedOptionModule [ "boot" "binfmtMiscRegistrations" ] [ "boot" "binfmt" "registrations" ])
# KSM
(mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ])
] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter"
"jsonExporter" "minioExporter" "nginxExporter" "nodeExporter"
"snmpExporter" "unifiExporter" "varnishExporter" ]