From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796300682; b=qxfTOjZFomuEIiVW/fRzaxcR8sTgy9xXLyoI+IH7fI6YEOaAlsyyxywkUfZOzu0KLbYU K6T4eITi3nI+06Wb6qkb+ZZfyzi6PVu5JdGuOos5/xVzTu1/YpmCoKtKaLEJjtfMsoQHI F1aNc+aInU2g5gCCqpiCvAbGIwWzXv+ZSfIbH4/VP6DzC3zZINTduSHXy1T/zQXM4t3kN KTV2R3MLbSQ6JSIGCmRS4PXgDnCweaOL+CsKgzOQEDCzt747izrOBugxuHO79vsEwo4Ep 6c6Pcrymu4AFrbtPpEk+avl6urIYZJel8BmbvWIfJzA0iykfAtJs/IurUFc4sTjAwPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796300682; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=zD9VR2dsfh/aPYcuMCBeW64nqwcJ4ssLXWyxvC2twn0=; b=Ltm7kVpHk83lxuarAeAGaG79mV6EGeegG1R4NdPuWpnAM7Mf0k3k91gHLTAj29gx9Ags RSbV63t2lpSpAcl1LVjUhYJD/od++S82EfbQmK7aObeFSVa5K2ncOqSZiEYHKJoEZIowG ZPEpTX3zsXwOAgS7GyBnGBGY/b2aXVci+sSWH4msFvZZ7+LfHzP8p8Tm9SvzHcuqO+Mtg vhNO6wCVttJ22ux6+PgPJn6A2FKK/ziA1df+5nrn/23PIf5y1YLRzOi8OOGZekNtqjKwf gEsqfqDVJOGEbjL+XkiHoqKZBD3I2Eof54f0ka4XCTY+m61vxFjDKx0oxmhVm5Jdp1Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QkCwKznO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6296606A687 for ; Thu, 3 Dec 2026 12:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QkCwKznO Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2E7F1F00899; Thu, 3 Dec 2026 12:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796300682; bh=zD9VR2dsfh/aPYcuMCBeW64nqwcJ4ssLXWyxvC2twn0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=QkCwKznOvc0cCY5+qawpevgEzthVqav5dAxRf76U0311pW0di7O9FAPx3IdDVnHno qa8F19zVsDYrfxA+yU/UKTsDSXYQXBcdSSijXpU06j5ZuZSk47E9ryYbWOCrKKyQfo WuVrfyVsOYBV5UqjcEhdizvCnlCuDYD/G4zzVL5KLcJc1pn3FO4OMPTRw2rfMyZSxA czB0ehHf+ZwA/uWXaf2qHYsYvaWtViOfei2lkNc0tMZpN6oDu+6Jh1zie9rgu2wEJF JaSrp+7vgzynkRTUeMT604PuhPiQYya24W6oncLfxgGFMdq3LeEJ/0Ledz4WEftq/7 utTbzHsUbrisQ== Date: Thu, 3 Dec 2026 12:24:37 +0000 From: "Lorenzo Stoakes (ARM)" To: Michal Hocko Cc: David Hildenbrand , Andrew Morton , David Rientjes , Ben Gardon , Johannes Weiner , linux-mm@kvack.org, LKML , Michal Hocko , Chris Mason , "Paul E. McKenney" Subject: Re: [PATCH v2] mm, oom: add rcu_barrier before hiding victim from the oom killer Message-ID: References: <20261202095450.296675-10-mhocko@kernel.org> <20261202212147.379270-1-mhocko@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261202212147.379270-1-mhocko@kernel.org> OK so for this one I think worth bringing in the big guns, i.e. Paul :) On Wed, Dec 02, 2026 at 10:21:47PM +0100, Michal Hocko wrote: > From: Michal Hocko > > OOM victim could have released quite a lot of memory through rcu_call > path (e.g. page tables). Call rcu_barrier before setting MMF_OOM_SKIP > on the victim to wait for those to execute before the oom killer is > allowed to pick another victim. > > Also move MMF_OOM_SKIP in exit_mmap path after page tables are freed > to capture as much memory as possible to be freed. This is safe from > the forward progress POV because oom_reaper will run concurrently in > case the exit path gets stuck. We are going to see less memory freed Ah OK sorry I only just read this, but commented below. How certain are we of this though? Both calls have no timeout and both take rcu_state.barrier_mutex I think so I fear that actually we _might_ have a forward-progress issue here? Have you been able to somehow pressure test this? I hate to say it but AI is pretty good at coming up with this kind of thing and iterating on it. We should definitely tread carefully here anyway. > by the oom reaper because it cannot tear down page tables directly > but that should be acceptable. > > Reported-by: Chris Mason > Signed-off-by: Michal Hocko > --- > mm/mmap.c | 19 ++++++++++--------- > mm/oom_kill.c | 7 +++++++ > 2 files changed, 17 insertions(+), 9 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index 4cb18b217048..0b19c720473a 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1314,19 +1314,11 @@ void exit_mmap(struct mm_struct *mm) > /* Use ULONG_MAX here to ensure all VMAs in the mm are unmapped */ > unmap_vmas(&tlb, &unmap); > > - /* > - * Free the memory before marking MMF_OOM_SKIP so a re-triggered OOM > - * killer will only skip this mm if it's already freed all it can. > - */ > + /* Free batched pages during unmap_vmas ASAP for oom victims */ > if (mm_is_oom_victim(mm)) > tlb_flush_mmu(&tlb); > mmap_read_unlock(mm); > > - /* > - * Set MMF_OOM_SKIP to hide this task from the oom killer/reaper > - * because the memory has been already unmapped. > - */ > - mm_flags_set(MMF_OOM_SKIP, mm); > mmap_write_lock(mm); > unmap.mm_wr_locked = true; > mt_clear_in_rcu(&mm->mm_mt); > @@ -1334,6 +1326,15 @@ void exit_mmap(struct mm_struct *mm) > free_pgtables(&tlb, &unmap); > tlb_finish_mmu(&tlb); > > + /* > + * Free the memory before marking MMF_OOM_SKIP so a re-triggered OOM > + * killer will only skip this mm if it's already freed all it can. > + */ Shouldn't we say this is paired with oom_reap_task(). Is it right to say that Paul? :) > + if (mm_is_oom_victim(mm)) { > + rcu_barrier(); So this is a fairly heavyweight barrier I think, it waits for _all_ in-flight call_rcu() callbacks to complete. Reading the rcu_barrier() code briefly suggests it does a _lot_ there. And this is a super sensitive point - will this always result in forward progress? Could it be significantly delayed? Are there any lock dependencies that could be problematic? > + mm_flags_set(MMF_OOM_SKIP, mm); > + } > + > /* > * Walk the list again, actually closing and freeing it, with preemption > * enabled, without holding any MM locks besides the unreachable > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 6ff1e93ec6e3..e0c2e3e647aa 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -628,6 +628,13 @@ static void oom_reap_task(struct task_struct *tsk) > done: > tsk->oom_reaper_list = NULL; > > + /* > + * Make sure that pre-exising call_rcu users will get a chance to > + * free up memory. This might have been exiting task itself as well > + * so call this before we hide the current victim from the oom killer. > + */ > + rcu_barrier(); Similar comments here. Paul what do you think? > + > /* > * Hide this mm from OOM killer because it has been either reaped or > * somebody can't call mmap_write_unlock(mm). > -- > 2.56.1 > -- Cheers, Lorenzo