diff --git a/flake.nix b/flake.nix index c061667..9c502f9 100644 --- a/flake.nix +++ b/flake.nix @@ -309,6 +309,7 @@ bluemap = ./modules/bluemap.nix; drumknotty = ./modules/drumknotty; gickup = ./modules/gickup; + hugepages = ./modules/hugepages.nix; matrix-ooye = ./modules/matrix-ooye.nix; python-http-handlers = ./modules/python-http-handlers.nix; robots-txt = ./modules/robots-txt.nix; diff --git a/modules/hugepages.nix b/modules/hugepages.nix new file mode 100644 index 0000000..5b64318 --- /dev/null +++ b/modules/hugepages.nix @@ -0,0 +1,38 @@ +{ config, lib, ... }: +let + cfg = config.boot.kernel.hugepages; +in +{ + options.boot.kernel.hugepages = { + size = lib.mkOption { + type = lib.types.enum [ 2 1024 ]; + default = 2; + description = '' + Hugepage size in MB. + + You can use this value to calculate the amount of memory you will have available as hugepages. + ''; + }; + + reservations = lib.mkOption { + type = lib.types.attrsOf lib.types.ints.unsigned; + default = { }; + description = '' + Number of hugepages each service wants reserved in vm.nr_hugepages, + keyed by service name. + ''; + }; + }; + + config = { + boot.kernelParams = let + num = { + "2" = "2M"; + "1024" = "1G"; + }.${toString cfg.size}; + in [ "hugepagesz=${num}" ]; + + boot.kernel.sysctl."vm.nr_hugepages" = + lib.foldl' (a: b: a + b) 0 (lib.attrValues cfg.reservations); + }; +}