From 9a58c23c1706b54a00c838b3dc7692e47f48ed92 Mon Sep 17 00:00:00 2001 From: m3ow Date: Tue, 16 Dec 2025 13:09:09 -0500 Subject: [PATCH] Change OOM killer behavior under Cgroupv2 --- environment/settings.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/environment/settings.go b/environment/settings.go index 596da6fc..8ae34ab6 100644 --- a/environment/settings.go +++ b/environment/settings.go @@ -3,6 +3,7 @@ package environment import ( "fmt" "math" + "os" "strconv" "github.com/apex/log" @@ -108,15 +109,24 @@ func boolPtr(b bool) *bool { // that Docker understands. func (l Limits) AsContainerResources() container.Resources { pids := l.ProcessLimit() + resources := container.Resources{ Memory: l.BoundedMemoryLimit(), MemoryReservation: l.MemoryLimit * 1024 * 1024, MemorySwap: l.ConvertedSwap(), BlkioWeight: l.IoWeight, - OomKillDisable: boolPtr(!l.OOMKiller), PidsLimit: &pids, } + // If the user wants to disable the OOM killer, we need to handle it differently + // depending on the cgroup version. + if !l.OOMKiller { + if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil { + } else { + resources.OomKillDisable = boolPtr(true) + } + } + // If the CPU Limit is not set, don't send any of these fields through. Providing // them seems to break some Java services that try to read the available processors. //