From: Matthew Wilcox <willy@infradead.org>
To: kbusch@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@fb.com
Subject: Re: [PATCH 1/2] mm/dmapool: replace linked list with xarray
Date: Thu, 28 Apr 2022 22:59:49 +0100 [thread overview]
Message-ID: <YmsOVVfcycVdbzUs@casper.infradead.org> (raw)
In-Reply-To: <20220428202714.17630-2-kbusch@kernel.org>
On Thu, Apr 28, 2022 at 02:27:13PM -0600, kbusch@kernel.org wrote:
> Store the cached dma pool pages in an xarray instead of a linked list.
> This allows constant lookup time to free the page, lockless iteration
> while displaying the attributes, and frees up space in 'struct dma_page'.
Hey Keith, this looks great, especially since there's more performance
you can squeeze out of it.
> struct dma_pool { /* the pool */
> - struct list_head page_list;
> + struct xarray pages;
> spinlock_t lock;
A further optimisation you could make is to use the xa_lock to protect
the rest of the data structure. But that would be a subsequent patch.
> @@ -282,7 +281,8 @@ void dma_pool_destroy(struct dma_pool *pool)
> device_remove_file(pool->dev, &dev_attr_pools);
> mutex_unlock(&pools_reg_lock);
>
> - list_for_each_entry_safe(page, tmp, &pool->page_list, page_list) {
> + xa_for_each(&pool->pages, i, page) {
> + xa_erase(&pool->pages, i);
> if (is_page_busy(page)) {
> if (pool->dev)
> dev_err(pool->dev, "%s %s, %p busy\n", __func__,
> @@ -291,12 +291,12 @@ void dma_pool_destroy(struct dma_pool *pool)
> pr_err("%s %s, %p busy\n", __func__,
> pool->name, page->vaddr);
> /* leak the still-in-use consistent memory */
> - list_del(&page->page_list);
> kfree(page);
> } else
> pool_free_page(pool, page);
> }
>
> + xa_destroy(&pool->pages);
If you're erasing the entries as you go, you don't need to call
xa_destroy(). Contrariwise, if you call xa_destroy(), you don't need to
call xa_erase(). I'd probably just call xa_destroy() at the end as it's
less work.
> @@ -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.
> + xa_store(&pool->pages, page->vaddr, page, mem_flags);
Oof. The XArray isn't good at such sparse allocations. You can improve
it (by a significant amount) by shifting the vaddr by PAGE_SHIFT bits.
Should save you two nodes of tree height and thus two cache lines per
lookup.
next prev parent reply other threads:[~2022-04-28 22:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 20:27 [PATCH 0/2] dmapool performance enhancements kbusch
2022-04-28 20:27 ` [PATCH 1/2] mm/dmapool: replace linked list with xarray kbusch
2022-04-28 21:59 ` Matthew Wilcox [this message]
2022-04-29 1:41 ` Keith Busch
2022-04-28 20:27 ` [PATCH 2/2] mm/dmapool: link blocks across pages kbusch
2022-05-27 19:35 ` [PATCH 0/2] dmapool performance enhancements Tony Battersby
2022-05-27 21:01 ` Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YmsOVVfcycVdbzUs@casper.infradead.org \
--to=willy@infradead.org \
--cc=kbusch@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox