On Wed, Jul 22, 2026 at 06:29:53PM +1000, Balbir Singh wrote:
> On 7/22/26 4:16 AM, Gregory Price wrote:
> >
> > User-numa
> >
> > Some devices don't want the user to have control over placement.
> > I have been working on compressed memory, for example, which only
> > ever wants to be used as a reclaim-demotion target.
> >
> > (The reasoning for this is another thread, i plan on publishing
> > my research on this this year)
> >
>
> I don't fully understand, how do we allocate memory on these devices then? Is
> the driver expected to allocate and map via vm_insert_page()?
>
It depends on your use case, but yes that's one possibility.
In another use case, you could enable (CAP_RECLAIM | CAP_DEMOTION) and
pages are allocated via alloc_demotion_target() in the reclaim path.
For general "device hosted memory", you can do a variety of things:
Direct alloc
ioctl(...) -> explicit alloc call
mmap(/dev/my_device) + mm_fault handler
Or a kernel-internal mempolicy
ioctl(...) -> set kernel-internal mempolicy on a vma
mmap(/dev/my_device) + kernel-internal only mempolicy on the vma
The KVM guest_memfd patch included at the end of the series uses the
kernel-internal mempolicy mechanism:
https://lore.kernel.org/linux-mm/al-pkvmgIxGu3LzM@gourry-fedora-PF4VCD3F/T/#me04a7e3556677babd82bfe3947b1a83b7f0017e1
This pattern is needed because the memory is never mapped into userland,
so userland actually *can't* set a mempolicy on this memory itself.
and then of course: CAP_USER_NUMA + mbind/set_mempolicy directly
This is kind of the point - the source of the memory has some control
over how it can be used.
> > Hot-unplug:
> >
> > Some devices can't necessarily handle unexpected migration, and
> > hot-unplug is fundamentally a migration. So the HOTUNPLUG cap
> > actually means "hot-unplug can execute migrations".
> >
> > If the entire device has pre-drained the memory (all memory is free)
> > then unplug works - it's just not very hot (no migrations) :]
> >
> > Maybe a naming issue?
> >
>
> Yes, I would prefer MIGRATION in the name, HOTUNPLUG made me wonder how these
> devices come online and because it is a device, it can go offline while the
> system is still online
>
There's a difference between device hotplug and memory hotplug. The
kernel's memory hotunplug system can at best be described as "best
effort", and if hotplugged as ZONE_NORMAL (on a non-private node) you're
unlikely to ever be able to hotunplug.
It's possible that this CAP bit should just go away and if the device
doesn't want its memory to be run migratable then it needs to hold extra
references on the folios. That's probably reasonable and looks a lot
like a long term pin.
(note: I have to respin for Sashiko fixes, i'm likely going to drop most
of the CAP bits except USER_NUMA in v6 and have them come in with
specific use cases).
~Gregory