aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-04-14 14:36:58 -0400
committerTejun Heo <tj@kernel.org>2013-05-14 14:42:07 -0400
commit1a574231669f8c3065c83974e9557fcbbd94b8a6 (patch)
tree1f2f0bc767f0fae3c5e5c28e3274733d4bf0fb07 /kernel/cgroup.c
parent54e7b4eb15fc4354d5ada5469e3db4a220ddb3ed (diff)
cgroup: make hierarchy_id use cyclic idr
We want to be able to lookup a hierarchy from its id and cyclic allocation is a whole lot simpler with idr. Convert to idr and use idr_alloc_cyclc(). Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 3ef677d314bc..dcb417c6c242 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -194,8 +194,7 @@ static int root_count;
194 * rules as other root ops - both cgroup_mutex and cgroup_root_mutex for 194 * rules as other root ops - both cgroup_mutex and cgroup_root_mutex for
195 * writes, either for reads. 195 * writes, either for reads.
196 */ 196 */
197static DEFINE_IDA(hierarchy_ida); 197static DEFINE_IDR(cgroup_hierarchy_idr);
198static int next_hierarchy_id;
199 198
200/* dummytop is a shorthand for the dummy hierarchy's top cgroup */ 199/* dummytop is a shorthand for the dummy hierarchy's top cgroup */
201#define dummytop (&rootnode.top_cgroup) 200#define dummytop (&rootnode.top_cgroup)
@@ -1432,27 +1431,16 @@ static void init_cgroup_root(struct cgroupfs_root *root)
1432 1431
1433static int cgroup_init_root_id(struct cgroupfs_root *root) 1432static int cgroup_init_root_id(struct cgroupfs_root *root)
1434{ 1433{
1435 int ret; 1434 int id;
1436 1435
1437 lockdep_assert_held(&cgroup_mutex); 1436 lockdep_assert_held(&cgroup_mutex);
1438 lockdep_assert_held(&cgroup_root_mutex); 1437 lockdep_assert_held(&cgroup_root_mutex);
1439 1438
1440 do { 1439 id = idr_alloc_cyclic(&cgroup_hierarchy_idr, root, 2, 0, GFP_KERNEL);
1441 if (!ida_pre_get(&hierarchy_ida, GFP_KERNEL)) 1440 if (id < 0)
1442 return -ENOMEM; 1441 return id;
1443 /* Try to allocate the next unused ID */ 1442
1444 ret = ida_get_new_above(&hierarchy_ida, next_hierarchy_id, 1443 root->hierarchy_id = id;
1445 &root->hierarchy_id);
1446 if (ret == -ENOSPC)
1447 /* Try again starting from 0 */
1448 ret = ida_get_new(&hierarchy_ida, &root->hierarchy_id);
1449 if (!ret) {
1450 next_hierarchy_id = root->hierarchy_id + 1;
1451 } else if (ret != -EAGAIN) {
1452 /* Can only get here if the 31-bit IDR is full ... */
1453 BUG_ON(ret);
1454 }
1455 } while (ret);
1456 return 0; 1444 return 0;
1457} 1445}
1458 1446
@@ -1462,7 +1450,7 @@ static void cgroup_exit_root_id(struct cgroupfs_root *root)
1462 lockdep_assert_held(&cgroup_root_mutex); 1450 lockdep_assert_held(&cgroup_root_mutex);
1463 1451
1464 if (root->hierarchy_id) { 1452 if (root->hierarchy_id) {
1465 ida_remove(&hierarchy_ida, root->hierarchy_id); 1453 idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
1466 root->hierarchy_id = 0; 1454 root->hierarchy_id = 0;
1467 } 1455 }
1468} 1456}