From e32f2cda301289b92c4fe3f25a8b38267f03d4ff Mon Sep 17 00:00:00 2001 From: Default email Date: Tue, 24 Nov 2020 21:58:05 +0100 Subject: [PATCH] Project import generated by Copybara. GitOrigin-RevId: 6f0c00907bbd81b47052eef59f7b284926a77289 --- .../nixpkgs/nixos/modules/config/zram.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/third_party/nixpkgs/nixos/modules/config/zram.nix b/third_party/nixpkgs/nixos/modules/config/zram.nix index 341101bc18..1f513b7e4d 100644 --- a/third_party/nixpkgs/nixos/modules/config/zram.nix +++ b/third_party/nixpkgs/nixos/modules/config/zram.nix @@ -80,6 +80,15 @@ in ''; }; + memoryMax = mkOption { + default = null; + type = with types; nullOr int; + description = '' + Maximum total amount of memory (in bytes) that can be used by the zram + swap devices. + ''; + }; + priority = mkOption { default = 5; type = types.int; @@ -146,7 +155,12 @@ in # Calculate memory to use for zram mem=$(${pkgs.gawk}/bin/awk '/MemTotal: / { - print int($2*${toString cfg.memoryPercent}/100.0/${toString devicesCount}*1024) + value=int($2*${toString cfg.memoryPercent}/100.0/${toString devicesCount}*1024); + ${lib.optionalString (cfg.memoryMax != null) '' + memory_max=int(${toString cfg.memoryMax}/${toString devicesCount}); + if (value > memory_max) { value = memory_max } + ''} + print value }' /proc/meminfo) ${pkgs.util-linux}/sbin/zramctl --size $mem --algorithm ${cfg.algorithm} /dev/${dev}