3p/nixpkgs: fix PR102855

This commit is contained in:
Luke Granger-Brown 2020-11-29 02:18:52 +00:00
parent e32f2cda30
commit 925895f869
2 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,57 @@
From 961b7c7a6d47b224b2c3fea44ed18b722611d7ab Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Thu, 5 Nov 2020 02:29:46 +0000
Subject: [PATCH] nixos/zram: add zramSwap.memoryMax option
This allows capping the total amount of memory that will be used for
zram-swap, in addition to the percentage-based calculation, which is
useful when blanket-applying a configuration to many machines.
This is based off the strategy used by Fedora for their rollout of
zram-swap-by-default in Fedora 33
(https://fedoraproject.org/wiki/Changes/SwapOnZRAM), which caps the
maximum amount of memory used for zram at 4GiB.
In future it might be good to port this to the systemd zram-generator,
instead of using this separate infrastructure.
---
nixos/modules/config/zram.nix | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/nixos/modules/config/zram.nix b/nixos/modules/config/zram.nix
index 341101bc184..1f513b7e4da 100644
--- a/nixos/modules/config/zram.nix
+++ b/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}
--
2.29.2

View file

@ -1,3 +1,4 @@
pr102855-zram-allow-memorymax.patch
pr103084-teamspeak3-bump-3.5.6.patch pr103084-teamspeak3-bump-3.5.6.patch
pr104891-factorio-bump-1.1.1.patch pr104891-factorio-bump-1.1.1.patch
pr105231-factorio-bump-1.1.2.patch pr105231-factorio-bump-1.1.2.patch