[PATCH v2 4/8] mm/migrate: use a dedicated list for hugetlb folios
From: Shivank Garg
Date: Thu Nov 19 2026 - 02:12:57 EST
migrate_hugetlbs() scans the full source list on every retry pass, even
though it only handles hugetlb folios, and migrate_pages() then scans the
list again to set aside hugetlb folios that exhausted their retries.
Move hugetlb folios to a local list in migrate_pages() before migration
and let migrate_hugetlbs() work on that list alone. Whatever was not
migrated is put back through @ret_folios on the way out, which removes the
later hugetlb check from the batching loop.
While at it, fix the function comment which was copied from migrate_pages()
and drop what is migrate_pages()'s contract with outside callers.
No functional change intended.
Signed-off-by: Shivank Garg <shivankg@xxxxxxx>
---
mm/migrate.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index e4e3d1683d1e..3dfdf46681e3 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1662,11 +1662,11 @@ struct migrate_pages_stats {
};
/*
- * Returns the number of hugetlb folios that were not migrated, or an error code
- * after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no hugetlb folios are movable
- * any more because the list has become empty or no retryable hugetlb folios
- * exist any more. It is caller's responsibility to call putback_movable_pages()
- * only if ret != 0.
+ * Migrate the hugetlb folios on @from, trying each folio up to
+ * NR_MAX_MIGRATE_PAGES_RETRY times. Permanent failures are moved to
+ * @ret_folios; any other folio that was not migrated stays on @from.
+ *
+ * Return the number of failed folios, or a negative errno.
*/
static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio,
free_folio_t put_new_folio, unsigned long private,
@@ -1686,9 +1686,6 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio,
nr_retry_pages = 0;
list_for_each_entry_safe(folio, folio2, from, lru) {
- if (!folio_test_hugetlb(folio))
- continue;
-
nr_pages = folio_nr_pages(folio);
cond_resched();
@@ -2184,6 +2181,7 @@ int migrate_pages(struct list_head *from, new_folio_t get_new_folio,
int nr_pages;
struct folio *folio, *folio2;
LIST_HEAD(folios);
+ LIST_HEAD(hugetlb_folios);
LIST_HEAD(ret_folios);
LIST_HEAD(split_folios);
struct migrate_pages_stats stats;
@@ -2192,20 +2190,19 @@ int migrate_pages(struct list_head *from, new_folio_t get_new_folio,
memset(&stats, 0, sizeof(stats));
- rc_gather = migrate_hugetlbs(from, get_new_folio, put_new_folio, private,
- mode, reason, &stats, &ret_folios);
+ list_for_each_entry_safe(folio, folio2, from, lru)
+ if (folio_test_hugetlb(folio))
+ list_move_tail(&folio->lru, &hugetlb_folios);
+
+ rc_gather = migrate_hugetlbs(&hugetlb_folios, get_new_folio,
+ put_new_folio, private, mode, reason,
+ &stats, &ret_folios);
if (rc_gather < 0)
goto out;
again:
nr_pages = 0;
list_for_each_entry_safe(folio, folio2, from, lru) {
- /* Retried hugetlb folios will be kept in list */
- if (folio_test_hugetlb(folio)) {
- list_move_tail(&folio->lru, &ret_folios);
- continue;
- }
-
nr_pages += folio_nr_pages(folio);
if (nr_pages >= NR_MAX_BATCHED_MIGRATION)
break;
@@ -2248,6 +2245,7 @@ int migrate_pages(struct list_head *from, new_folio_t get_new_folio,
* Put the permanent failure folio back to migration list, they
* will be put back to the right list by the caller.
*/
+ list_splice_tail(&hugetlb_folios, &ret_folios);
list_splice(&ret_folios, from);
/*
--
2.53.0