summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-04-14 11:36:58 -0700
committerMaciej Wereski <m.wereski@partner.samsung.com>2014-12-29 09:31:37 +0100
commit4912bfd6d1e13b32f9c9efa43ff6dfcb59618c58 (patch)
treea02307f98c4fafa47d2390dfeed2bc3e68458892
parent6e39060d794da7636c7aef0398d7f5a3ad76f444 (diff)
downloadlinux-3.10-4912bfd6d1e13b32f9c9efa43ff6dfcb59618c58.tar.gz
linux-3.10-4912bfd6d1e13b32f9c9efa43ff6dfcb59618c58.tar.bz2
linux-3.10-4912bfd6d1e13b32f9c9efa43ff6dfcb59618c58.zip
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> Change-Id: Ibd20ebe71ddb452178302cf86a22572b18cd82df Origin: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=1a574231669f8c3065c83974e9557fcbbd94b8a6 Backported-by: Maciej Wereski <m.wereski@partner.samsung.com> Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
-rw-r--r--kernel/cgroup.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 62f95510950..d9acb5236d5 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -202,8 +202,7 @@ static int root_count;
* rules as other root ops - both cgroup_mutex and cgroup_root_mutex for
* writes, either for reads.
*/
-static DEFINE_IDA(hierarchy_ida);
-static int next_hierarchy_id;
+static DEFINE_IDR(cgroup_hierarchy_idr);
/* dummytop is a shorthand for the dummy hierarchy's top cgroup */
#define dummytop (&rootnode.top_cgroup)
@@ -1440,27 +1439,16 @@ static void init_cgroup_root(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_root_mutex);
- do {
- if (!ida_pre_get(&hierarchy_ida, GFP_KERNEL))
- return -ENOMEM;
- /* Try to allocate the next unused ID */
- ret = ida_get_new_above(&hierarchy_ida, next_hierarchy_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);
+ id = idr_alloc_cyclic(&cgroup_hierarchy_idr, root, 2, 0, GFP_KERNEL);
+ if (id < 0)
+ return id;
+
+ root->hierarchy_id = id;
return 0;
}
@@ -1470,7 +1458,7 @@ static void cgroup_exit_root_id(struct cgroupfs_root *root)
lockdep_assert_held(&cgroup_root_mutex);
if (root->hierarchy_id) {
- ida_remove(&hierarchy_ida, root->hierarchy_id);
+ idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
root->hierarchy_id = 0;
}
}