[PATCH RFC 00/12] mm/vmalloc: migrate vmap_area indexing from rb-tree to maple-tree
Uladzislau Rezki
urezki at gmail.com
Thu Jun 18 03:06:06 PDT 2026
On Tue, Jun 16, 2026 at 07:07:57PM +0100, Matthew Wilcox wrote:
> On Mon, Jun 15, 2026 at 11:52:22AM +0200, Uladzislau Rezki wrote:
> > On Sun, Jun 14, 2026 at 12:15:28AM +0100, Matthew Wilcox wrote:
> > > What I don't understand is why you maintain a separate "free" tree.
> > > It should not be necessary any more, but maybe you tried removing it
> > > already and found a performance problem?
> >
> > We maintain it in order to split several entities. That prevents
> > interfering between allocated data and vmap-free-space manager.
> > So in that case one context can easily access allocated data, for
> > example vread iterator, etc., whereas another can do an allocation.
> >
> > So by splitting parts i minimize lock-contention.
>
> Sure, but there are many ways to reduce lock contention. One is to not
> take locks at all; the maple tree is RCU-safe, so you can read the tree
> holding only the RCU read lock, as long as you obey the RCU rules.
>
> Specifically:
> - Write side has to RCU-free the objects that are stored in the tree
> - Read side has to trylock the objects it finds (and retry the walk
> if the trylock fails)
> - Read side can see a mixture of objects if the tree is changed while
> it is reading, but for any given index in the tree it is guaranteed
> to see one of the objects which has been referred to by that index.
> That is, if the write side overwrites an index that referred to
> object A with object B, the reader will see either object A or B.
> It will not see NULL and it will not see any other object.
> - If the write side stores both object C and object D in the tree,
> the read side may see neither, both, only C or only D.
>
Some thoughts about it.
Having the tree which is RCU safe is good for sure. We can benefit from
at least in the: vmallocinfo scanning/dumping, possibly in the vread_iter()
when access to /proc/kcore and other places(which i need to check carefully).
But this is for read-only traversal.
Switching to gap-based approach requires quite a bit of refactoring and it
should be a full switch without any hybrid schemes or mixes. I expect that
we remove more code then adding because of some parts will become hidden
like lookups/reserving range/erase, etc which is good.
- replacing free_vmap_area to maple-tree gap based approach;
- rewriting pcpu-allocator which lives in the end of vmalloc space;
- refactoring per-cpu allocator which is also part of vmalloc space;
- vread iterator;
- vmalloc dump path;
- vmap_node logic(use gap-reserve to minimize contention);
- and more...
To me such rewrite makes sense if we end up in something structural not
just because maple tree exists. The criteria i would go with are: at least
same performance level, remove more then add, the design stays at least in
same good shape.
There are some drawback i am thinking of. One of them is maple insert path,
mas_store_gfp()? First we need to find an empty area, then set-range and do
mas_store_gfp() that uses gfp flag for its internal allocation. If we are
under spin-lock sleeping is not possible, using NOWAIT or ATOMIC is not a
case thus we should somehow pre-allocate outside the lock and store the range
without any allocation.
The allocator operation:
- finds an empty range;
- publishes VA that blocks that range.
those two have to be serialized among other writes. Otherwise two CPUs can use
same empty range and both try to reserve them. If preallocate outside the lock,
the "alloc" side has to validate that a selected range is still empty and only
then store VA to block the range.
I think it is worth to prototype something to see how it would go. I may be
missing something for sure.
Thank you for your input!
--
Uladzislau Rezki
More information about the maple-tree
mailing list