Re: [PATCH v8 5/8] mm: sched: move NUMA balancing tiering promotion to pghot

From: Bharata B Rao

Date: Mon Aug 03 2026 - 04:25:10 EST


[Reply to Shashiko review]

On 28-Jul-26 11:13 AM, Bharata B Rao wrote:
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 2bccb0a53a0a..c36092ebca42 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -41,6 +41,7 @@
> #include <linux/pgalloc.h>
> #include <linux/pgalloc_tag.h>
> #include <linux/pagewalk.h>
> +#include <linux/pghot.h>
>
> #include <asm/tlb.h>
> #include "internal.h"
> @@ -2205,7 +2206,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)
> int nid = NUMA_NO_NODE;
> int target_nid, last_cpupid;
> pmd_t pmd, old_pmd;
> - bool writable = false;
> + bool writable = false, needs_promotion = false;
> int flags = 0;
>
> vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd);
> @@ -2232,11 +2233,29 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)
> goto out_map;
>
> nid = folio_nid(folio);
> + needs_promotion = folio_is_promo_candidate(folio);
>
> target_nid = numa_migrate_check(folio, vmf, haddr, &flags, writable,
> &last_cpupid);
> if (target_nid == NUMA_NO_NODE)
> goto out_map;
> +
> + if (needs_promotion) {
> + /*
> + * Hot page promotion, mode=NUMA_BALANCING_MEMORY_TIERING.
> + *
> + * Isolation and migration are handled by pghot. Since VMA
> + * won't be available to kmigrated which does batched migration
> + * from non-process context, filter shared EXEC pages here itself.
> + */
> + if ((vma->vm_flags & VM_EXEC) && folio_maybe_mapped_shared(folio))
> + nid = NUMA_NO_NODE;
> + else
> + nid = target_nid;
> + goto out_map;
> + }

> Does this drop NUMA fault statistics for shared EXEC pages?
>
> If nid is set to NUMA_NO_NODE here, the out_map path skips task_numa_fault()
> entirely, which seems like it would disrupt scan-period adjustment.

It does drop the call to task_numa_fault() for shared EXEC pages but then
base kernel also has a memory-tiering gate that resulted in shared EXEC pages
not being considered for scan period updates. So this doesn't really drop the
NUMA fault stats for shared exec pages. However I can make it structurally
similar to base so that it is the memory-tiering gate that rejects the
scan period update for shared exec pages.

> Additionally, for non-shared pages, nid is set to target_nid, which might
> prematurely account the fault to the target node before the migration actually
> happens.

Accounting the fault to target node is deliberate here because in pghot the
promotion is delegated to kmigrated. So reporting mem_node=target_nid (top tier)
is what feeds the scan period update in task_numa_fault(). Since pghot does
async migration, it feeds all promo candidates rather than only the successfully
migrated ones like in base.

> diff --git a/mm/memory.c b/mm/memory.c
> index ff338c2abe92..91daba4c2bc9 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -75,6 +75,7 @@
> #include <linux/perf_event.h>
> #include <linux/ptrace.h>
> #include <linux/vmalloc.h>
> +#include <linux/pghot.h>
> #include <linux/sched/sysctl.h>
> #include <linux/pgalloc.h>
> #include <linux/uaccess.h>
> @@ -6029,10 +6030,9 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf,
> if (folio_maybe_mapped_shared(folio) && (vma->vm_flags & VM_SHARED))
> *flags |= TNF_SHARED;
> /*
> - * For memory tiering mode, cpupid of slow memory page is used
> - * to record page access time. So use default value.
> + * For memory tiering mode, last_cpupid is unused. So use default value.
> */
> - if (folio_use_access_time(folio))
> + if (folio_is_promo_candidate(folio))
> *last_cpupid = (-1 & LAST_CPUPID_MASK);
> else
> *last_cpupid = folio_last_cpupid(folio);
> @@ -6113,6 +6113,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)
> int nid = NUMA_NO_NODE;
> bool writable = false, ignore_writable = false;
> bool pte_write_upgrade = vma_wants_manual_pte_write_upgrade(vma);
> + bool needs_promotion = false;
> int last_cpupid;
> int target_nid;
> pte_t pte, old_pte;
> @@ -6147,12 +6148,30 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)
> goto out_map;
>
> nid = folio_nid(folio);
> + needs_promotion = folio_is_promo_candidate(folio);
> nr_pages = folio_nr_pages(folio);
>
> target_nid = numa_migrate_check(folio, vmf, vmf->address, &flags,
> writable, &last_cpupid);
> if (target_nid == NUMA_NO_NODE)
> goto out_map;
> +
> + if (needs_promotion) {
> + /*
> + * Hot page promotion, mode=NUMA_BALANCING_MEMORY_TIERING.
> + *
> + * Isolation and migration are handled by pghot. Since VMA
> + * won't be available to kmigrated which does batched migration
> + * from non-process context, filter shared EXEC pages here itself.
> + */
> + if ((vma->vm_flags & VM_EXEC) && folio_maybe_mapped_shared(folio))
> + nid = NUMA_NO_NODE;
> + else
> + nid = target_nid;
> + goto out_map;
> + }

> Is the same accounting disruption happening here in do_numa_page() as well?
>
> Assigning NUMA_NO_NODE skips task_numa_fault() later in the function, and
> assigning target_nid credits the target node prior to the actual migration.

Reply to this same as above.

The other two comments for this patch actually belong to patch 3/8 and have
been addressed there.

Regards,
Bharata.