aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-27 20:05:07 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:20 -0500
commit54616283c2948812a44240858ced610e7cacbde1 (patch)
tree268bbe9049d9370d5b644dfde51fc4a8942bae3b /lib
parent050a6b47d98e2bcea909c1129111e721668aaa2c (diff)
idr: add idr_layer->prefix
Add a field which carries the prefix of ID the idr_layer covers. This will be used to implement lookup hint. This patch doesn't make use of the new field and doesn't introduce any behavior difference. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/idr.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/idr.c b/lib/idr.c
index d66e75bfc1a0..5cd602936645 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -60,6 +60,16 @@ static int idr_max(int layers)
60 return (1 << bits) - 1; 60 return (1 << bits) - 1;
61} 61}
62 62
63/*
64 * Prefix mask for an idr_layer at @layer. For layer 0, the prefix mask is
65 * all bits except for the lower IDR_BITS. For layer 1, 2 * IDR_BITS, and
66 * so on.
67 */
68static int idr_layer_prefix_mask(int layer)
69{
70 return ~idr_max(layer + 1);
71}
72
63static struct idr_layer *get_from_free_list(struct idr *idp) 73static struct idr_layer *get_from_free_list(struct idr *idp)
64{ 74{
65 struct idr_layer *p; 75 struct idr_layer *p;
@@ -272,6 +282,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa,
272 if (!new) 282 if (!new)
273 return -ENOMEM; 283 return -ENOMEM;
274 new->layer = l-1; 284 new->layer = l-1;
285 new->prefix = id & idr_layer_prefix_mask(new->layer);
275 rcu_assign_pointer(p->ary[m], new); 286 rcu_assign_pointer(p->ary[m], new);
276 p->count++; 287 p->count++;
277 } 288 }
@@ -313,6 +324,7 @@ build_up:
313 * upwards. 324 * upwards.
314 */ 325 */
315 p->layer++; 326 p->layer++;
327 WARN_ON_ONCE(p->prefix);
316 continue; 328 continue;
317 } 329 }
318 if (!(new = idr_layer_alloc(gfp_mask, layer_idr))) { 330 if (!(new = idr_layer_alloc(gfp_mask, layer_idr))) {
@@ -334,6 +346,7 @@ build_up:
334 new->ary[0] = p; 346 new->ary[0] = p;
335 new->count = 1; 347 new->count = 1;
336 new->layer = layers-1; 348 new->layer = layers-1;
349 new->prefix = id & idr_layer_prefix_mask(new->layer);
337 if (bitmap_full(p->bitmap, IDR_SIZE)) 350 if (bitmap_full(p->bitmap, IDR_SIZE))
338 __set_bit(0, new->bitmap); 351 __set_bit(0, new->bitmap);
339 p = new; 352 p = new;