Re: [PATCH v1 1/3] mm: process_mrelease: expedite clean file folio reclaim via mmu_gather

From: Minchan Kim

Date: Mon May 11 2026 - 17:49:34 EST


On Mon, May 11, 2026 at 06:13:09PM +0200, Alexander Gordeev wrote:
> On Fri, May 08, 2026 at 02:56:35PM -0700, Minchan Kim wrote:
>
> Hi Minchan,
>
> > > > +void free_pages_and_caches(struct mm_struct *mm, struct encoded_page **pages, int nr)
> > > > +{
> > > > + bool try_evict_file_folios = mm_flags_test(MMF_UNSTABLE, mm);
> > > > + struct folio_batch folios;
> > > > + unsigned int refs[PAGEVEC_SIZE];
> > > > +
> > > > + folio_batch_init(&folios);
> > > > + for (int i = 0; i < nr; i++) {
> > > > + struct folio *folio = page_folio(encoded_page_ptr(pages[i]));
> > > > +
> > > > + if (folio_test_anon(folio))
> > > > + free_swap_cache(folio);
> > > > + else if (unlikely(try_evict_file_folios))
> > > > + free_file_cache(folio);
> > >
> > > This condition is absent in free_pages_and_swap_cache().
> > > What would happen with non-anon and non-evict folio?
> >
> > Are you asking about mlocked pages for file?
> >
> > During unmapping, munlock_vma_folio() inside __folio_remove_rmap() clears
> > the PG_mlocked flag and moves the folio back to the evictable LRU list.
> >
> > By the time the folios reach free_pages_and_caches(), if the folio is
> > exclusive, it will be successfully evicted. However, if the folio is shared,
> > mapping_evict_folio() detects it via the refcount check and skips the
> > eviction.
> >
> > However, I realized we miss shmem folios in the swap cache due to the new
> > folio_test_anon() check we introduced. I will update the check to something
> > like this:
> >
> > if (folio_test_swapcache(folio))
> > free_swap_cache(folio);
>
> This condition looks redundant, since free_swap_cache() checks it too.

What I meant is that the free_pages_and_swap_cache calls free_swap_cache
unconditionally for all those folio but my change in
free_pages_and_cached calls it only anon folio, which will miss shmem
cases.