Re: [RFC PATCH v5 02/10] migrate: Add migrate_misplaced_folios_batch()

From: Joshua Hahn

Date: Thu Feb 26 2026 - 15:43:31 EST


On Thu, 29 Jan 2026 20:10:35 +0530 Bharata B Rao <bharata@xxxxxxx> wrote:

> From: Gregory Price <gourry@xxxxxxxxxx>
>
> Tiered memory systems often require migrating multiple folios at once.
> Currently, migrate_misplaced_folio() handles only one folio per call,
> which is inefficient for batch operations. This patch introduces
> migrate_misplaced_folios_batch(), a batch variant that leverages
> migrate_pages() internally for improved performance.
>
> The caller must isolate folios beforehand using
> migrate_misplaced_folio_prepare(). On return, the folio list will be
> empty regardless of success or failure.
>
> This function will be used by pghot kmigrated thread.
>
> Signed-off-by: Gregory Price <gourry@xxxxxxxxxx>
> [Rewrote commit description]
> Signed-off-by: Bharata B Rao <bharata@xxxxxxx>
> ---

[...snip...]

> + if (nr_remaining)
> + putback_movable_pages(folio_list);

Hello Bharata, I hope you are doing well! Thank you for the series.
I saw the numbers and they look great. I'm hoping to do some more testing
myself as well : -) I'm also going through the series as well!!

> + if (nr_succeeded) {

The single-folio case, migrate_misplaced_folio, has a guard here to
check that the function performs more than just a migration, but a promotion.
Specifically, it checks that the folio's node is not toptier, and the
destination node is toptier. Should that also be included here?

When this is called in kmigrated_walk_zone in the next patch, there is no
check to make sure that the folios are actually on a lower tier, and the
destination is on a higher tier. Maybe I'm missing something? But it
wasn't entirely obvious to me that the migration is always a promotion.

I want to note that we're also skipping the count_memcg_events, which
I understand is much harder to do here becuase each folio might belong
to a different memcg. Ying also noted this in his reply from v1 [1]
but I don't think it ever got addressed.

Anyways, thank you! I hope you have a great day!
Joshua

> + count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
> + mod_node_page_state(pgdat, PGPROMOTE_SUCCESS, nr_succeeded);
> + }
> + WARN_ON(!list_empty(folio_list));
> + return nr_remaining ? -EAGAIN : 0;
> +}
> #endif /* CONFIG_NUMA_BALANCING */
> #endif /* CONFIG_NUMA */
> --
> 2.34.1
>

[1] https://lore.kernel.org/linux-mm/87a541e51s.fsf@DESKTOP-5N7EMDA/