[PATCH RFC 7/8] mm/huge_memory: walk the after-split anon folios in reverse order
From: Kairui Song via B4 Relay
Date: Fri Nov 13 2026 - 17:04:19 EST
From: Kairui Song <kasong@xxxxxxxxxxx>
Just like the file folio, walk the after-split range with folio_prev()
so the pieces are queued in ascending reclaim order where the forward
walk left them descending, and the cached "next" goes away. All of its
users either expects an ascending or do not care.
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/huge_memory.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index e16b93318613..2ff201a5e5f3 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -4076,7 +4076,7 @@ static int __folio_freeze_split_anon(struct folio *folio,
struct folio *end_folio = folio_next(folio);
struct swap_cluster_info *ci = NULL;
const int old_order = folio_order(folio);
- struct folio *new_folio, *next;
+ struct folio *new_folio;
struct anon_vma *anon_vma = NULL;
enum ttu_flags ttu_flags = 0;
struct lruvec *lruvec;
@@ -4137,15 +4137,15 @@ static int __folio_freeze_split_anon(struct folio *folio,
ret = __split_frozen_folio(folio, new_order, split_at, NULL, split_type);
/*
- * Unfreeze the after-split folios and put them back to the right
- * place. Keep the head @folio frozen until the end: sub entries
- * in swap cache must be updated first, so a concurrent
- * swap_cache_get_folio() cannot return the head folio for a sub
- * entry (folio_try_get() will fail on the head @folio until unfreeze).
+ * Unfreeze the after-split folios and put them back, keeping @folio
+ * frozen until every sub entry in the swap cache is repointed, so
+ * that a racing swap_cache_get_folio() cannot folio_try_get() the
+ * head. Backward is also the reclaim order: the pieces queue just
+ * before @folio on the LRU, or at the tail of @list, both drained
+ * from the tail.
*/
- for (new_folio = folio_next(folio); new_folio != end_folio;
- new_folio = next) {
- next = folio_next(new_folio);
+ for (new_folio = folio_prev(end_folio); new_folio != folio;
+ new_folio = folio_prev(new_folio)) {
zone_device_private_split_cb(folio, new_folio);
folio_ref_unfreeze(new_folio,
folio_swapcache_ref_count(new_folio) + 1);
--
2.56.1