diff options
author | Leon Isenberg <ljli@users.noreply.github.com> | 2017-03-24 23:16:16 +0100 |
---|---|---|
committer | Leon Isenberg <ljli@users.noreply.github.com> | 2017-03-24 23:16:16 +0100 |
commit | db30cff50008546ca00a46f0e6171bbc186cb3c2 (patch) | |
tree | 2bc2c85076a41546009d5f340849acf0539e544f /nixos/modules | |
parent | 82adcd6cfb1c779b86c26e326a33728b316fa9c6 (diff) | |
download | nixlib-db30cff50008546ca00a46f0e6171bbc186cb3c2.tar nixlib-db30cff50008546ca00a46f0e6171bbc186cb3c2.tar.gz nixlib-db30cff50008546ca00a46f0e6171bbc186cb3c2.tar.bz2 nixlib-db30cff50008546ca00a46f0e6171bbc186cb3c2.tar.lz nixlib-db30cff50008546ca00a46f0e6171bbc186cb3c2.tar.xz nixlib-db30cff50008546ca00a46f0e6171bbc186cb3c2.tar.zst nixlib-db30cff50008546ca00a46f0e6171bbc186cb3c2.zip |
earlyoom service: init
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/system/earlyoom.nix | 96 |
2 files changed, 97 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 610c2a2b758a..a55c2c4565e2 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -528,6 +528,7 @@ ./services/system/cgmanager.nix ./services/system/cloud-init.nix ./services/system/dbus.nix + ./services/system/earlyoom.nix ./services/system/kerberos.nix ./services/system/nscd.nix ./services/system/uptimed.nix diff --git a/nixos/modules/services/system/earlyoom.nix b/nixos/modules/services/system/earlyoom.nix new file mode 100644 index 000000000000..daa46838bfa8 --- /dev/null +++ b/nixos/modules/services/system/earlyoom.nix @@ -0,0 +1,96 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + ecfg = config.services.earlyoom; +in +{ + options = { + services.earlyoom = { + + enable = mkOption { + type = types.bool; + default = false; + description = '' + Enable early out of memory killing. + ''; + }; + + freeMemThreshold = mkOption { + type = types.int; + default = 10; + description = '' + Minimum of availabe memory (in percent). + If the free memory falls below this threshold and the analog is true for + <option>services.earlyoom.freeSwapThreshold</option> + the killing begins. + ''; + }; + + freeSwapThreshold = mkOption { + type = types.int; + default = 10; + description = '' + Minimum of availabe swap space (in percent). + If the available swap space falls below this threshold and the analog + is true for <option>services.earlyoom.freeMemThreshold</option> + the killing begins. + ''; + }; + + useKernelOOMKiller= mkOption { + type = types.bool; + default = false; + description = '' + Use kernel OOM killer instead of own user-space implementation. + ''; + }; + + ignoreOOMScoreAdjust = mkOption { + type = types.bool; + default = false; + description = '' + Ignore oom_score_adjust values of processes. + User-space implementation only. + ''; + }; + + enableDebugInfo = mkOption { + type = types.bool; + default = false; + description = '' + Enable debugging messages. + ''; + }; + }; + }; + + config = mkIf ecfg.enable { + assertions = [ + { assertion = ecfg.freeMemThreshold > 0 && ecfg.freeMemThreshold <= 100; + message = "Needs to be a positive percentage"; } + { assertion = ecfg.freeSwapThreshold > 0 && ecfg.freeSwapThreshold <= 100; + message = "Needs to be a positive percentage"; } + { assertion = !ecfg.useKernelOOMKiller || !ecfg.ignoreOOMScoreAdjust; + message = "Both options in conjunction do not make sense"; } + ]; + + systemd.services.earlyoom = { + description = "Early OOM Daemon for Linux"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + StandardOutput = "null"; + StandardError = "syslog"; + ExecStart = '' + ${pkgs.earlyoom}/bin/earlyoom \ + -m ${toString ecfg.freeMemThreshold} \ + -s ${toString ecfg.freeSwapThreshold} \ + ${optionalString ecfg.useKernelOOMKiller "-k"} \ + ${optionalString ecfg.ignoreOOMScoreAdjust "-i"} \ + ${optionalString ecfg.enableDebugInfo "-d"} + ''; + }; + }; + }; +} |