From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FCF6606A336 for ; Thu, 3 Dec 2026 12:24:47 +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 kanga.kvack.org (Postfix) id 3E7DE6B05B4; Thu, 3 Dec 2026 07:24:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 398C26B05B5; Thu, 3 Dec 2026 07:24:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 287676B05B6; Thu, 3 Dec 2026 07:24:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0768C6B05B4 for ; Thu, 3 Dec 2026 07:24:45 -0500 (EST) Received: from smtpin22.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 842FF80630 for ; Thu, 3 Dec 2026 12:24:45 +0000 (UTC) X-FDA: 85502590530.22.938F17B Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf16.hostedemail.com (Postfix) with ESMTP id 9E69B180003 for ; Thu, 3 Dec 2026 12:24:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=QkCwKznO; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of ljs@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=ljs@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796300683; b=pucHt36k7x/2KyyscBvseCdI7AemKcLnT82v+YbUP+a0duzRDzKGhc5ZPUEcBfPM38i8TN CNY5Y31HxnX1/5Nyhgo/xASmfkJdfqYGKdvjGwZLJYgbnoQv8Zq6GfQHUAhigiE8sg9jn6 QOuXD3iGXcQO8+vZyiUmmiBLPpNTzMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796300683; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zD9VR2dsfh/aPYcuMCBeW64nqwcJ4ssLXWyxvC2twn0=; b=QtJaxw5Ihhpg4MZXaFVYMKlEeN3Jcu6IKua6BTpXybGEFuATngceNQxZbdlfdfJah7V33Y YDj38oDJz5dX5u3cLtDiS6hE2DsbUtT9aR9GUeIc57u9/Q0RH9DvjgXB14e4xB867ngY3h 7izBb+2Cjuew0Uk3Uf6C8OyXPIJjrZ8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=QkCwKznO; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of ljs@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=ljs@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id CE7FB4326F; Thu, 3 Dec 2026 12:24:42 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261202212147.379270-1-mhocko@kernel.org> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9E69B180003 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Stat-Signature: i5maarzauu7n7t6prpca8ua819qni6bj X-Rspam-User: X-HE-Tag: 1796300683-127500 X-HE-Meta: U2FsdGVkX19VAHk/KVfXO1EZrG7dtsbSghKY1vOffe2lxprj1pkrRlTTg8Gn6tTmzI8td/c/uzp2M1G5ksJuFTDGjzOwwcXkByCu3yIF43KFBEhN/NX+9/4n1A1p/9rO4/YI7SSDpltXn+n9j5X5pTMInICtUUoAsmdhluUJuAlbwNmPapOpp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bsOjixFaW51pt7HDOlWmXzbALSh9ZRwYjpaWzl5xl80eCzCGKSPBMVGL7mdPpT5vtzMDhZyo/NRZBFZ324Ve/uiwx+BjFPzY0mGB1yvxHThEiTujh/aEZBxv2Lvp13kMpzMVodpg7ryWr1uYtatgag/TLT/9txi4q85ZAiMIsycx9WVc0YpcDkoY7sTeujJ1yxevgc7UyoybAvU7KhLo5cuvkJGDvLm2y0SGbywNOH8jKK5qmZFOzzwHoGv2t+MosHr+eljgWWwuWq2aQ0ty7XZqjgYAUL+iQi1qWwBKGikwAlYfdrQlfSqS5WmZD70I/4wamZ6Y03mvHdo= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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