[PATCH 0/4] mm/vmscan: refactor shrink_folio_list()
From: Zhang Peng
Date: Sun Sep 20 2026 - 10:25:32 EST
shrink_folio_list() has grown into a very long function whose body mixes
several independent concerns: folio activation, the pageout() dispatch
state machine, the unmap step, and the final freeing path. The control
flow between them is expressed entirely through a chain of goto labels
(activate_locked, activate_locked_split, keep_locked, keep), which makes
it hard to see which decision each block actually reaches.
This series extracts four self-contained blocks into helpers, without
changing behaviour:
Patch 1: the activation block at activate_locked, into
folio_activate_locked().
Patch 2: the freeing path (buffer release, lazyfree, __remove_mapping,
folio_batch drain), into folio_try_reclaim_free().
Patch 3: the pageout() dispatch state machine, into
folio_try_pageout().
Patch 4: the TTU setup and try_to_unmap() block, into
folio_try_unmap().
Rather than returning a boolean, the extracted helpers return an explicit
result enum, so the reclaim decisions the caller has to make - activate,
keep, or reclaimed - stay visible at the call site instead of being
buried in the helper. Where a folio may be returned either locked or
unlocked, the result also records which, so the caller does not have to
infer the lock state from an invisible internal decision.
This is preparation for batching the dirty TLB flush before pageout,
which needs to call the pageout path from a second place. That change
will be posted separately once this cleanup has landed [1].
No functional change intended.
[1] https://lore.kernel.org/all/CAGsJ_4wrQRGjqavMzWgi2+PrRr1ztf4QRZEb6HKm02OF8nEBUQ@xxxxxxxxxxxxxx/
Suggested-by: Kairui Song <kasong@xxxxxxxxxxx>
Signed-off-by: Zhang Peng <bruzzhang@xxxxxxxxxxx>
---
Zhang Peng (4):
mm/vmscan: introduce folio_activate_locked() helper
mm/vmscan: extract folio reclaim freeing from shrink_folio_list()
mm/vmscan: extract folio pageout from shrink_folio_list()
mm/vmscan: extract folio unmap logic into folio_try_unmap()
mm/vmscan.c | 376 +++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 217 insertions(+), 159 deletions(-)
---
base-commit: 498ee28e5ec4727f829507c4a1bde3ab1b7704cd
change-id: 20260919-vmscan-refactor-1b3e5588af52
Best regards,
--
bruzzhang <bruzzhang@xxxxxxxxxxx>