* [PATCH v2 1/3] mm/migrate: rename page to folio leftovers
2026-07-01 5:17 [PATCH v2 0/3] mm/migrate: preparatory cleanups for batch copy and offload Shivank Garg
@ 2026-07-01 5:17 ` Shivank Garg
2026-07-01 15:39 ` Zi Yan
2026-07-01 23:54 ` SJ Park
2026-07-01 5:17 ` [PATCH v2 2/3] mm/migrate: fix stale list name in migrate_folios_move() comment Shivank Garg
2026-07-01 5:17 ` [PATCH v2 3/3] mm/migrate: use migrate_info field instead of private Shivank Garg
2 siblings, 2 replies; 7+ messages in thread
From: Shivank Garg @ 2026-07-01 5:17 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Zi Yan, Matthew Brost,
Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko
Cc: linux-mm, linux-kernel, Shivank Garg, Dev Jain
Rename migrate_folio_undo_src()'s page_was_mapped parameter to was_mapped,
unmap_and_move_huge_page() to unmap_and_move_hugetlb_folio(), its
page_was_mapped variable to was_mapped and fix stale "page" wording in its
comments.
Also fix migrate_folio() kerneldoc to say "folio" instead of "page".
Suggested-by: Dev Jain <dev.jain@arm.com>
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
mm/migrate.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 49e10feeb094..858350ca58b4 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -884,7 +884,7 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst,
* @mapping: The address_space containing the folio.
* @dst: The folio to migrate the data to.
* @src: The folio containing the current data.
- * @mode: How to migrate the page.
+ * @mode: How to migrate the folio.
*
* Common logic to directly migrate a single LRU folio suitable for
* folios that do not have private data.
@@ -1157,13 +1157,10 @@ static void __migrate_folio_extract(struct folio *dst,
}
/* Restore the source folio to the original state upon failure */
-static void migrate_folio_undo_src(struct folio *src,
- int page_was_mapped,
- struct anon_vma *anon_vma,
- bool locked,
- struct list_head *ret)
+static void migrate_folio_undo_src(struct folio *src, int was_mapped,
+ struct anon_vma *anon_vma, bool locked, struct list_head *ret)
{
- if (page_was_mapped)
+ if (was_mapped)
remove_migration_ptes(src, src, 0);
/* Drop an anon_vma reference if we took one */
if (anon_vma)
@@ -1449,7 +1446,8 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,
}
/*
- * Counterpart of unmap_and_move_page() for hugepage migration.
+ * Counterpart of migrate_folio_unmap() and migrate_folio_move() for hugetlb
+ * folio migration.
*
* This function doesn't wait the completion of hugepage I/O
* because there is no race between I/O and migration for hugepage.
@@ -1466,20 +1464,20 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,
* because then pte is replaced with migration swap entry and direct I/O code
* will wait in the page fault for migration to complete.
*/
-static int unmap_and_move_huge_page(new_folio_t get_new_folio,
+static int unmap_and_move_hugetlb_folio(new_folio_t get_new_folio,
free_folio_t put_new_folio, unsigned long private,
struct folio *src, int force, enum migrate_mode mode,
enum migrate_reason reason, struct list_head *ret)
{
struct folio *dst;
int rc = -EAGAIN;
- int page_was_mapped = 0;
+ int was_mapped = 0;
struct anon_vma *anon_vma = NULL;
struct address_space *mapping = NULL;
enum ttu_flags ttu = 0;
if (folio_ref_count(src) == 1) {
- /* page was freed from under us. So we are done. */
+ /* folio was freed from under us. So we are done. */
folio_putback_hugetlb(src);
return 0;
}
@@ -1501,8 +1499,8 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio,
}
/*
- * Check for pages which are in the process of being freed. Without
- * folio_mapping() set, hugetlbfs specific move page routine will not
+ * Check for folios which are in the process of being freed. Without
+ * folio_mapping() set, hugetlbfs specific move folio routine will not
* be called and we could leak usage counts for subpools.
*/
if (hugetlb_folio_subpool(src) && !folio_mapping(src)) {
@@ -1532,13 +1530,13 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio,
}
try_to_migrate(src, ttu);
- page_was_mapped = 1;
+ was_mapped = 1;
}
if (!folio_mapped(src))
rc = move_to_new_folio(dst, src, mode);
- if (page_was_mapped)
+ if (was_mapped)
remove_migration_ptes(src, !rc ? dst : src, ttu);
if (ttu & TTU_RMAP_LOCKED)
@@ -1663,10 +1661,10 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio,
continue;
}
- rc = unmap_and_move_huge_page(get_new_folio,
- put_new_folio, private,
- folio, pass > 2, mode,
- reason, ret_folios);
+ rc = unmap_and_move_hugetlb_folio(get_new_folio,
+ put_new_folio, private,
+ folio, pass > 2, mode,
+ reason, ret_folios);
/*
* The rules are:
* 0: hugetlb folio will be put back
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 2/3] mm/migrate: fix stale list name in migrate_folios_move() comment
2026-07-01 5:17 [PATCH v2 0/3] mm/migrate: preparatory cleanups for batch copy and offload Shivank Garg
2026-07-01 5:17 ` [PATCH v2 1/3] mm/migrate: rename page to folio leftovers Shivank Garg
@ 2026-07-01 5:17 ` Shivank Garg
2026-07-01 5:17 ` [PATCH v2 3/3] mm/migrate: use migrate_info field instead of private Shivank Garg
2 siblings, 0 replies; 7+ messages in thread
From: Shivank Garg @ 2026-07-01 5:17 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Zi Yan, Matthew Brost,
Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko
Cc: linux-mm, linux-kernel, Shivank Garg
The return-value description in migrate_folios_move() still refers to
unmap_folios, but that list no longer exists. Update this name to
src_folios.
Reviewed-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
mm/migrate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 858350ca58b4..5bc81d61116f 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1739,7 +1739,7 @@ static void migrate_folios_move(struct list_head *src_folios,
/*
* The rules are:
* 0: folio will be freed
- * -EAGAIN: stay on the unmap_folios list
+ * -EAGAIN: stay on the src_folios list
* Other errno: put on ret_folios list
*/
switch (rc) {
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 3/3] mm/migrate: use migrate_info field instead of private
2026-07-01 5:17 [PATCH v2 0/3] mm/migrate: preparatory cleanups for batch copy and offload Shivank Garg
2026-07-01 5:17 ` [PATCH v2 1/3] mm/migrate: rename page to folio leftovers Shivank Garg
2026-07-01 5:17 ` [PATCH v2 2/3] mm/migrate: fix stale list name in migrate_folios_move() comment Shivank Garg
@ 2026-07-01 5:17 ` Shivank Garg
2026-07-02 0:00 ` SJ Park
2 siblings, 1 reply; 7+ messages in thread
From: Shivank Garg @ 2026-07-01 5:17 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Zi Yan, Matthew Brost,
Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko
Cc: linux-mm, linux-kernel, Shivank Garg, Jonathan Cameron
Add an unsigned long migrate_info member to the struct folio union and
use it to store migration state (anon_vma pointer and FOLIO_WAS_*
markers) instead of using folio->private. While at it, switch to bitwise
OR.
No functional change.
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Jonathan Cameron <jic23@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Huang Ying <ying.huang@linux.alibaba.com>
Acked-by: Zi Yan <ziy@nvidia.com>
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
include/linux/mm_types.h | 1 +
mm/migrate.c | 14 +++++++-------
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index b18c2b2e7d2c..ae9bca4eda5c 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -427,6 +427,7 @@ struct folio {
union {
void *private;
swp_entry_t swap;
+ unsigned long migrate_info;
};
atomic_t _mapcount;
atomic_t _refcount;
diff --git a/mm/migrate.c b/mm/migrate.c
index 5bc81d61116f..6fb6f46eea5f 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1130,7 +1130,7 @@ static int move_to_new_folio(struct folio *dst, struct folio *src,
}
/*
- * To record some information during migration, we use unused private
+ * To record some information during migration, we use the migrate_info
* field of struct folio of the newly allocated destination folio.
* This is safe because nobody is using it except us.
*/
@@ -1143,17 +1143,17 @@ enum {
static void __migrate_folio_record(struct folio *dst,
int old_folio_state, struct anon_vma *anon_vma)
{
- dst->private = (void *)anon_vma + old_folio_state;
+ dst->migrate_info = (unsigned long)anon_vma | old_folio_state;
}
static void __migrate_folio_extract(struct folio *dst,
int *old_folio_state, struct anon_vma **anon_vmap)
{
- unsigned long private = (unsigned long)dst->private;
+ unsigned long info = dst->migrate_info;
- *anon_vmap = (struct anon_vma *)(private & ~FOLIO_OLD_STATES);
- *old_folio_state = private & FOLIO_OLD_STATES;
- dst->private = NULL;
+ *anon_vmap = (struct anon_vma *)(info & ~FOLIO_OLD_STATES);
+ *old_folio_state = info & FOLIO_OLD_STATES;
+ dst->migrate_info = 0;
}
/* Restore the source folio to the original state upon failure */
@@ -1214,7 +1214,7 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
return -ENOMEM;
*dstp = dst;
- dst->private = NULL;
+ dst->migrate_info = 0;
if (!folio_trylock(src)) {
if (mode == MIGRATE_ASYNC)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread