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=1796376421; b=BISp1uoCcNo0qN8gIE83Yf39mWZ0w+OkE10s8PIdsOld/ALrmCGSfTYxPzhM/0ZeE3xB 89r416vJIO+YlOxMAvYb/jN/9mmAEguX8p3NrMbnToyXAUKL0KcmbKGn1RnDzB4ojz535 v5Ci6ylmEXkTV3QHZW8G1802GM79qgfohD+xV88CJ8Cm0RPi0ApT34SGsjtUNkmIViiSG eNAbjc6/k1lSDfHQENOie/Qe+lESUnchmXfOT9feNL5O5sA3L/fGGvdBK9TiT6FYMFaZ+ tS5ddQT4OxVWnUIRofGx/vgVOcbbVOsOPCMD8qdCgQ4+YvNbIKejDRHaz3pwJc4oAsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796376421; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=LQbptFoMruJ1EFOUSEABo3UcQZGPmXCgmu8uh07W7ts=; b=3lBauZllkRkDQ6vWugMntxNgtxI0YNsTuV04vACFXUx4ghyjKLBgGL0CVohA0+S+JFz2 +nSdTNjvwIh5dxiYTIZj1Sl4kcCjWuGHZEl7Ct6gzf9/WzUXgqS0jreRO83bAvvVj5lHU ckT+4O/Gi6//CcQ351RPp4JHrv8HrJ3T7Rp0C50fFV7eZBK4wQXpIl8bFChnfEBX9w/BV lIuZSLTgNvp/nex2cplxuBiRoWyp6vi+PYLfJIoCrR6oPeiease2Xeeh5HyxgyieY3ZFV BPNUdCSWRpyADwvKK1cNb4FNtNNbnJOuixsfdrwX5DcCLj6d9RoYfXRIVSPKdgWZdSg== 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=YrQdtVU3; 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 B5B24606A32D for ; Fri, 4 Dec 2026 09:27:01 +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 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-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: <20261204090827.568530-1-mhocko@kernel.org> 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