Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Harry Yoo <harry@kernel.org>
Cc: David Hildenbrand <david@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Ben Gardon <bgardon@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
	Chris Mason <mason@kernel.org>
Subject: Re: [PATCH 07/10] memcg, oom: wait for rcu_call callbacks before retrying reclaim
Date: Wed, 2 Dec 2026 20:33:01 +0100	[thread overview]
Message-ID: <axBybX-Y4utVTsrA@tiehlicka> (raw)
In-Reply-To: <axBt-bpsIh1CqjJL@thinkstation>

On Wed 02-12-26 19:22:20, Harry Yoo wrote:
> On Wed, Dec 02, 2026 at 10:54:00AM +0100, Michal Hocko wrote:
> > From: Michal Hocko <mhocko@suse.com>
> > 
> > In a memory cgroup with a small limit, the OOM killer can kill a task
> > while most of the limit is taken up by memory that is already queued to
> > be freed after an RCU grace period.
> > 
> > Memory that was passed to call_rcu() stays charged until its callback
> > frees it. The task_struct and the credentials of an exited child are
> > freed that way. With MMU_GATHER_RCU_TABLE_FREE, so are its page tables.
> > Reclaim cannot free such memory, and call_rcu() does not throttle its
> > caller.
> >
> > So tasks that fork short-lived children can fill the limit with
> > memory that only waits to be freed. When a charge then fails at the
> > limit, try_charge_memcg() reclaims and drains the per-CPU stocks. It
> > then calls mem_cgroup_oom() without waiting for a grace period.
> > 
> > Call rcu_barrier before retrying the charge after unsuccessful reclaim
> > (slow path) to reduce this potential issue.
> > 
> > Reported-by: Chris Mason <mason@kernel.org>
> > Signed-off-by: Michal Hocko <mhocko@suse.com>
> > ---
> 
> I was wondering why we have to call rcu_barrier() for every retry
> instead of just once before OOM. Retrying memory won't free page
> tables anyway.
> 
> Apparently sashiko wondered it too.

I considered this to be a slow path (the full reclaim round to fail) so
additional wait on rcu_barrier doesn't seem all that terrible. Yet we
capture potential memory freers before retrying the charge.
I could have done something like
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a8dd933273c8..7a1e9afed685 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2802,7 +2802,8 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask,
 
 	if (nr_retries--) {
 		/* Wait for any potential call_rcu memory freers */
-		rcu_barrier();
+		if (!nr_retries)
+			rcu_barrier();
 		goto retry;
 	}

to reduce that to the very last run. But this is a bit confusing and in
the worst case we are going through more expensive reclaim rounds while
there might be rcu callbacks sitting and waiting. I do not think we have
a decent way of knowning and making that more directed. But if there is
a general agreement that this is the right way, I can go with that of
course. This would be really hard to measure without artificial
workloads which I do not want to really optimize for.

-- 
Michal Hocko
SUSE Labs


  reply	other threads:[~2026-12-02 19:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:53 [PATCH 0/10] assorted oom fixes Michal Hocko
2026-12-02  9:53 ` [PATCH 01/10] memcg-v1, oom: do not sleep in worker contexts Michal Hocko
2026-12-02  9:53 ` [PATCH 02/10] mm/oom_kill: keep the allocating mm eligible Michal Hocko
2026-12-02  9:53 ` [PATCH 03/10] mm, oom: do not panic on constrained OOMs Michal Hocko
2026-12-02  9:53 ` [PATCH 04/10] mm/oom_kill: ratelimit memcg OOM reports with no victim Michal Hocko
2026-12-02  9:53 ` [PATCH 05/10] mm, oom: thaw tasks sharing the mm with the oom victim Michal Hocko
2026-12-02 16:30   ` sashiko-bot
2026-12-02 19:23     ` Michal Hocko
2026-12-02  9:53 ` [PATCH 06/10] mm, oom: check oom victims prior to numa placement Michal Hocko
2026-12-02  9:54 ` [PATCH 07/10] memcg, oom: wait for rcu_call callbacks before retrying reclaim Michal Hocko
2026-12-02 16:31   ` sashiko-bot
2026-12-02 19:38     ` Michal Hocko
2026-12-02 19:22   ` Harry Yoo
2026-12-02 19:33     ` Michal Hocko [this message]
2026-12-02  9:54 ` [PATCH 08/10] mm, " Michal Hocko
2026-12-02 16:31   ` sashiko-bot
2026-12-02 19:44     ` Michal Hocko
2026-12-02  9:54 ` [PATCH 09/10] mm, oom: add rcu_barrier before hiding victim from the oom killer Michal Hocko
2026-12-02 16:31   ` sashiko-bot
2026-12-02  9:54 ` [PATCH 10/10] memcg: wake v1 OOM lock contenders on unlock Michal Hocko
2026-12-02 13:06 ` [PATCH 0/10] assorted oom fixes David Hildenbrand (Arm)
2026-12-02 19:01   ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axBybX-Y4utVTsrA@tiehlicka \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=bgardon@google.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=harry@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mason@kernel.org \
    --cc=rientjes@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox