diff options
author | Andrew Morton <akpm@osdl.org> | 2004-06-17 17:55:47 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-06-17 17:55:47 -0700 |
commit | 5470e17c27b96d169720cc0a174f974ca027e59d (patch) | |
tree | dcaed513871a48caa0ebd3d72512af1d3f4c5ba7 /lib | |
parent | 90e518e12d2393e2fd818860915dc9d3937cd88f (diff) | |
download | history-5470e17c27b96d169720cc0a174f974ca027e59d.tar.gz |
[PATCH] idr: remove counter bits from id's
idr_get_new() currently returns an incrementing counter in the top 8 bits of
the counter. Which means that most users have to mask it off again, and we
only have a 24-bit range.
So remove that counter. Also:
- Remove the BITS_PER_INT define due to namespace collision risk.
- Make MAX_ID_SHIFT 31, so counters have a 0 to 2G-1 range.
- Why is MAX_ID_SHIFT using sizeof(int) and not sizeof(long)? If it's for
consistency across 32- and 64-bit machines, why not just make it "31"?
- Does this still hold true with the counter removed?
/* We can only use half the bits in the top level because there are
only four possible bits in the top level (5 bits * 4 levels = 25
bits, but you only use 24 bits in the id). */
If not, what needs to change?
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/idr.c | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/lib/idr.c b/lib/idr.c index 4d7963c727ddda..a4c042d7445923 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -27,15 +27,6 @@ * so you don't need to be too concerned about locking and conflicts * with the slab allocator. - * A word on reuse. We reuse empty id slots as soon as we can, always - * using the lowest one available. But we also merge a counter in the - * high bits of the id. The counter is RESERVED_ID_BITS (8 at this time) - * long. This means that if you allocate and release the same id in a - * loop we will reuse an id after about 256 times around the loop. The - * word about is used here as we will NOT return a valid id of -1 so if - * you loop on the largest possible id (and that is 24 bits, wow!) we - * will kick the counter to avoid -1. (Paranoid? You bet!) - * * What you need to do is, since we don't keep the counter as part of * id / ptr pair, to keep a copy of it in the pointed to structure * (or else where) so that when you ask for a ptr you can varify that @@ -78,7 +69,8 @@ * If memory is required, it will return -EAGAIN, you should unlock * and go back to the idr_pre_get() call. If the idr is full, it * will return a -ENOSPC. ptr is the pointer you want associated - * with the id. The value is returned in the "id" field. + * with the id. The value is returned in the "id" field. idr_get_new() + * returns a value in the range 0 ... 0x7fffffff * void *idr_find(struct idr *idp, int id); @@ -271,12 +263,6 @@ build_up: v = sub_alloc(idp, ptr, &id); if (v == -2) goto build_up; - if ( likely(v >= 0 )) { - idp->count++; - v += (idp->count << MAX_ID_SHIFT); - if ( unlikely( v == -1 )) - v += (1L << MAX_ID_SHIFT); - } return(v); } EXPORT_SYMBOL(idr_get_new_above); @@ -334,6 +320,7 @@ static void sub_remove(struct idr *idp, int shift, int id) idp->layers = 0; } } + void idr_remove(struct idr *idp, int id) { struct idr_layer *p; |