Re: [PATCH v2 1/2] mm/rmap: don't defer TLB flushes when unmapping lazyfree folios

From: Lorenzo Stoakes (ARM)

Date: Wed Dec 02 2026 - 15:39:23 EST


On Wed, Dec 02, 2026 at 09:36:56PM +0100, David Hildenbrand (Arm) wrote:
> On 12/2/26 20:49, Lorenzo Stoakes (ARM) wrote:
> > Lazyfree seems like yet another silly edge case thing we shouldn't have done (or
> > maybe should have done better :)
> >
> > But anyway, LGTM so:
> >
> > Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
>
> Thanks.

NP.

> >> ---
> >> mm/rmap.c | 14 ++++++++++++--
> >> 1 file changed, 12 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/mm/rmap.c b/mm/rmap.c
> >> index 038435994b99a..7459722d22d9f 100644
> >> --- a/mm/rmap.c
> >> +++ b/mm/rmap.c

[ ... ]

> >> @@ -2329,11 +2331,17 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> >> * architecture must guarantee that a clear->dirty
> >> * transition on a cached TLB entry is written through
> >> * and traps if the PTE is unmapped.
> >> + *
> >> + * If we don't defer the flush, we flush only once we
> >> + * know that we won't restore the PTEs below. We never
> >> + * defer the flush for lazyfree folios: if we discard
> >> + * them, the PTE will be none, and a page fault could
> >> + * map a new folio while stale TLB entries still exist.
> >> */
> >> - if (should_defer_flush(mm, flags))
> >> + if (!folio_test_lazyfree(folio) && should_defer_flush(mm, flags))
> >> set_tlb_ubc_flush_pending(mm, pteval, address, end_addr);
> >> else
> >> - flush_tlb_range(vma, address, end_addr);
> >> + flush = true;
> >
> > Hmm it's like 'should defer' or 'should defer a little bit' :)
> >
> > But I can't see how the 'slight' delay does any harm and as the commit msg says
> > you avoid unnecessary flushes.
> >
> > Claude mentioned something though it says this exit case the 'not restore PTEs'
> > one can make contpte_set_ptes() restore a previously non-cont block as cont,
> > leaving non-cont TLB entries overlapping new cont ones.
>
> That's arch code problems, and would be pre-existing. I'll ping some people to
> understand if something in arch code might need fixing.

Great thanks! Will leave with you :)

--
Cheers, Lorenzo