linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	linux-kernel@vger.kernel.org, tglx@linutronix.de,
	Nicholas Bellinger <nab@linux-iscsi.org>,
	Shaohua Li <shli@fb.com>,
	Kent Overstreet <kent.overstreet@gmail.com>
Subject: Re: [PATCH] percpu_ida: Use _irqsave() instead of local_irq_save() + spin_lock
Date: Sat, 5 May 2018 08:52:02 -0700	[thread overview]
Message-ID: <20180505155202.GA29992@bombadil.infradead.org> (raw)
In-Reply-To: <60a88d5f-95eb-ba45-e59c-5a822a3d370b@kernel.dk>

On Sat, May 05, 2018 at 08:10:20AM -0600, Jens Axboe wrote:
> On 5/4/18 9:51 PM, Matthew Wilcox wrote:
> > On Fri, May 04, 2018 at 04:22:16PM -0700, Andrew Morton wrote:
> >> I'm feeling a bit hostile toward lib/percpu_ida.c in general ;) It has
> >> very few users and seems rather complicated (what's with that
> >> schedule() in percpu_ida_alloc?).  I'm suspecting and hoping that if
> >> someone can figure out what the requirements were, this could all be
> >> zapped and reimplemented using something else which we already have.
> > 
> > Note that I have no code in percpu_ida ... it's quite different from
> > the regular IDA.  But I have noticed the stunning similarity between the
> > percpu_ida and the code in lib/sbitmap.c.  I have no idea which one is
> > better, but they're essentially doing the same thing.
> 
> Not sure where you see that "stunning similarity"? The sbitmap code is
> basically the blk-mq tagging sparse bitmaps, abstracted into a generally
> usable form. The percpu_ida design works fine for lower utilization, but
> it fell apart for the tagging use case where we can easily run at full
> utilization. percpu_ida has percpu caches, sbitmap gets away with just
> percpu hints. These caches are why it doesn't work well for > 50%
> utilization. sbitmap also supports shallow operations, and online
> resizing. Outside of the sharing the same basic functionality of "give
> me some free ID", I really don't see a lot of similarities. In terms of
> functionality, yes, I don't think it would be hard to get rid of
> percpu_ida and just replace it with sbitmap. Probably a worthwhile
> pursuit.

Yes, I meant stunning similarity in terms of functionality, rather than
implementation.  I didn't intend to imply that you'd filed off the serial
numbers, given it a fresh coat of paint and called it yours ;-)

I've been looking into what it'll take to replace percpu_ida with sbitmap.
The good news is that there's large chunks of the percpu_ida API that
aren't being used, and the better news is that there's actually only
one percpu_ida, although it gets used by a lot of target drivers.

Looking at the functions in the header file ...

percpu_ida_alloc - seven drivers, all sess_tag_pool
percpu_ida_free - seven drivers, all sess_tag_pool
percpu_ida_destroy - target_core_transport.c (sess_tag_pool)
percpu_ida_init - target_core_transport.c (sess_tag_pool)
percpu_ida_for_each_free - unused
percpu_ida_free_tags - unused

percpu_ida_alloc uses 'state' in a little bit of an unusual way.  It seems
to me that TASK_RUNNING means "Do not sleep", and any other value means
"sleep in this TASK_ state".  As I understand the sbitmap code, that
means we want an sbitmap_queue.

init and destroy seem to map to sbitmap_queue_init_node and
sbitmap_queue_free.  percpu_ida_free maps to sbitmap_queue_clear.
percpu_ida_alloc(x, TASK_RUNNING) maps to sbitmap_queue_get, and any
other state is going to involve the kind of code we see in blk_mq_get_tag.

Does all of that make sense, or have I missed something?

And, Kent, do you see any reason to keep percpu_ida around?  Is there
an important way in which it's superior to sbitmap?

  parent reply	other threads:[~2018-05-05 15:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-04 15:32 [PATCH] percpu_ida: Use _irqsave() instead of local_irq_save() + spin_lock Sebastian Andrzej Siewior
2018-05-04 23:22 ` Andrew Morton
2018-05-05  3:51   ` Matthew Wilcox
2018-05-05 14:10     ` Jens Axboe
2018-05-05 14:42       ` Jens Axboe
2018-05-05 15:52       ` Matthew Wilcox [this message]
2018-05-07 13:47         ` Matthew Wilcox
2018-05-07 21:34           ` Jens Axboe

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=20180505155202.GA29992@bombadil.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bigeasy@linutronix.de \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=shli@fb.com \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).