Re: [RFC 2/3] mm: process_mrelease: skip LRU movement for exclusive file folios

From: Minchan Kim

Date: Tue Apr 14 2026 - 16:23:32 EST


On Tue, Apr 14, 2026 at 09:20:25AM +0200, David Hildenbrand (Arm) wrote:
> On 4/14/26 00:39, Minchan Kim wrote:
> > For the process_mrelease reclaim, skip LRU handling for exclusive
> > file-backed folios since they will be freed soon so pointless
> > to move around in the LRU.
> >
> > This avoids costly LRU movement which accounts for a significant portion
> > of the time during unmap_page_range.
> >
> > - 91.31% 0.00% mmap_exit_test [kernel.kallsyms] [.] exit_mm
> > exit_mm
> > __mmput
> > exit_mmap
> > unmap_vmas
> > - unmap_page_range
> > - 55.75% folio_mark_accessed
> > + 48.79% __folio_batch_add_and_move
> > 4.23% workingset_activation
> > + 12.94% folio_remove_rmap_ptes
> > + 9.86% page_table_check_clear
> > + 3.34% tlb_flush_mmu
> > 1.06% __page_table_check_pte_clear
> >
> > Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
> > ---
> > mm/memory.c | 13 ++++++++++++-
> > 1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/memory.c b/mm/memory.c
> > index 2f815a34d924..25e17893c919 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -1640,6 +1640,8 @@ static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb,
> > bool delay_rmap = false;
> >
> > if (!folio_test_anon(folio)) {
> > + bool skip_mark_accessed;
> > +
> > ptent = get_and_clear_full_ptes(mm, addr, pte, nr, tlb->fullmm);
> > if (pte_dirty(ptent)) {
> > folio_mark_dirty(folio);
> > @@ -1648,7 +1650,16 @@ static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb,
> > *force_flush = true;
> > }
> > }
> > - if (pte_young(ptent) && likely(vma_has_recency(vma)))
> > +
> > + /*
> > + * For the process_mrelease reclaim, skip LRU handling for exclusive
> > + * file-backed folios since they will be freed soon so pointless
> > + * to move around in the LRU.
> > + */
> > + skip_mark_accessed = mm_flags_test(MMF_UNSTABLE, mm) &&
> > + folio_mapcount(folio) < 2;
>
> folio_mapcount() is most certainly the wrong thing to use if you want to
> handle large folios properly.
>
> Maybe !folio_likely_mapped_shared() is what you are looking for. Maybe.

Didn't know that. I will use folio_maybe_mapped_shared in next revision.

Thank you!