Re: [RFC, PATCH 00/12] userfaultfd: working set tracking for VM guest memory

Kiryl Shutsemau
2026-04-14T17:08:56Z

On Tue, Apr 14, 2026 at 11:28:33AM -0400, Peter Xu wrote:
> Hi, Kiryl,
>
> On Tue, Apr 14, 2026 at 03:23:34PM +0100, Kiryl Shutsemau (Meta) wrote:
> > This series adds userfaultfd support for tracking the working set of
> > VM guest memory, enabling VMMs to identify cold pages and evict them
> > to tiered or remote storage.
>
> Thanks for sharing this work, it looks very interesting to me.
>
> Personally I am also looking at some kind of VMM memtiering issues. I'm
> not sure if you saw my lsfmm proposal, it mentioned the challenge we're
> facing, it's slightly different but still a bit relevant:
>
> https://lore.kernel.org/all/aYuad2k75iD9bnBE@x1.local/

Thanks will read up. I didn't follow userfultfd work until recently.

> Unfortunately, that proposal was rejected upstream.

Sorry about that. We can chat about in hall track, if you are there :)

> > == VMM Workflow ==
>
> AFAIU, this workflow provides two functionalities:
>
> >
> > UFFDIO_DEACTIVATE(all) -- async, no vCPU stalls
> > sleep(interval)
> > PAGEMAP_SCAN -- find cold pages
>
> Until here it's only about page hotness tracking. I am curious whether you
> evaluated idle page tracking. Is it because of perf overheads on rmap?

I didn't gave idle page tracking much thought. I needed uffd faults to
serialize reclaim against memory accesses. If use it for one thing we
can as well try to use it for tracking as well. And it seems to be
fitting together nicely with sync/async mode flipping.

> To
> me, your solution (until here.. on the hotness sampling) reads more like a
> more efficient way to do idle page tracking but only per-mm, not per-folio.
>
> That will also be something I would like to benefit if QEMU will decide to
> do full userspace swap. I think that's our last resort, I'll likely start
> with something that makes QEMU work together with Linux on swapping
> (e.g. we're happy to make MGLRU or any reclaim logic that Linux mm
> currently uses, as long as efficient) then QEMU only cares about the rest,
> which is what the migration problem is about.
>
> The other issue about idle page tracking to us is, I believe MGLRU
> currently doesn't work well with it (due to ignoring IDLE bits) where the
> old LRU algo works. I'm not sure how much you evaluated above, so it'll be
> great to share from that perspective too. I also mentioned some of these
> challenges in the lsfmm proposal link above.
>
> > UFFDIO_SET_MODE(sync) -- block faults for eviction
> > pwrite + MADV_DONTNEED cold pages -- safe, faults block
> > UFFDIO_SET_MODE(async) -- resume tracking
>
> These operations are the 2nd function. It's, IMHO, a full userspace swap
> system based on userfaultfd.

Right. And we want to decide where to put cold pages from userspace.

> Have you thought about directly relying on userfaultfd-wp to do this work?
> The relevant question is, why do we need to block guest reads on pages
> being evicted by the userapp? Can we still allow that to happen, which
> seems to be more efficient? IIUC, only writes / updates matters in such
> swap system.

But we do care about about read accesses. We don't want to swap out
pages that got read-touched. And we cannot in practice switch to WP mode
after PAGEMAP_SCAN: it would require a lot of UFFDIO_WRITEPROTECT calls
with TLB flushing each.

With my approach switching tracking and reclaiming is single bit flip
under mmap lock.

> Also, I'm not sure if you're aware of LLNL's umap library:
>
> https://github.com/llnl/umap
>
> That implemnted the swap system using userfaultfd wr-protect mode only, so
> no new kernel API needed.

Will look into it. Thanks.

--
Kiryl Shutsemau / Kirill A. Shutemov