{ pkgs, lib, config, ... }: with lib; let cfg = config.fudo.system; in { options.fudo.system = { disableTransparentHugePages = mkOption { type = types.bool; description = '' Disable transparent huge pages (recommended for database loads, in particular for Redis. ''; default = false; }; postHugePageServices = mkOption { type = with types; listOf str; description = "List of systemd services that should wait until after THP are disabled."; default = []; example = ["redis.service"]; }; tmpOnTmpfs = mkOption { type = types.bool; description = "Put tmp filesystem on tmpfs (needs enough RAM)."; default = true; }; }; config = mkIf cfg.disableTransparentHugePages { systemd.services.disableHugePages = { description = "Turn off Transparent Huge Pages (https://www.kernel.org/doc/Documentation/vm/transhuge.txt)"; after = [ "sysinit.target" "localfs-target" ]; before = cfg.postHugePageServices; enable = true; serviceConfig = { ExecStart = "/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/enabled > /dev/null"; Type = "oneshot"; }; }; }; }