From 2b4c66788ad3498c4a0afa454a0f0cb0c661ab05 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 17 Apr 2023 16:16:36 +0200 Subject: [PATCH] cgroup: allow one to set the memory.high CGv2 knob too will be used from our current only call site in pve-container. Signed-off-by: Thomas Lamprecht --- src/PVE/CGroup.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/PVE/CGroup.pm b/src/PVE/CGroup.pm index 7a83ff8..e2839cf 100644 --- a/src/PVE/CGroup.pm +++ b/src/PVE/CGroup.pm @@ -408,7 +408,7 @@ sub get_pressure_stat { # # Dies on error (including a not-running or currently-shutting-down guest). sub change_memory_limit { - my ($self, $mem_bytes, $swap_bytes) = @_; + my ($self, $mem_bytes, $swap_bytes, $mem_high_bytes) = @_; my ($path, $ver) = $self->get_path('memory', 1); if (!defined($path)) { @@ -416,8 +416,11 @@ sub change_memory_limit { } elsif ($ver == 2) { PVE::ProcFSTools::write_proc_entry("$path/memory.swap.max", $swap_bytes) if defined($swap_bytes); - PVE::ProcFSTools::write_proc_entry("$path/memory.max", $mem_bytes) - if defined($mem_bytes); + if (defined($mem_bytes)) { + # 'max' is the hard-limit (triggers OOM), while 'high' throttles & adds reclaim pressure + PVE::ProcFSTools::write_proc_entry("$path/memory.high", $mem_high_bytes // 'max'); + PVE::ProcFSTools::write_proc_entry("$path/memory.max", $mem_bytes); + } } elsif ($ver == 1) { # With cgroupv1 we cannot control memory and swap limits separately. # This also means that since the two values aren't independent, we need to handle -- 2.39.5