aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-04 15:09:13 -0400
committerTejun Heo <tj@kernel.org>2014-05-04 15:09:13 -0400
commit7d699ddb2b181a2c76e5ea18b1bdf102c4bebe4b (patch)
tree0811810b37ff735921b689aa1ca273ecf253e29c
parent69dfa00ccb72a37f3810687ca110e5a8154c6eed (diff)
cgroup, memcg: allocate cgroup ID from 1
Currently, cgroup->id is allocated from 0, which is always assigned to the root cgroup; unfortunately, memcg wants to use ID 0 to indicate invalid IDs and ends up incrementing all IDs by one. It's reasonable to reserve 0 for special purposes. This patch updates cgroup core so that ID 0 is not used and the root cgroups get ID 1. The ID incrementing is removed form memcg. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r--include/linux/cgroup.h4
-rw-r--r--kernel/cgroup.c4
-rw-r--r--mm/memcontrol.c8
3 files changed, 6 insertions, 10 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index c6c703f2486b..793f70a48820 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -144,8 +144,8 @@ struct cgroup {
144 /* 144 /*
145 * idr allocated in-hierarchy ID. 145 * idr allocated in-hierarchy ID.
146 * 146 *
147 * The ID of the root cgroup is always 0, and a new cgroup 147 * ID 0 is not used, the ID of the root cgroup is always 1, and a
148 * will be assigned with a smallest available ID. 148 * new cgroup will be assigned with a smallest available ID.
149 * 149 *
150 * Allocating/Removing ID must be protected by cgroup_mutex. 150 * Allocating/Removing ID must be protected by cgroup_mutex.
151 */ 151 */
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 21667f396a1e..3fa0463e74bb 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1531,7 +1531,7 @@ static int cgroup_setup_root(struct cgroup_root *root, unsigned int ss_mask)
1531 lockdep_assert_held(&cgroup_tree_mutex); 1531 lockdep_assert_held(&cgroup_tree_mutex);
1532 lockdep_assert_held(&cgroup_mutex); 1532 lockdep_assert_held(&cgroup_mutex);
1533 1533
1534 ret = idr_alloc(&root->cgroup_idr, root_cgrp, 0, 1, GFP_KERNEL); 1534 ret = idr_alloc(&root->cgroup_idr, root_cgrp, 1, 2, GFP_KERNEL);
1535 if (ret < 0) 1535 if (ret < 0)
1536 goto out; 1536 goto out;
1537 root_cgrp->id = ret; 1537 root_cgrp->id = ret;
@@ -4225,7 +4225,7 @@ static long cgroup_create(struct cgroup *parent, const char *name,
4225 * Temporarily set the pointer to NULL, so idr_find() won't return 4225 * Temporarily set the pointer to NULL, so idr_find() won't return
4226 * a half-baked cgroup. 4226 * a half-baked cgroup.
4227 */ 4227 */
4228 cgrp->id = idr_alloc(&root->cgroup_idr, NULL, 1, 0, GFP_KERNEL); 4228 cgrp->id = idr_alloc(&root->cgroup_idr, NULL, 2, 0, GFP_KERNEL);
4229 if (cgrp->id < 0) { 4229 if (cgrp->id < 0) {
4230 err = -ENOMEM; 4230 err = -ENOMEM;
4231 goto err_unlock; 4231 goto err_unlock;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 29501f040568..1d0b29715b73 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -527,18 +527,14 @@ static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
527 527
528static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) 528static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg)
529{ 529{
530 /* 530 return memcg->css.cgroup->id;
531 * The ID of the root cgroup is 0, but memcg treat 0 as an
532 * invalid ID, so we return (cgroup_id + 1).
533 */
534 return memcg->css.cgroup->id + 1;
535} 531}
536 532
537static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) 533static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
538{ 534{
539 struct cgroup_subsys_state *css; 535 struct cgroup_subsys_state *css;
540 536
541 css = css_from_id(id - 1, &memory_cgrp_subsys); 537 css = css_from_id(id, &memory_cgrp_subsys);
542 return mem_cgroup_from_css(css); 538 return mem_cgroup_from_css(css);
543} 539}
544 540