aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-14 09:15:02 -0400
committerTejun Heo <tj@kernel.org>2014-05-14 09:15:02 -0400
commit9395a4500404e05173eda9a2d198b6fa500e90c5 (patch)
treedb5e953a6b3e1d074e64c3e36e3b7c90fc564770
parent25e15d835036a70a53dcc993beaa036f8919a373 (diff)
cgroup: enable refcnting for root csses
Currently, css_get(), css_tryget() and css_tryget_online() are noops for root csses as an optimization; however, we're planning to use css refcnts to track of cgroup lifetime too and root cgroups also need to be reference counted. Since css has been converted to percpu_refcnt, the overhead of refcnting is miniscule and this optimization isn't too meaningful anymore. Furthermore, controllers which optimize the root cgroup often never even invoke these functions in their hot paths. This patch enables refcnting for root csses too. This makes CSS_ROOT flag unused and removes it. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r--include/linux/cgroup.h10
-rw-r--r--kernel/cgroup.c6
2 files changed, 5 insertions, 11 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 160fcc69149e..286e39e4e9bf 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -77,7 +77,6 @@ struct cgroup_subsys_state {
77 77
78/* bits in struct cgroup_subsys_state flags field */ 78/* bits in struct cgroup_subsys_state flags field */
79enum { 79enum {
80 CSS_ROOT = (1 << 0), /* this CSS is the root of the subsystem */
81 CSS_ONLINE = (1 << 1), /* between ->css_online() and ->css_offline() */ 80 CSS_ONLINE = (1 << 1), /* between ->css_online() and ->css_offline() */
82}; 81};
83 82
@@ -89,9 +88,7 @@ enum {
89 */ 88 */
90static inline void css_get(struct cgroup_subsys_state *css) 89static inline void css_get(struct cgroup_subsys_state *css)
91{ 90{
92 /* We don't need to reference count the root state */ 91 percpu_ref_get(&css->refcnt);
93 if (!(css->flags & CSS_ROOT))
94 percpu_ref_get(&css->refcnt);
95} 92}
96 93
97/** 94/**
@@ -106,8 +103,6 @@ static inline void css_get(struct cgroup_subsys_state *css)
106 */ 103 */
107static inline bool css_tryget_online(struct cgroup_subsys_state *css) 104static inline bool css_tryget_online(struct cgroup_subsys_state *css)
108{ 105{
109 if (css->flags & CSS_ROOT)
110 return true;
111 return percpu_ref_tryget_live(&css->refcnt); 106 return percpu_ref_tryget_live(&css->refcnt);
112} 107}
113 108
@@ -119,8 +114,7 @@ static inline bool css_tryget_online(struct cgroup_subsys_state *css)
119 */ 114 */
120static inline void css_put(struct cgroup_subsys_state *css) 115static inline void css_put(struct cgroup_subsys_state *css)
121{ 116{
122 if (!(css->flags & CSS_ROOT)) 117 percpu_ref_put(&css->refcnt);
123 percpu_ref_put(&css->refcnt);
124} 118}
125 119
126/* bits in struct cgroup flags field */ 120/* bits in struct cgroup flags field */
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index e694f4153edb..cb5864e36f99 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4158,8 +4158,6 @@ static void init_and_link_css(struct cgroup_subsys_state *css,
4158 if (cgrp->parent) { 4158 if (cgrp->parent) {
4159 css->parent = cgroup_css(cgrp->parent, ss); 4159 css->parent = cgroup_css(cgrp->parent, ss);
4160 css_get(css->parent); 4160 css_get(css->parent);
4161 } else {
4162 css->flags |= CSS_ROOT;
4163 } 4161 }
4164 4162
4165 BUG_ON(cgroup_css(cgrp, ss)); 4163 BUG_ON(cgroup_css(cgrp, ss));
@@ -4582,9 +4580,10 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)
4582 BUG_ON(IS_ERR(css)); 4580 BUG_ON(IS_ERR(css));
4583 init_and_link_css(css, ss, &cgrp_dfl_root.cgrp); 4581 init_and_link_css(css, ss, &cgrp_dfl_root.cgrp);
4584 if (early) { 4582 if (early) {
4585 /* idr_alloc() can't be called safely during early init */ 4583 /* allocation can't be done safely during early init */
4586 css->id = 1; 4584 css->id = 1;
4587 } else { 4585 } else {
4586 BUG_ON(percpu_ref_init(&css->refcnt, css_release));
4588 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2, GFP_KERNEL); 4587 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2, GFP_KERNEL);
4589 BUG_ON(css->id < 0); 4588 BUG_ON(css->id < 0);
4590 } 4589 }
@@ -4671,6 +4670,7 @@ int __init cgroup_init(void)
4671 struct cgroup_subsys_state *css = 4670 struct cgroup_subsys_state *css =
4672 init_css_set.subsys[ss->id]; 4671 init_css_set.subsys[ss->id];
4673 4672
4673 BUG_ON(percpu_ref_init(&css->refcnt, css_release));
4674 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2, 4674 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2,
4675 GFP_KERNEL); 4675 GFP_KERNEL);
4676 BUG_ON(css->id < 0); 4676 BUG_ON(css->id < 0);