From: Jeff Layton <jlayton@redhat.com>
To: Tejun Heo <tj@kernel.org>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/6] idr: introduce idr_alloc_cyclic
Date: Wed, 27 Mar 2013 13:21:41 -0400 [thread overview]
Message-ID: <20130327132141.2dcb2b7b@tlielax.poochiereds.net> (raw)
In-Reply-To: <20130327170135.GD7395@htj.dyndns.org>
On Wed, 27 Mar 2013 10:01:35 -0700
Tejun Heo <tj@kernel.org> wrote:
> Hello,
>
> On Wed, Mar 27, 2013 at 12:48:04PM -0400, Jeff Layton wrote:
> > > > + * Note that people using cyclic allocation to avoid premature reuse of an
> > > > + * already-used ID may be in for a nasty surprise after idr->cur wraps. The
> > > > + * IDR code is designed to avoid unnecessary allocations. If there is space
> > > > + * in an existing layer that holds high IDs then it will return one of those
> > > > + * instead of allocating a new layer at the bottom of the range.
> > >
> > > Ooh, does it? Where?
> > >
> >
> > That's what I gathered from looking at idr_get_empty_slot. I could be
> > wrong here, so please correct me if I am. The IDR internals are really
> > hard to follow...
>
> Amen, it's horrible.
>
> > In any case, it looks like it only tries to allocate a new layer if:
> >
> > idr->top is empty
> >
> > ...or...
> >
> > while (id > idr_max(layers)) {
> > ...
> > }
> >
> > After the wrap, idr->top won't be empty if we have at least one layer
> > still in use. We start with id = starting_id, which after wrap will be
> > much lower than idr_max() at that point (right?).
> >
> > So we'll skip the while loop and fall right into sub_alloc and will
> > quite possibly end up allocating a slot out of the current layer, which
> > is almost certainly not near the bottom of the range.
> >
> > Again, I'm far from sure of my understanding of the internals here, so
> > please do correct me if that's not right...
>
> So, there are two paths which do layer allocation.
> idr_get_empty_slot() does bottom -> top expansion. ie. it grows the
> tree if the current position can't be covered by the current tree.
> Note that the tree can always point to zero. That is, the first slot
> of the top layer always includes zero.
>
> The other part - building tree top -> bottom - happens in sub_alloc()
> which traverses the tree downwards for the current position and
> creates new idr_layer if it doesn't exist.
>
> So, after wrap, the tree is already tall enough so
> idr_get_empty_slot() will just call into sub_alloc() which will build
> the tree downwards. AFAICS, it does guarantee lowest-packing.
>
Ok, that's good to know, and I'll remove the comment for the v2 patch.
I'm glad to be wrong in this case :)
--
Jeff Layton <jlayton@redhat.com>
next prev parent reply other threads:[~2013-03-27 17:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-27 13:18 [PATCH v1 0/6] idr: add idr_alloc_cyclic and convert existing cyclic users Jeff Layton
2013-03-27 13:18 ` [PATCH v1 1/6] idr: introduce idr_alloc_cyclic Jeff Layton
2013-03-27 16:25 ` Tejun Heo
2013-03-27 16:48 ` Jeff Layton
2013-03-27 17:01 ` Tejun Heo
2013-03-27 17:21 ` Jeff Layton [this message]
2013-03-27 13:18 ` [PATCH v1 2/6] amso1100: convert to using idr_alloc_cyclic Jeff Layton
2013-03-27 16:27 ` Tejun Heo
2013-03-27 16:50 ` Jeff Layton
2013-03-27 13:18 ` [PATCH v1 3/6] mlx4: " Jeff Layton
2013-03-27 13:18 ` [PATCH v1 4/6] nfsd: convert nfs4_alloc_stid to use idr_alloc_cyclic Jeff Layton
2013-04-03 19:24 ` J. Bruce Fields
2013-03-27 13:18 ` [PATCH v1 5/6] inotify: convert inotify_add_to_idr " Jeff Layton
2013-03-27 13:18 ` [PATCH v1 6/6] sctp: convert sctp_assoc_set_id " Jeff Layton
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=20130327132141.2dcb2b7b@tlielax.poochiereds.net \
--to=jlayton@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.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