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=1796241461; b=WcMJszX5EaYxL/zT1GEEcqs4BzC3PHVpLTahUQrhlBtZYz3G1FFNbBzPhsmIqXqh5sic ++eYnYrT2AVxUneYKXE0YF9SQj90flPYmW4VqzQIlIwhUca7OMM+Kr7GX2pPeJP3HVi5D IVjN0KbDilpU1piC7yblNORXPR02xNgDBFEAHZO+amx7PO9CSx7R0XbYljsOswoXeL+yY qODUcOCy1NaMeYDNiKMRrmdL66SiTbsIzxRi5Khm09A4aAohOUAQuZZFyUj2MCa2/RNaM JNlDSSiGgj4UoE8M0vp/zRyosdO9VfQk+VjHXR+1YittkI3WGyKXe6eyjoY3bQNGW6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796241461; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=+LSkKTC8WrS9+ym6glwWp0UMi0IxYXL/19zSV3UkgHA=; b=xmabnrSWXjN1TefVgLtaKU2hj/y7kFBEi2NPRLcSlsjOqMOavYIgostEv/Nr1jywKyzH axbIBN9pXvLLxRT8cj5Nqhhi9UxGY7KYc1aLVcXK77QV5tqg7RKKnnx5vtgdz6xRMTnF7 B1kK+ivK6TK4I4ohfnQccUbQmlpkXucVHKTcwJcpYcrNaOPa9DTUtUrGrIvvjY9YgJ8hs wmwWKbEX63BmikSzqf89A2IIfQzZI1hpFTc/ZbZRa8O7NygbYlgKQmR6S7obcAlgO6fGT NaLuoOg2LK6AAX4m6bVtkCS02Vfbd4enjfJwfOg5xUdWJiTRYkmBTbNnzZVlPnJQvew== 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=lWvnu1BE; 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 64362606A336 for ; Wed, 2 Dec 2026 19:57:41 +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=lWvnu1BE Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAC471F00897; Wed, 2 Dec 2026 19:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796241461; bh=+LSkKTC8WrS9+ym6glwWp0UMi0IxYXL/19zSV3UkgHA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=lWvnu1BEi/FoyM+PSYomLZfpSInzmgWm3FORb3AB0mwzcB8P/XXyl8RHSYKEwSXkT ctXQu88pZ2QKMu40vpE51syisJdO49k74tSe4DOMSA66c702PEE92O7TCnrwzLddS4 pZfdy3szpynVy/AhXE1k18+jyiPgoq8DYMmLaKw/mlxcZ4KOdrApOsGPARQ3nXIW/B LD6Khw1G1GluoFhwtM9mL6TcQZpPtGjhTLt0JvhcZmeXOB8mFeE3fRZvnR5ouEN2Ze kFWZfljZo6pT1SsnhqnouWbaCCpNxTlqKkHifMQS6mL9dfPpAOqFBN6i5Nc3SE3RUm rqCUEMKpM2oPQ== Date: Wed, 2 Dec 2026 19:57:36 +0000 From: "Lorenzo Stoakes (ARM)" To: Michal Hocko Cc: sashiko-reviews@lists.linux.dev, David Hildenbrand , David Rientjes , Ben Gardon , Johannes Weiner , Andrew Morton , linux-mm@kvack.org, Chris Mason Subject: Re: [PATCH 09/10] mm, oom: add rcu_barrier before hiding victim from the oom killer Message-ID: References: <20261202095450.296675-1-mhocko@kernel.org> <20261202095450.296675-10-mhocko@kernel.org> X-Mailing-List: sashiko-reviews@lists.linux.dev 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: On Wed, Dec 02, 2026 at 08:53:24PM +0100, Michal Hocko wrote: > Forgot to CC Lorenzo, sorry about that. Apology should be mine, sorry did mean to take a look at this off-list previously, just snowed under! I guess you'll respin given the below? I can wait for that I guess? > > On Wed 02-12-26 16:31:03, sashiko-bot@kernel.org wrote: > > Thank you for your contribution! Sashiko AI review found 1 potential > > issue to consider: > > - [High] mm: exit_mmap() delays tlb flush and MMF_OOM_SKIP across > > free_pgtables() > > -- > > > > commit 1c8250a513b4c920254c3d354feba98a795ac23c > > Author: Michal Hocko > > > > mm, oom: add rcu_barrier before hiding victim from the oom killer > > > > This commit adds rcu_barrier() before setting MMF_OOM_SKIP in > > oom_reap_task() and exit_mmap(), and moves the MMF_OOM_SKIP update in > > exit_mmap() after free_pgtables() and tlb_finish_mmu(). > > > > > diff --git a/mm/mmap.c b/mm/mmap.c > > > index ec55ccbb88055..8974405faf490 100644 > > > --- a/mm/mmap.c > > > +++ b/mm/mmap.c > > > @@ -1317,20 +1317,8 @@ void exit_mmap(struct mm_struct *mm) > > > /* update_hiwater_rss(mm) here? but nobody should be looking */ > > > /* 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. > > > - */ > > > - 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); > > > @@ -1338,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. > > > + */ > > > + if (mm_is_oom_victim(mm)) { > > > + rcu_barrier(); > > > + mm_flags_set(MMF_OOM_SKIP, mm); > > > + } > > > > [Severity: High] > > Does removing tlb_flush_mmu(&tlb) after unmap_vmas() and delaying > > MMF_OOM_SKIP across free_pgtables() leave gathered data folios unfreed > > while blocking the OOM reaper on mmap_write_lock(mm)? > > > > unmap_vmas() clears the PTEs and leaves up to MAX_GATHER_BATCH_COUNT > > batches of unmapped data pages queued in exit_mmap()'s on-stack > > struct mmu_gather tlb until tlb_finish_mmu(). Once the PTEs are cleared, > > a concurrent oom_reap_task_mm() cannot reclaim those pages from the page > > tables either. > > > > free_pgtables() then runs under mmap_write_lock(mm) and takes sleeping VMA > > and rmap locks (vma_start_write(), anon_vma->root->rwsem in > > unlink_anon_vmas(), and mapping->i_mmap_rwsem in > > unlink_file_vma_batch_final()), followed by rcu_barrier() still under > > mmap_write_lock(mm). > > > > While exit_mmap() is blocked in free_pgtables() or rcu_barrier() holding > > mmap_write_lock(mm), oom_reap_task_mm() fails mmap_read_trylock(mm). After > > MAX_OOM_REAP_RETRIES, oom_reap_task() sees MMF_OOM_SKIP still clear, emits > > false "oom_reaper: unable to reap pid" warnings and lock dumps (regressing > > 97b1255cb27c ("mm,oom_reaper: check for MMF_OOM_SKIP before complaining")), > > and sets MMF_OOM_SKIP while the gathered data pages in tlb are still > > unfreed (regressing a35b6312255d ("mm/mmap: free gathered pages before > > MMF_OOM_SKIP")). > > OK, my primary intention was to delay MMF_OOM_SKIP primarily. But > dropping tlb_flush_mmu seems just pointless (well, just to save one > branch in the exit hot path) and it can actually do more bad than good. > I will fold this in > > diff --git a/mm/mmap.c b/mm/mmap.c > index 87b081f85370..0b19c720473a 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1313,6 +1313,10 @@ void exit_mmap(struct mm_struct *mm) > /* update_hiwater_rss(mm) here? but nobody should be looking */ > /* Use ULONG_MAX here to ensure all VMAs in the mm are unmapped */ > unmap_vmas(&tlb, &unmap); > + > + /* Free batched pages during unmap_vmas ASAP for oom victims */ > + if (mm_is_oom_victim(mm)) > + tlb_flush_mmu(&tlb); > mmap_read_unlock(mm); > > mmap_write_lock(mm); > -- > Michal Hocko > SUSE Labs -- Cheers, Lorenzo