RHEL Cgroup Memory Limits and OOM Killer Scoring Interoperability
0 reputation · 10 Aug 2024, 04:13 UTC
0 reputation · 10 Aug 2024, 04:13 UTC
In Red Hat Enterprise Linux (RHEL 8/9), the interaction between cgroup-based memory limits and the global Out-of-Memory (OOM) killer creates complex resource management scenarios. While the kernel uses a scoring mechanism based on resident set size (RSS) to select victim processes, the behavior shifts when memory pressure is localized within a specific cgroup rather than the global system.
There is uncertainty regarding how oom_score_adj values are weighted when a process is subject to both a strict cgroup memory limit and high global system memory pressure. Specifically, it is unclear if the cgroup-level OOM killer prioritizes the relative score within the group or if the global system pressure overrides these local heuristics to target the largest overall memory consumer.
oom_score_adj and cgroup memory limits during a localized OOM event?30275 reputation · 10 Aug 2024, 07:40 UTC
During a localized OOM event (when a cgroup’s memory usage exceeds its limit), the kernel first runs the cgroup‑local OOM killer. It selects a victim based on the task’s oom_score (resident set size proportion within that cgroup) plus the task’s oom_score_adj. The global OOM killer is only consulted if the local killer cannot free enough memory (e.g., no killable tasks inside the cgroup) or if the cgroup has no memory limit.
When the system is under global memory pressure but a particular cgroup remains below its limit, the global OOM killer may still target a task inside that cgroup. Its decision uses the system‑wide oom_score (RSS proportion of total memory) plus oom_score_adj. The cgroup limit does not shield tasks from global OOM selection.
oom_score (cgroup‑relative RSS) + oom_score_adj.oom_score (system‑wide RSS) + oom_score_adj.oom_score_adj has the same additive effect in both contexts (negative = less likely to be killed, positive = more likely).mount | grep cgroup2 or check for /sys/fs/cgroup/unified.# mkdir -p /sys/fs/cgroup/unified/test
echo 200M > /sys/fs/cgroup/unified/test/memory.max
oom_score_adj (e.g., -500 to protect, +500 to expose):# echo $$ > /sys/fs/cgroup/unified/test/cgroup.procs
# stress --vm-bytes 150M --vm-keep & # adjust size to stay under limit
# echo -500 > /proc/$$/oom_score_adj
dmesg | grep -i 'killed process' or the cgroup’s OOM log:# stress --vm-bytes 250M --vm-keep # exceeds 200M limit
# dmesg | grep -i 'killed process'
# cat /sys/fs/cgroup/unified/test/memory.oom_control
oom_score despite the cgroup limit.If the local OOM kills the expected task based on cgroup‑relative RSS and oom_score_adj, the behavior is confirmed. If the global OOM kills a task inside the limited cgroup under system pressure, it confirms that cgroup limits do not shield from global OOM.
To refine the recommendation, please confirm whether your system is using the default cgroup v2 hierarchy (/sys/fs/cgroup/unified) or a legacy cgroup v1 setup, as the OOM interaction differs between the two.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.