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 3/8] mm/migrate: factor out folio splitting on allocation failure
Date: Thu, 19 Nov 2026 07:11:58 +0000 [thread overview]
Message-ID: <20261119-migrate-refactor-shivank-v2-3-f4535bd0bc52@amd.com> (raw)
In-Reply-To: <20261119-migrate-refactor-shivank-v2-0-f4535bd0bc52@amd.com>
If destination folio allocation fails, migrate_folios_unmap() may split
a large folio and retry migration with smaller folios. Factor this logic
out into migrate_folio_split_on_alloc_fail() to simplify the allocation
failure path.
No functional change intended.
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
mm/migrate.c | 69 +++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 26 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 1f4ddd23cea1..e4e3d1683d1e 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1847,6 +1847,34 @@ static void migrate_folios_undo(struct list_head *src_folios,
}
}
+static int migrate_folio_split_on_alloc_fail(struct folio *folio,
+ struct list_head *split_folios, enum migrate_mode mode,
+ enum migrate_reason reason, struct migrate_pages_stats *stats)
+{
+ bool is_thp = folio_test_pmd_mappable(folio);
+ int rc;
+
+ /* Large folio NUMA faulting doesn't split to retry. */
+ if (!folio_test_large(folio) || reason == MR_NUMA_MISPLACED)
+ return -ENOMEM;
+
+ rc = try_split_folio(folio, split_folios, mode);
+ if (!rc) {
+ stats->nr_thp_split += is_thp;
+ stats->nr_split++;
+ return 0;
+ }
+
+ /*
+ * Try again to split large folio to mitigate the failure of longterm
+ * pinning.
+ */
+ if (reason == MR_LONGTERM_PIN && rc == -EAGAIN)
+ return -EAGAIN;
+
+ return -ENOMEM;
+}
+
/*
* Unmap the folios in @from, queuing successfully unmapped sources on
* @unmap_folios and their destinations on @dst_folios. Increment @nr_failed
@@ -1868,10 +1896,8 @@ static int migrate_folios_unmap(struct list_head *from,
int nr_retry_pages = 0;
int pass = 0;
bool is_thp = false;
- bool is_large = false;
struct folio *folio, *folio2, *dst = NULL;
- int rc, nr_pages;
- bool nosplit = (reason == MR_NUMA_MISPLACED);
+ int rc, split_rc, nr_pages;
for (pass = 0; pass < nr_pass && retry; pass++) {
retry = 0;
@@ -1879,7 +1905,6 @@ static int migrate_folios_unmap(struct list_head *from,
nr_retry_pages = 0;
list_for_each_entry_safe(folio, folio2, from, lru) {
- is_large = folio_test_large(folio);
is_thp = folio_test_pmd_mappable(folio);
nr_pages = folio_nr_pages(folio);
@@ -1976,28 +2001,20 @@ static int migrate_folios_unmap(struct list_head *from,
*/
*nr_failed += 1;
stats->nr_thp_failed += is_thp;
- /* Large folio NUMA faulting doesn't split to retry. */
- if (is_large && !nosplit) {
- int ret = try_split_folio(folio, split_folios, mode);
-
- if (!ret) {
- stats->nr_thp_split += is_thp;
- stats->nr_split++;
- break;
- } else if (reason == MR_LONGTERM_PIN &&
- ret == -EAGAIN) {
- /*
- * Try again to split large folio to
- * mitigate the failure of longterm pinning.
- */
- retry++;
- thp_retry += is_thp;
- nr_retry_pages += nr_pages;
- /* Undo duplicated failure counting. */
- *nr_failed -= 1;
- stats->nr_thp_failed -= is_thp;
- break;
- }
+
+ split_rc = migrate_folio_split_on_alloc_fail(folio,
+ split_folios, mode, reason, stats);
+ if (!split_rc)
+ break;
+ /* Retry this folio in a later pass. */
+ if (split_rc == -EAGAIN) {
+ retry++;
+ thp_retry += is_thp;
+ nr_retry_pages += nr_pages;
+ /* Undo duplicated failure counting. */
+ *nr_failed -= 1;
+ stats->nr_thp_failed -= is_thp;
+ break;
}
stats->nr_failed_pages += nr_pages + nr_retry_pages;
--
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 ` Shivank Garg [this message]
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 ` [PATCH v2 7/8] mm/migrate: fold the LRU batch paths into __migrate_lru_folios() Shivank Garg
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-3-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®