From: Shivank Garg <shivankg@amd.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
"Byungchul Park" <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
"Lorenzo Stoakes" <ljs@kernel.org>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
Yiannis Nikolakopoulos <yiannis@zptcorp.com>,
"Bharata B Rao" <bharata@amd.com>,
David Rientjes <rientjes@google.com>,
Huan Nguyen <nhuhuan@google.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Matthew Wilcox" <willy@infradead.org>,
Hugh Dickins <hughd@google.com>,
"Vlastimil Babka" <vbabka@kernel.org>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
Shivank Garg <shivankg@amd.com>
Subject: [PATCH v2 7/8] mm/migrate: fold the LRU batch paths into __migrate_lru_folios()
Date: Thu, 19 Nov 2026 07:12:02 +0000 [thread overview]
Message-ID: <20261119-migrate-refactor-shivank-v2-7-f4535bd0bc52@amd.com> (raw)
In-Reply-To: <20261119-migrate-refactor-shivank-v2-0-f4535bd0bc52@amd.com>
migrate_pages() calls migrate_folios_batch() directly for MIGRATE_ASYNC
and migrate_pages_sync() otherwise, and then retries the folios split
along the way itself.
Turn migrate_pages_sync() into __migrate_lru_folios(), which migrates one
batch of LRU folios in any mode and owns the split folio retry. This
leaves migrate_pages() with a single call per LRU batch.
Keep the existing retry and accounting behavior unchanged.
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
mm/migrate.c | 70 ++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 40 insertions(+), 30 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 1d44c6ce48cd..bad69e1e2ac4 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2200,20 +2200,34 @@ static int migrate_folios_batch(struct list_head *from,
return rc;
}
-static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio,
+/*
+ * Migrate one batch of LRU folios. MIGRATE_ASYNC processes it directly. The
+ * other modes first make a short asynchronous pass, then retry each remaining
+ * folio separately in the requested mode.
+ */
+static int __migrate_lru_folios(struct list_head *from, new_folio_t get_new_folio,
free_folio_t put_new_folio, unsigned long private,
enum migrate_mode mode, enum migrate_reason reason,
- struct list_head *ret_folios, struct list_head *split_folios,
+ struct list_head *ret_folios,
struct migrate_pages_stats *stats)
{
int rc, nr_failed = 0;
LIST_HEAD(folios);
+ LIST_HEAD(split_folios);
struct migrate_pages_stats astats;
+ if (mode == MIGRATE_ASYNC) {
+ rc = migrate_folios_batch(from, get_new_folio, put_new_folio,
+ private, mode, reason, ret_folios,
+ &split_folios, stats,
+ NR_MAX_MIGRATE_PAGES_RETRY);
+ goto out;
+ }
+
memset(&astats, 0, sizeof(astats));
/* Try to migrate in batch with MIGRATE_ASYNC mode firstly */
rc = migrate_folios_batch(from, get_new_folio, put_new_folio, private,
- MIGRATE_ASYNC, reason, &folios, split_folios, &astats,
+ MIGRATE_ASYNC, reason, &folios, &split_folios, &astats,
NR_MAX_MIGRATE_ASYNC_RETRY);
stats->nr_succeeded += astats.nr_succeeded;
stats->nr_thp_succeeded += astats.nr_thp_succeeded;
@@ -2223,7 +2237,7 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio,
stats->nr_failed_pages += astats.nr_failed_pages;
stats->nr_thp_failed += astats.nr_thp_failed;
list_splice_tail(&folios, ret_folios);
- return rc;
+ goto out;
}
stats->nr_thp_failed += astats.nr_thp_split;
/*
@@ -2240,15 +2254,31 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio,
while (!list_empty(from)) {
list_move(from->next, &folios);
rc = migrate_folios_batch(&folios, get_new_folio, put_new_folio,
- private, mode, reason, ret_folios, split_folios,
- stats, NR_MAX_MIGRATE_SYNC_RETRY);
+ private, mode, reason, ret_folios,
+ &split_folios, stats,
+ NR_MAX_MIGRATE_SYNC_RETRY);
list_splice_tail_init(&folios, ret_folios);
if (rc < 0)
- return rc;
+ goto out;
nr_failed += rc;
}
+ rc = nr_failed;
+out:
+ if (rc < 0) {
+ list_splice_tail(&split_folios, ret_folios);
+ } else if (!list_empty(&split_folios)) {
+ /*
+ * Folios split along the way get one asynchronous attempt at
+ * their new order. Their failure is not counted: the large
+ * folio they came from was already counted as one failure.
+ */
+ migrate_folios_batch(&split_folios, get_new_folio, put_new_folio,
+ private, MIGRATE_ASYNC, reason, ret_folios,
+ NULL, stats, 1);
+ list_splice_tail_init(&split_folios, ret_folios);
+ }
- return nr_failed;
+ return rc;
}
/*
@@ -2288,7 +2318,6 @@ int migrate_pages(struct list_head *from, new_folio_t get_new_folio,
LIST_HEAD(hugetlb_folios);
LIST_HEAD(movable_ops_pages);
LIST_HEAD(ret_folios);
- LIST_HEAD(split_folios);
struct migrate_pages_stats stats;
trace_mm_migrate_pages_start(mode, reason);
@@ -2328,32 +2357,13 @@ int migrate_pages(struct list_head *from, new_folio_t get_new_folio,
list_cut_before(&folios, from, &folio2->lru);
else
list_splice_init(from, &folios);
- if (mode == MIGRATE_ASYNC)
- rc = migrate_folios_batch(&folios, get_new_folio, put_new_folio,
- private, mode, reason, &ret_folios,
- &split_folios, &stats,
- NR_MAX_MIGRATE_PAGES_RETRY);
- else
- rc = migrate_pages_sync(&folios, get_new_folio, put_new_folio,
- private, mode, reason, &ret_folios,
- &split_folios, &stats);
+ rc = __migrate_lru_folios(&folios, get_new_folio, put_new_folio,
+ private, mode, reason, &ret_folios, &stats);
list_splice_tail_init(&folios, &ret_folios);
if (rc < 0) {
rc_gather = rc;
- list_splice_tail(&split_folios, &ret_folios);
goto out;
}
- if (!list_empty(&split_folios)) {
- /*
- * Failure isn't counted since all split folios of a large folio
- * is counted as 1 failure already. And, we only try to migrate
- * with minimal effort, force MIGRATE_ASYNC mode and retry once.
- */
- migrate_folios_batch(&split_folios, get_new_folio,
- put_new_folio, private, MIGRATE_ASYNC, reason,
- &ret_folios, NULL, &stats, 1);
- list_splice_tail_init(&split_folios, &ret_folios);
- }
rc_gather += rc;
if (!list_empty(from))
goto again;
--
2.53.0
next prev parent reply other threads:[~2026-11-19 7:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 7:11 [PATCH v2 0/8] mm/migrate: separate hugetlb, movable_ops and LRU migration paths Shivank Garg
2026-11-19 7:11 ` [PATCH v2 1/8] mm/migrate: extract folio unmap phase Shivank Garg
2026-11-19 7:11 ` [PATCH v2 2/8] mm/migrate: handle retries in migrate_folios_move() Shivank Garg
2026-11-19 7:11 ` [PATCH v2 3/8] mm/migrate: factor out folio splitting on allocation failure Shivank Garg
2026-11-19 7:11 ` [PATCH v2 4/8] mm/migrate: use a dedicated list for hugetlb folios Shivank Garg
2026-11-19 7:12 ` [PATCH v2 5/8] mm/migrate: add a dedicated movable_ops migration pass Shivank Garg
2026-11-19 7:12 ` [PATCH v2 6/8] mm/migrate: rename migrate_pages_batch() to migrate_folios_batch() Shivank Garg
2026-11-19 7:12 ` Shivank Garg [this message]
2026-11-19 7:12 ` [PATCH v2 8/8] mm/migrate: add migrate_lru_folios() entry point Shivank Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119-migrate-refactor-shivank-v2-7-f4535bd0bc52@amd.com \
--to=shivankg@amd.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=bharata@amd.com \
--cc=byungchul@sk.com \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=hughd@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=muchun.song@linux.dev \
--cc=nhuhuan@google.com \
--cc=osalvador@suse.de \
--cc=rientjes@google.com \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
--cc=yiannis@zptcorp.com \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®