linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Imre Deak <imre.deak@nokia.com>
To: ext Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Eric Paris <eparis@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] idr: fix backtrack logic in idr_remove_all
Date: Tue, 18 May 2010 14:18:23 +0300	[thread overview]
Message-ID: <20100518111823.GB5261@localhost> (raw)
In-Reply-To: <4BF26AD9.5070601@kernel.org>

On Tue, May 18, 2010 at 12:24:25PM +0200, ext Tejun Heo wrote:
> Hello,
> 
> On 05/12/2010 01:47 PM, imre.deak@nokia.com wrote:
> > The fix changes how we determine the number of levels to step back.
> > Instead of deducting this merely from the msb of the current ID, we
> > should really check if advancing the ID causes an overflow to a bit
> > position corresponding to a given layer. In the above example overflow
> > from bit 0 to bit 1 should mean stepping back 1 level. Overflow from
> > bit 1 to bit 2 should mean stepping back 2 level and so on.
> > 
> > The fix was tested with elements up to 1 << 20, which corresponds to
> > 4 layers on 32 bit systems.
> > 
> > Signed-off-by: Imre Deak <imre.deak@nokia.com>
> > ---
> >  lib/idr.c |    4 +++-
> >  1 files changed, 3 insertions(+), 1 deletions(-)
> > 
> > diff --git a/lib/idr.c b/lib/idr.c
> > index 9042a56..931d9d0 100644
> > --- a/lib/idr.c
> > +++ b/lib/idr.c
> > @@ -445,6 +445,7 @@ EXPORT_SYMBOL(idr_remove);
> >  void idr_remove_all(struct idr *idp)
> >  {
> >  	int n, id, max;
> > +	int bt_mask;
> >  	struct idr_layer *p;
> >  	struct idr_layer *pa[MAX_LEVEL];
> >  	struct idr_layer **paa = &pa[0];
> > @@ -462,8 +463,9 @@ void idr_remove_all(struct idr *idp)
> >  			p = p->ary[(id >> n) & IDR_MASK];
> >  		}
> >  
> > +		bt_mask = id;
> >  		id += 1 << n;
> > -		while (n < fls(id)) {
> > +		while (n < fls(id & ~bt_mask)) {
> 
> Shouldn't this be id ^ bt_mask?  The above only detects 1 -> 0
> transitions not the other way around.

It works according to the following with n=1:

id            id+2            fls((id+2) & ~id)
0             2               2
2             4               3
4             6               2
6             8               4
8             10              2
10            12              3
12            14              2

I think this should work.

> I don't think it will free all the layers in the middle.  Have you counted
> the number of frees match the number of allocations?

Not that, but I checked with kmemleak for 1 << 20 entries. I haven't got
any leaks.

--Imre


  reply	other threads:[~2010-05-18 11:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-12 11:47 [PATCH] idr: fix backtrack logic in idr_remove_all imre.deak
2010-05-18 10:24 ` Tejun Heo
2010-05-18 11:18   ` Imre Deak [this message]
2010-05-18 15:23     ` Tejun Heo
2010-05-18 20:59       ` Imre Deak
2010-05-18 22:23         ` [PATCH v2] " imre.deak

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=20100518111823.GB5261@localhost \
    --to=imre.deak@nokia.com \
    --cc=akpm@linux-foundation.org \
    --cc=eparis@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --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;
as well as URLs for NNTP newsgroup(s).