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 190BF606A322 for ; Fri, 4 Dec 2026 09:27:09 +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=YrQdtVU3 Received: by kanga.kvack.org (Postfix) id E63426B00EF; Fri, 4 Dec 2026 04:27:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E14196B05B3; Fri, 4 Dec 2026 04:27:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2A646B05B7; Fri, 4 Dec 2026 04:27:07 -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 AA5396B00EF for ; Fri, 4 Dec 2026 04:27:07 -0500 (EST) Received: from smtpin12.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 753371402B6 for ; Fri, 4 Dec 2026 09:27:04 +0000 (UTC) X-FDA: 85505771568.12.03EDD32 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf12.hostedemail.com (Postfix) with ESMTP id D89EB4000E for ; Fri, 4 Dec 2026 09:27:02 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=YrQdtVU3; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of ljs@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ljs@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796376423; b=fUKp2I7qFCFp3JLjX6qeC6QwS6L1n2D8tadrZ4/nQBQsfgUczw7ufAsDQBuUXRbqp5tsTW Hg598833roQF221m7d6s5glBVytZ41vbYsXo8YnnlGhxymGJeNL2jwuzGuLxjDAx/GlEy4 volMihfxhmc0tUxK24/BGfNjiTvxiQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796376423; 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=LQbptFoMruJ1EFOUSEABo3UcQZGPmXCgmu8uh07W7ts=; b=cekZ023yDC7Iamtsi3aAwQT7Whdlari22ATFkvd4dvaOVSD8BP5DLgL8DcJKJ4jwAlBfb0 W7HIXdDvT7DacbT4hBuzklMiuF3DyiExZz7ZeOEq4R1r5tAesQsp4xnfTt8p7c6jsW2/Kc BldavtpiwNsA1Zx18v/Cs1PuWiG5sR4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=YrQdtVU3; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of ljs@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ljs@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 9F5FE60A52; Fri, 4 Dec 2026 09:27:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD37F1F000C2; Fri, 4 Dec 2026 09:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796376421; bh=LQbptFoMruJ1EFOUSEABo3UcQZGPmXCgmu8uh07W7ts=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=YrQdtVU34OxZTmK2UB2UurCDZg1CXAB5RTfrKOWEoQhvnEQr43/5i+/ftElE4Sr4N HKrzOhN1ITIUJgZjG9HtGza9UVO0f2QfNAwsN39bxf3gYGJ+mKqaHoHOgIdxmkuUWo bNzJH0NzJS6VHror4RgUPH6N9sB1KQTGzTBf3XIM7zSA85+0PaIXHaAIjC/7dMqw3u ILTxeZMTkIal7PxYReprG9ZmtHxcw22q3Jos0uayHu/DLf19703VF9U/asSC7VI86q hc4ZE3CSx9kLnSOwumogUip+1g2teI3VqH07tV1NQnANFxebWFbQImIolNK796VQOM eMDJNiWt4YHRA== Date: Fri, 4 Dec 2026 09:26:56 +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 Subject: Re: [PATCH v3] mm, oom: move MMF_OOM_SKIP after page table releasing in exit_mmap Message-ID: References: <20261202212147.379270-1-mhocko@kernel.org> <20261204090827.568530-1-mhocko@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261204090827.568530-1-mhocko@kernel.org> X-Rspamd-Queue-Id: D89EB4000E X-Stat-Signature: 1dixodhck69zxaoor3aj677r6qg9skfo X-Rspam-User: X-Spam-Status: No, score=-16.2 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-Rspamd-Server: rspam08 X-HE-Tag: 1796376422-628312 X-HE-Meta: U2FsdGVkX180fsNLhp2qfuJ5RlMenKpicxeQaU4n8Xz03G2KPOhjQkmAshOBZi5yOOdDtYL7/JyrOe5dcgpYKF7JgjvIibfPMbcJBot0XLzS+Awvj//zdxj55PGVhNh2frTjrKBYUzz1s2pvRyEcfTbRTHiIWdd9Zked1F+I+mSF6T+6+cO62A2veZHM2gkeP0DEj3FUeLOFo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AsoHnBRw2WYgcfhxguYVWwAtlVAz0QswmFFV3PIQy4D3ySgqv5ainYlqIAihhAtQUpvS56hHngurBZOj+nsCpIkE06riHrRVSOVQPxwnAfBw9VEBvpo60Wv41+2PB+5i6X4Zgn54OuiVn9VcrHLwfINVb4HbRKyG8h7eEpA6D97uSx0j0jkSAP6CiudvXpznRvLuZNM986d8mKdecs7YGPQMJy4U+Slaj/78Bhiu/IBta0H+YpHL/zihwAegwDC7lzkcA2FTi/NAstMMr8Yd27GYQzfDGXZI0s+2n+HF4pnCecYAbD24M 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 On Fri, Dec 04, 2026 at 10:08:27AM +0100, Michal Hocko wrote: > From: Michal Hocko > > OOM victim could have consumed quite a lot of memory through page tables > and those are currently released after we set MMF_OOM_SKIP in the > exit_mmap path. If the memory consumed through the address space is not > sufficient to recover from the OOM (e.g. most of it is shared memory > etc.) then we could go after another oom victim even though page tables > could have released enough memory to prevent from that. > > Move MMF_OOM_SKIP in exit_mmap path after page tables freeing to capture > as much memory as possible to be released. We need to wait for RCU > callbacks to see that memory freed. > > In order to prevent oom reaper or process_mrelease to stumble over freed > page tables they are checking MMF_OOM_SKIP under mmap_lock for read > which is synchronized with MMF_OOM_SKIP set under exclusive lock after > page tables are freed. > > The move is safe from the forward progress POV too because oom_reaper > will run concurrently in case the exit path gets stuck and also if RCU > callbacks are not making forward progress for whatever reason and it > will bail out by setting MMF_OOM_SKIP. Up until exit_mmap takes the > exclusive mmap_lock they will cooperate in releasing the address space. > We are going to see less memory freed by the oom reaper because it > cannot tear down page tables directly but that should be acceptable. > Please note that the reaper execution is delayed so the freeing should > be typically done the exit path. > > Reported-by: Chris Mason > Signed-off-by: Michal Hocko Nice, lovely to see my RCU page table work coming in useful here :)) Reviewed-by: Lorenzo Stoakes (ARM) > --- > mm/mmap.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > Changes > since v1 > - restore tlb_flush_mmu after unmap_vmas > since v2 > - dropped rcu_barrier from the oom_reaper path as there might be > an obscure case when RCU grace period might allocate > https://lore.kernel.org/all/ed6c5f64-7afe-45a2-8d18-e4e1c0052840@paulmck-laptop/T/#u > - set MMF_OOM_SKIP unconditionally in exit_mmap path > - reworded the changelog to better describe the actual problem > and explain the coordination and synchronization between exit, > process_mrelease and oom_reaper > > diff --git a/mm/mmap.c b/mm/mmap.c > index 4cb18b217048..eeb39eaeb23a 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,14 @@ 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. > + */ > + if (mm_is_oom_victim(mm)) > + rcu_barrier(); > + 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 > -- > 2.56.1 > -- Cheers, Lorenzo