Re: [PATCH] mm/vmscan: skip lazyfree folios when demoting in shrink_folio_list()
From: Barry Song
Date: Tue Nov 03 2026 - 19:44:00 EST
On Wed, Nov 4, 2026 at 8:24 AM Bing Jiao <bingjiao@xxxxxxxxxx> wrote:
>
> shrink_folio_list() currently demotes lazyfree (MADV_FREE) folios to
> lower-tier memory instead of discarding them. In the earlier patch
> series [1] that commit 26aa2d199d6f ("mm/migrate: demote pages during
> reclaim") was based on, demotion was inside the PageAnon(page) &&
> PageSwapBacked(page) block with a comment to skip MADV_FREE pages. When
> that commit moved do_demote_pass above the block to also demote file
> pages, the PageSwapBacked check excluding lazyfree pages was dropped.
>
> Demoting lazyfree folios during reclaim does not make sense. Userspace
> already marked the contents as discardable under memory pressure. Even
> if MADV_FREE is treated as a cache to avoid page allocation and zeroing,
> folios in shrink_folio_list() have already aged to the tail of the
> inactive LRU, and demoting them still allocates a new page on the lower
> tier, copies stale data, and unmaps the PTE.
>
> Skip folio_test_lazyfree(folio) in the do_demote_pass check so lazyfree
> folios proceed to the normal reclaim path in shrink_folio_list().
>
> Link: https://lore.kernel.org/r/1560468577-101178-6-git-send-email-yang.shi@xxxxxxxxxxxxxxxxx [1]
> Signed-off-by: Bing Jiao <bingjiao@xxxxxxxxxx>
> ---
This makes sense to me. Lazyfree folios can be freed
directly, and we're already in the reclaim path. Allocating
and copying them seems wasteful.
It would be even better to have some real-world workload data
to back this up?
Best,
Barry