From d6a89d71ca9371a2a638b099d33187905fb1295d Mon Sep 17 00:00:00 2001 From: robert dennis <31261583+robertdrakedennis@users.noreply.github.com> Date: Fri, 29 May 2026 23:24:58 -0400 Subject: [PATCH] add conditional support for ioweight --- environment/settings.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/environment/settings.go b/environment/settings.go index 1d57154ee..6850167f4 100644 --- a/environment/settings.go +++ b/environment/settings.go @@ -3,6 +3,7 @@ package environment import ( "fmt" "math" + "os" "strconv" "github.com/apex/log" @@ -107,11 +108,15 @@ func (l Limits) AsContainerResources() container.Resources { Memory: l.BoundedMemoryLimit(), MemoryReservation: l.MemoryLimit * 1024 * 1024, MemorySwap: l.ConvertedSwap(), - BlkioWeight: l.IoWeight, OomKillDisable: &l.OOMDisabled, PidsLimit: &pids, } + // Only set the block IO weight when the host's cgroup hierarchy can honor it. + if blkioWeightSupported() { + resources.BlkioWeight = l.IoWeight + } + // 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. // @@ -131,6 +136,26 @@ func (l Limits) AsContainerResources() container.Resources { return resources } +// blkioWeightSupported reports whether the host's cgroup hierarchy can honor a +// container block IO weight. On cgroup v2 the io.weight knob must be present or +// runc fails container creation; cgroup v1/hybrid always supports it. +func blkioWeightSupported() bool { + // cgroup v1/hybrid honors the weight via blkio.weight; only v2 needs probing. + if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err != nil { + return true + } + // On v2 the knob lives on the delegated child cgroups, not the root. + for _, p := range []string{ + "/sys/fs/cgroup/system.slice/io.weight", + "/sys/fs/cgroup/io.weight", + } { + if _, err := os.Stat(p); err == nil { + return true + } + } + return false +} + type Variables map[string]interface{} // Get is an ugly hacky function to handle environment variables that get passed