Re: [PATCH 1/2] mm/dmapool: replace linked list with xarray

From: Keith Busch
Date: Thu Apr 28 2022 - 21:41:12 EST


On Thu, Apr 28, 2022 at 10:59:49PM +0100, Matthew Wilcox wrote:
> On Thu, Apr 28, 2022 at 02:27:13PM -0600, kbusch@xxxxxxxxxx wrote:
> > @@ -316,13 +316,14 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
> > {
> > unsigned long flags;
> > struct dma_page *page;
> > + unsigned long i;
> > size_t offset;
> > void *retval;
> >
> > might_alloc(mem_flags);
> >
> > spin_lock_irqsave(&pool->lock, flags);
> > - list_for_each_entry(page, &pool->page_list, page_list) {
> > + xa_for_each(&pool->pages, i, page) {
> > if (page->offset < pool->allocation)
> > goto ready;
> > }
>
> A further optimisation you could do is use xarray search marks to
> search for only pages which have free entries.

That's an interesting idea. I didn't consider setting marks since patch 2
replaces this search with essentially a stack pop. If a marked entry can be
returned in a similar time, though, I could drop patch 2. I can't tell from the
xarray code if that operation time is in the same ballpark, though, so I'll
just rerun the the benchmark. :)