Re: [PATCH 2/7] mm/migrate: use migrate_info field instead of private
From: Huang, Ying
Date: Thu May 07 2026 - 05:48:30 EST
Shivank Garg <shivankg@xxxxxxx> writes:
> 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_*
> flags) instead of using folio->private.
>
> No functional change.
>
> Suggested-by: David Hildenbrand <david@xxxxxxxxxx>
> Signed-off-by: Shivank Garg <shivankg@xxxxxxx>
> ---
> 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 a308e2c23b82..f52818dcf4d2 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -426,6 +426,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 0c6a0ab6ecce..03c2a6f7e5e4 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 */
> @@ -1217,7 +1217,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)
LGTM! Feel free to add my
Reviewed-by: Huang Ying <ying.huang@xxxxxxxxxxxxxxxxx>
in the future versions.
---
Best Regards,
Huang, Ying