Commit 1a574231 authored by Tejun Heo's avatar Tejun Heo

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: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
parent 54e7b4eb
...@@ -194,8 +194,7 @@ static int root_count; ...@@ -194,8 +194,7 @@ static int root_count;
* rules as other root ops - both cgroup_mutex and cgroup_root_mutex for * rules as other root ops - both cgroup_mutex and cgroup_root_mutex for
* writes, either for reads. * writes, either for reads.
*/ */
static DEFINE_IDA(hierarchy_ida); static DEFINE_IDR(cgroup_hierarchy_idr);
static int next_hierarchy_id;
/* dummytop is a shorthand for the dummy hierarchy's top cgroup */ /* dummytop is a shorthand for the dummy hierarchy's top cgroup */
#define dummytop (&rootnode.top_cgroup) #define dummytop (&rootnode.top_cgroup)
...@@ -1432,27 +1431,16 @@ static void init_cgroup_root(struct cgroupfs_root *root) ...@@ -1432,27 +1431,16 @@ static void init_cgroup_root(struct cgroupfs_root *root)
static int cgroup_init_root_id(struct cgroupfs_root *root) static int cgroup_init_root_id(struct cgroupfs_root *root)
{ {
int ret; int id;
lockdep_assert_held(&cgroup_mutex); lockdep_assert_held(&cgroup_mutex);
lockdep_assert_held(&cgroup_root_mutex); lockdep_assert_held(&cgroup_root_mutex);
do { id = idr_alloc_cyclic(&cgroup_hierarchy_idr, root, 2, 0, GFP_KERNEL);
if (!ida_pre_get(&hierarchy_ida, GFP_KERNEL)) if (id < 0)
return -ENOMEM; return id;
/* Try to allocate the next unused ID */
ret = ida_get_new_above(&hierarchy_ida, next_hierarchy_id, root->hierarchy_id = id;
&root->hierarchy_id);
if (ret == -ENOSPC)
/* Try again starting from 0 */
ret = ida_get_new(&hierarchy_ida, &root->hierarchy_id);
if (!ret) {
next_hierarchy_id = root->hierarchy_id + 1;
} else if (ret != -EAGAIN) {
/* Can only get here if the 31-bit IDR is full ... */
BUG_ON(ret);
}
} while (ret);
return 0; return 0;
} }
...@@ -1462,7 +1450,7 @@ static void cgroup_exit_root_id(struct cgroupfs_root *root) ...@@ -1462,7 +1450,7 @@ static void cgroup_exit_root_id(struct cgroupfs_root *root)
lockdep_assert_held(&cgroup_root_mutex); lockdep_assert_held(&cgroup_root_mutex);
if (root->hierarchy_id) { if (root->hierarchy_id) {
ida_remove(&hierarchy_ida, root->hierarchy_id); idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
root->hierarchy_id = 0; root->hierarchy_id = 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment