[PATCH 04/10] mm/oom_kill: ratelimit memcg OOM reports with no victim
From: Michal Hocko
Date: Wed Dec 02 2026 - 04:55:07 EST
From: Chris Mason <mason@xxxxxxxxxx>
A memory cgroup that is at its limit and has no killable task can flood
the kernel log with OOM reports, and delay the OOM killer for the rest
of the system.
When a memcg OOM finds no victim, out_of_memory() prints the whole OOM
report and returns false. Nothing was freed, so the next charge that
invokes the OOM killer, or the next write that sets memory.max below the
usage, prints the same report again. Each report is printed with
oom_lock held, which every other OOM in the system needs as well.
The fix used here is to rate limit the report of a memcg OOM with no
victim. All memory cgroups share that rate limit, so a cgroup
that keeps running into such an OOM can suppress the report of another
cgroup. If that turns out to be too limiting we can make this per memcg
but there doesn't seem to be a strong reason to go that way for now
Fixes: 3100dab2aa09 ("mm: memcontrol: print proper OOM header when no eligible victim left")
Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
[mhocko@xxxxxxxx: reworked the original patch]
Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
---
mm/oom_kill.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 660ab39e1df5..7c97f788501d 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -1164,8 +1164,20 @@ bool out_of_memory(struct oom_control *oc)
select_bad_process(oc);
/* Found nothing?!?! */
if (!oc->chosen) {
- dump_header(oc);
- pr_warn("Out of memory and no killable processes...\n");
+ static DEFINE_RATELIMIT_STATE(memcg_rs, DEFAULT_RATELIMIT_INTERVAL,
+ DEFAULT_RATELIMIT_BURST);
+
+ /*
+ * A memcg oom does not panic, and its caller goes on. A memcg
+ * memcg with no killable task gets here with each charge that
+ * calls the oom killer, and with each write to memory.max, so do
+ * not dump each time.
+ */
+ if (!is_memcg_oom(oc) || __ratelimit(&memcg_rs)) {
+ dump_header(oc);
+ pr_warn("Out of memory and no killable processes...\n");
+ }
+
/*
* If we got here due to an actual allocation at the
* system level without any constrains, we cannot survive this
--
2.56.1