From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Tony Battersby <tonyb@cybernetics.com>
Cc: Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Matthew Wilcox <willy@infradead.org>,
Sathya Prakash <sathya.prakash@broadcom.com>,
Chaitra P B <chaitra.basappa@broadcom.com>,
Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>,
iommu@lists.linux-foundation.org, linux-mm <linux-mm@kvack.org>,
linux-scsi <linux-scsi@vger.kernel.org>,
MPT-FusionLinux.pdl@broadcom.com
Subject: Re: [PATCH 1/3] dmapool: improve scalability of dma_pool_alloc
Date: Thu, 26 Jul 2018 22:37:15 +0300 [thread overview]
Message-ID: <CAHp75VcXVgAtUWY5yRBFg85C5NPN2BAFyAfAkPLkKq5+SsNHpg@mail.gmail.com> (raw)
In-Reply-To: <15ff502d-d840-1003-6c45-bc17f0d81262@cybernetics.com>
On Thu, Jul 26, 2018 at 9:54 PM, Tony Battersby <tonyb@cybernetics.com> wrote:
> dma_pool_alloc() scales poorly when allocating a large number of pages
> because it does a linear scan of all previously-allocated pages before
> allocating a new one. Improve its scalability by maintaining a separate
> list of pages that have free blocks ready to (re)allocate. In big O
> notation, this improves the algorithm from O(n^2) to O(n).
> spin_lock_irqsave(&pool->lock, flags);
> - list_for_each_entry(page, &pool->page_list, page_list) {
> - if (page->offset < pool->allocation)
> - goto ready;
> + if (!list_empty(&pool->avail_page_list)) {
> + page = list_first_entry(&pool->avail_page_list,
> + struct dma_page,
> + avail_page_link);
> + goto ready;
> }
It looks like
page = list_first_entry_or_null();
if (page)
goto ready;
Though I don't know which one produces better code in the result.
>From reader prospective of view I would go with my variant.
> + /* This test checks if the page is already in avail_page_list. */
> + if (list_empty(&page->avail_page_link))
> + list_add(&page->avail_page_link, &pool->avail_page_list);
How can you be sure that the page you are testing for is the first one?
It seems you are relying on the fact that in the list should be either
0 or 1 page. In that case what's the point to have a list?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2018-07-26 19:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-26 18:54 Tony Battersby
2018-07-26 19:37 ` Andy Shevchenko [this message]
2018-07-26 19:56 ` Tony Battersby
2018-07-27 13:50 ` Tony Battersby
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=CAHp75VcXVgAtUWY5yRBFg85C5NPN2BAFyAfAkPLkKq5+SsNHpg@mail.gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=MPT-FusionLinux.pdl@broadcom.com \
--cc=chaitra.basappa@broadcom.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=linux-scsi@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=sathya.prakash@broadcom.com \
--cc=suganath-prabu.subramani@broadcom.com \
--cc=tonyb@cybernetics.com \
--cc=willy@infradead.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