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

From: Zi Yan

Date: Thu Nov 19 2026 - 16:47:34 EST


On 18 Nov 2026, at 4:20, 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>
> ---
> mm/vmscan.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
Makes sense.

Acked-by: Zi Yan <ziy@xxxxxxxxxx>

Best Regards,
Yan, Zi