[RFC PATCH v1 4/4] mm: sched: Batch-migrate misplaced pages

From: Bharata B Rao
Date: Mon Jun 16 2025 - 09:46:42 EST


Currently the folios identified as misplaced by the NUMA
balancing sub-system are migrated one by one from the NUMA
hint fault handler as and when they are identified as
misplaced.

Instead of such singe folio migrations, batch them and
migrate them at once. This is achieved by passing on the
information about misplaced folio to kmigrated which will
batch and migrate the folios.

The failed migration count isn't fed back to the scan period
update heuristics currently.

Signed-off-by: Bharata B Rao <bharata@xxxxxxx>
---
mm/memory.c | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 8eba595056fe..b27054f6b4d5 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5903,32 +5903,10 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)
writable, &last_cpupid);
if (target_nid == NUMA_NO_NODE)
goto out_map;
- if (migrate_misplaced_folio_prepare(folio, vma, target_nid)) {
- flags |= TNF_MIGRATE_FAIL;
- goto out_map;
- }
- /* The folio is isolated and isolation code holds a folio reference. */
- pte_unmap_unlock(vmf->pte, vmf->ptl);
+
writable = false;
ignore_writable = true;
-
- /* Migrate to the requested node */
- if (!migrate_misplaced_folio(folio, target_nid)) {
- nid = target_nid;
- flags |= TNF_MIGRATED;
- task_numa_fault(last_cpupid, nid, nr_pages, flags);
- return 0;
- }
-
- flags |= TNF_MIGRATE_FAIL;
- vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd,
- vmf->address, &vmf->ptl);
- if (unlikely(!vmf->pte))
- return 0;
- if (unlikely(!pte_same(ptep_get(vmf->pte), vmf->orig_pte))) {
- pte_unmap_unlock(vmf->pte, vmf->ptl);
- return 0;
- }
+ nid = target_nid;
out_map:
/*
* Make it present again, depending on how arch implements
@@ -5942,8 +5920,10 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)
writable);
pte_unmap_unlock(vmf->pte, vmf->ptl);

- if (nid != NUMA_NO_NODE)
+ if (nid != NUMA_NO_NODE) {
+ kmigrated_add_pfn(folio_pfn(folio), nid);
task_numa_fault(last_cpupid, nid, nr_pages, flags);
+ }
return 0;
}

--
2.34.1