Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 359385
b: refs/heads/master
c: 5461628
h: refs/heads/master
i:
  359383: 7e24e06
v: v3
  • Loading branch information
Tejun Heo authored and Linus Torvalds committed Feb 28, 2013
1 parent 412ba71 commit ba52d9a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 050a6b47d98e2bcea909c1129111e721668aaa2c
refs/heads/master: 54616283c2948812a44240858ced610e7cacbde1
1 change: 1 addition & 0 deletions trunk/include/linux/idr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define IDR_MASK ((1 << IDR_BITS)-1)

struct idr_layer {
int prefix; /* the ID prefix of this idr_layer */
DECLARE_BITMAP(bitmap, IDR_SIZE); /* A zero bit means "space here" */
struct idr_layer __rcu *ary[1<<IDR_BITS];
int count; /* When zero, we can release it */
Expand Down
13 changes: 13 additions & 0 deletions trunk/lib/idr.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ static int idr_max(int layers)
return (1 << bits) - 1;
}

/*
* Prefix mask for an idr_layer at @layer. For layer 0, the prefix mask is
* all bits except for the lower IDR_BITS. For layer 1, 2 * IDR_BITS, and
* so on.
*/
static int idr_layer_prefix_mask(int layer)
{
return ~idr_max(layer + 1);
}

static struct idr_layer *get_from_free_list(struct idr *idp)
{
struct idr_layer *p;
Expand Down Expand Up @@ -272,6 +282,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa,
if (!new)
return -ENOMEM;
new->layer = l-1;
new->prefix = id & idr_layer_prefix_mask(new->layer);
rcu_assign_pointer(p->ary[m], new);
p->count++;
}
Expand Down Expand Up @@ -313,6 +324,7 @@ static int idr_get_empty_slot(struct idr *idp, int starting_id,
* upwards.
*/
p->layer++;
WARN_ON_ONCE(p->prefix);
continue;
}
if (!(new = idr_layer_alloc(gfp_mask, layer_idr))) {
Expand All @@ -334,6 +346,7 @@ static int idr_get_empty_slot(struct idr *idp, int starting_id,
new->ary[0] = p;
new->count = 1;
new->layer = layers-1;
new->prefix = id & idr_layer_prefix_mask(new->layer);
if (bitmap_full(p->bitmap, IDR_SIZE))
__set_bit(0, new->bitmap);
p = new;
Expand Down

0 comments on commit ba52d9a

Please sign in to comment.