Re: [PATCH v5 5/5] mm/vmscan: flush TLB for every 31 folios evictions
From: Barry Song
Date: Thu Aug 13 2026 - 17:59:15 EST
On Mon, Jul 20, 2026 at 1:08 PM Zhang Peng <zippermonkey@xxxxxxxxxx> wrote:
>
> Currently we flush TLB for every dirty folio, which is a bottleneck for
> systems with many cores as this causes heavy IPI usage.
>
> So instead, batch the folios, and flush once for every 31 folios (one
> folio_batch). These folios will be held in a folio_batch with their lock
> released, then when the folio_batch is full, do the following steps:
>
> - For each folio: trylock - recheck still evictable (writeback, mapped,
> dma_pinned). If no longer evictable, put back via ret_folios.
> - Flush TLB once for the whole batch.
> - Pageout each survivor via folio_try_pageout().
>
> The recheck step is required because dropping the folio lock between
> shrink_folio_list() and pageout_batch() opens a window in which a
> parallel swapin (do_swap_page) can fully complete and install a new PTE;
> once mapped, a parallel GUP can pin the folio without taking the folio
> lock. Folios caught by any of these checks are put back via ret_folios.
>
> Suggested-by: Kairui Song <kasong@xxxxxxxxxxx>
> Signed-off-by: Zhang Peng <bruzzhang@xxxxxxxxxxx>
Yes, I think batching the dirty flush is a great idea. I can clearly
see that IPIs for dirty flushes (smp_call) on x86 take up a
significant part of the flame graph when building the kernel in a
memcg, so I think this is something we should pursue.
Could we revisit this patch after we clean up the previous ones?
Best Regards
Barry