On 2026-11-17 14:51 +1100, Alistair Popple wrote:
> On 2026-11-17 at 10:57 +1100, "Gregory Price (Meta)" <[email protected]>
> wrote...
> >
> > Ah, I follow. I'm still working through the performance implications of
> > mmu_notifiers in the presence of PROT_NONE faults, but if i'm
> > understanding correctly it tracks that you'd say it's incompatible.
>
> Incompatible is probably not the correct term as it still works. It's just
> that
> GPU faults are really expensive, and to be avoided at all costs. So having
> NUMA
> balancing running around randomly unmapping pages the GPU is using (regardless
> of whether or not they are on the device) results in more GPU faults and
> therefore a huge perf impact for basically no (or in fact sometimes negative)
> gain.
>
> > I presume here the driver needs a global view of memory (or at least all
> > memory it can potentially DMA), rather than simply just a subset
> > (some set of VMAs)?
>
> The basic process is this:
>
> * GPU needs to access some user space virtual address (eg. allocated with
> mmap/malloc)
> * Therefore GPU driver needs to setup GPU page tables to point to the physical
> memory[1] backing the user space virtual address
> * To find the physical address the GPU driver uses hmm_range_fault() on the
> range, possibly faulting pages in if required (ie. if CPU PTE permissions
> don't match what's required).
> * hmm_range_fault() relies on mmu_notifiers for synchronisation with CPU PTE
> state.
> * An mmu_notifier firing causes a driver to do two things:
> a) Must invalidate any GPU page tables / TLBs mapping the notified virtual
> address.
> b) Increments a sequence number for any concurrent hmm_range_faults(),
> which must
> retry as their view of CPU PTEs is now out-dated. This is the problem
> this patch series hits - the migration on fault causes an mmu_notifier
> to fire
> resulting in a hmm_range_fault() retry and associated overhead.
>
> So the driver doesn't need a global view of memory, just a view of the memory
> the GPU needs, or likely needs, to access. Determining that depends on the
> driver - some might require pre-registration of the ranges (eg. via an ioctl)
> prior to launching work whilst others might wait until the GPU work faults on
> an
> address not in the GPU page tables. Or some combination thereof.
>
I feel like i'm missing something here.
Why can't this be solved by just setting MPOL_LOCAL (or any bind policy)
without MPOL_F_NUMA_BALANCING on the VMA to prevent the VMA from being
NUMA scanned in the first place?
mpol_misplaced() already checks whether it should migrate with the
MPOL_F_MOF flag:
pol = get_vma_policy(vma, addr, folio_order(folio), &ilx);
if (!(pol->flags & MPOL_F_MOF))
goto out;
and task_numa_work never scans VMA's without MOF:
for (; vma; vma = vma_next(&vmi)) {
if (!vma_migratable(vma) || !vma_policy_mof(vma) ... )
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_UNSUITABLE);
continue;
}
...
}
So any stray (already scanned) pages at least won't migrate, and
NUMA balancing skips re-arming for VMAs that don't set MPOL_F_MOF.
You'd only have to worry about a user setting a mempolicy after
it becomes hmm tracked - and i think we could work around that
by locking a VMA policy in place.
Gets a little tricky for pagecache i suppose, but the plumbing
exists to handle this.
Anyway, MOF gets set is if you inherit the default policy:
void __init numa_policy_init(void)
{
...
for_each_node(nid) {
preferred_node_policy[nid] = (struct mempolicy) {
.refcnt = ATOMIC_INIT(1),
.mode = MPOL_PREFERRED,
.flags = MPOL_F_MOF | MPOL_F_MORON,
.nodes = nodemask_of_node(nid),
};
}
...
}
or you set MPOL_F_NUMA_BALANCING on the policy:
static inline int sanitize_mpol_flags(int *mode, unsigned short *flags)
{
...
if (*flags & MPOL_F_NUMA_BALANCING) {
if (*mode == MPOL_BIND || *mode == MPOL_PREFERRED_MANY)
*flags |= (MPOL_F_MOF | MPOL_F_MORON);
else
return -EINVAL;
}
...
}
If the memory is tmpfs/shmem, you can even set a default mempolicy at
mount time that does not set numa balancing. If we need that for
another filesystem, it can be added trivially.
If there's a need for a driver or hmm to update a VMA mempolicy as part
of the hmm runtime process so userland doesn't have to know about it
under the hood - i think we could do that too.
Am I missing something? Seems we can just rid hmm-tracked regions of
NUMA Balancing PROT_NONE faults entirely instead of ignoring them.
~Gregory
--
~Gregory