modules/hugepages: init

This commit is contained in:
h7x4
2026-07-21 17:40:29 +09:00
parent 9a837d210d
commit 8bb86ef634
2 changed files with 39 additions and 0 deletions
+1
View File
@@ -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;
+38
View File
@@ -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);
};
}