Re: [PATCH 2/4] mm/vmscan: flush deferred writable TLB entries before unlocking the folio

From: Jose A. Perez de Azpillaga

Date: Wed Nov 18 2026 - 17:36:00 EST


On 11/18/26 10:20 AM, David Hildenbrand (Arm) wrote:
> try_to_unmap() with TTU_BATCH_FLUSH transfers the PTE dirty bit to the
> folio and defers the TLB flush.
>
> Reclaim must flush the TLB before unlocking the folio, otherwise stale
> writable TLB entries might be left behind temporarily: writeback started
> by other mechanisms (e.g., fsync) will not find any mappings in
> folio_mkclean(), so it will neither write-protect nor flush anything.
>
> A write through a stale TLB entry after the folio was cleaned gets lost
> once the folio is reclaimed.
>
> However, reclaim currently does not flush the TLB if the now-dirty folio
> does not get written back (e.g., gets activated or kept instead). Fix it
> by flushing right after try_to_unmap() if the folio is dirty, which makes
> the existing flush before pageout() unnecessary.
>
> For dirty page-cache folios that reclaim activates, we will now flush the
> TLB immediately after unmapping them instead of batching the flush, which
> is the right thing to do. Performance-wise, it shouldn't really matter
> much, because folios with dirty PTEs are usually young and reclaim won't
> even try to unmap them.
>
> Fixes: d950c9477d51 ("mm: defer flush of writable TLB entries")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

LGTM:

Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>

--
cheers,
jose a. p-a