From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Michal Hocko <mhocko@suse.com>
Cc: sashiko-reviews@lists.linux.dev,
David Hildenbrand <david@kernel.org>,
David Rientjes <rientjes@google.com>,
Ben Gardon <bgardon@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Chris Mason <mason@kernel.org>
Subject: Re: [PATCH 09/10] mm, oom: add rcu_barrier before hiding victim from the oom killer
Date: Wed, 2 Dec 2026 19:57:36 +0000 [thread overview]
Message-ID: <axB38vHgKASeJ3G4@gremlin> (raw)
In-Reply-To: <axB3NJ9PXVomY081@tiehlicka>
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 <mhocko@suse.com>
> >
> > 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
next prev parent reply other threads:[~2026-12-02 19:57 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:53 [PATCH 0/10] assorted oom fixes Michal Hocko
2026-12-02 9:53 ` [PATCH 01/10] memcg-v1, oom: do not sleep in worker contexts Michal Hocko
2026-12-02 9:53 ` [PATCH 02/10] mm/oom_kill: keep the allocating mm eligible Michal Hocko
2026-12-02 9:53 ` [PATCH 03/10] mm, oom: do not panic on constrained OOMs Michal Hocko
2026-12-02 9:53 ` [PATCH 04/10] mm/oom_kill: ratelimit memcg OOM reports with no victim Michal Hocko
2026-12-02 9:53 ` [PATCH 05/10] mm, oom: thaw tasks sharing the mm with the oom victim Michal Hocko
2026-12-02 16:30 ` sashiko-bot
2026-12-02 19:23 ` Michal Hocko
2026-12-02 9:53 ` [PATCH 06/10] mm, oom: check oom victims prior to numa placement Michal Hocko
2026-12-02 9:54 ` [PATCH 07/10] memcg, oom: wait for rcu_call callbacks before retrying reclaim Michal Hocko
2026-12-02 16:31 ` sashiko-bot
2026-12-02 19:38 ` Michal Hocko
2026-12-02 19:22 ` Harry Yoo
2026-12-02 19:33 ` Michal Hocko
2026-12-02 9:54 ` [PATCH 08/10] mm, " Michal Hocko
2026-12-02 16:31 ` sashiko-bot
2026-12-02 19:44 ` Michal Hocko
2026-12-02 9:54 ` [PATCH 09/10] mm, oom: add rcu_barrier before hiding victim from the oom killer Michal Hocko
2026-12-02 16:31 ` sashiko-bot
2026-12-02 19:53 ` Michal Hocko
2026-12-02 19:57 ` Lorenzo Stoakes (ARM) [this message]
2026-12-02 9:54 ` [PATCH 10/10] memcg: wake v1 OOM lock contenders on unlock Michal Hocko
2026-12-02 13:06 ` [PATCH 0/10] assorted oom fixes David Hildenbrand (Arm)
2026-12-02 19:01 ` Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axB38vHgKASeJ3G4@gremlin \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bgardon@google.com \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=mason@kernel.org \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.