On Mon, Jul 16, 2018 at 10:00:48AM -0700, Dan Williams wrote:
The foreach_order_pgoff() helper takes advantage of the ability to
insert multi-order entries into a radix. It is currently used by
devm_memremap_pages() to minimize the number of entries in the pgmap
radix. Instead of dividing a range by a constant power-of-2 sized unit
and inserting an entry for each unit, it determines the maximum
power-of-2 sized entry (subject to alignment offset) that can be
inserted at each iteration.
Up-level this helper so it can be used for populating other radix
instances. For example asynchronous-memmap-initialization-thread lookups
arriving in a follow on change.
Hopefully by the time you're back, I'll have this code replaced with
the XArray. Here's my proposed API:
old = xa_store_range(xa, first, last, ptr, GFP_KERNEL);
and then you'd simply use xa_for_each() as an iterator. You'd do one
iteration for each range in the XArray, not for each entry occupied.
So there's a difference between:
xa_store(xa, 1, ptr, GFP_KERNEL);
xa_store(xa, 2, ptr, GFP_KERNEL);
xa_store(xa, 3, ptr, GFP_KERNEL);
xa_store_range(xa, 1, 3, ptr, GFP_KERNEL);
index = 0; i = 0;
xa_for_each(xa, p, index, ULONG_MAX, XA_PRESENT)
will return i = 3 for the first case and i = 1 for the second.