aboutsummaryrefslogtreecommitdiffstats
path: root/mm/hugetlb_cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-08 20:11:23 -0400
committerTejun Heo <tj@kernel.org>2013-08-08 20:11:23 -0400
commiteb95419b023abacb415e2a18fea899023ce7624d (patch)
tree705284469b67cbe440b86c6cb81e1cf27648eba9 /mm/hugetlb_cgroup.c
parent6387698699afd72d6304566fb6ccf84bffe07c56 (diff)
cgroup: pass around cgroup_subsys_state instead of cgroup in subsystem methods
cgroup is currently in the process of transitioning to using struct cgroup_subsys_state * as the primary handle instead of struct cgroup * in subsystem implementations for the following reasons. * With unified hierarchy, subsystems will be dynamically bound and unbound from cgroups and thus css's (cgroup_subsys_state) may be created and destroyed dynamically over the lifetime of a cgroup, which is different from the current state where all css's are allocated and destroyed together with the associated cgroup. This in turn means that cgroup_css() should be synchronized and may return NULL, making it more cumbersome to use. * Differing levels of per-subsystem granularity in the unified hierarchy means that the task and descendant iterators should behave differently depending on the specific subsystem the iteration is being performed for. * In majority of the cases, subsystems only care about its part in the cgroup hierarchy - ie. the hierarchy of css's. Subsystem methods often obtain the matching css pointer from the cgroup and don't bother with the cgroup pointer itself. Passing around css fits much better. This patch converts all cgroup_subsys methods to take @css instead of @cgroup. The conversions are mostly straight-forward. A few noteworthy changes are * ->css_alloc() now takes css of the parent cgroup rather than the pointer to the new cgroup as the css for the new cgroup doesn't exist yet. Knowing the parent css is enough for all the existing subsystems. * In kernel/cgroup.c::offline_css(), unnecessary open coded css dereference is replaced with local variable access. This patch shouldn't cause any behavior differences. v2: Unnecessary explicit cgrp->subsys[] deref in css_online() replaced with local variable @css as suggested by Li Zefan. Rebased on top of new for-3.12 which includes for-3.11-fixes so that ->css_free() invocation added by da0a12caff ("cgroup: fix a leak when percpu_ref_init() fails") is converted too. Suggested by Li Zefan. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Aristeu Rozanski <aris@redhat.com> Acked-by: Daniel Wagner <daniel.wagner@bmw-carit.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'mm/hugetlb_cgroup.c')
-rw-r--r--mm/hugetlb_cgroup.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index 57ecb5d2513f..e2132435060f 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -73,19 +73,18 @@ static inline bool hugetlb_cgroup_have_usage(struct hugetlb_cgroup *h_cg)
73 return false; 73 return false;
74} 74}
75 75
76static struct cgroup_subsys_state *hugetlb_cgroup_css_alloc(struct cgroup *cgroup) 76static struct cgroup_subsys_state *
77hugetlb_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
77{ 78{
79 struct hugetlb_cgroup *parent_h_cgroup = hugetlb_cgroup_from_css(parent_css);
80 struct hugetlb_cgroup *h_cgroup;
78 int idx; 81 int idx;
79 struct cgroup *parent_cgroup;
80 struct hugetlb_cgroup *h_cgroup, *parent_h_cgroup;
81 82
82 h_cgroup = kzalloc(sizeof(*h_cgroup), GFP_KERNEL); 83 h_cgroup = kzalloc(sizeof(*h_cgroup), GFP_KERNEL);
83 if (!h_cgroup) 84 if (!h_cgroup)
84 return ERR_PTR(-ENOMEM); 85 return ERR_PTR(-ENOMEM);
85 86
86 parent_cgroup = cgroup->parent; 87 if (parent_h_cgroup) {
87 if (parent_cgroup) {
88 parent_h_cgroup = hugetlb_cgroup_from_cgroup(parent_cgroup);
89 for (idx = 0; idx < HUGE_MAX_HSTATE; idx++) 88 for (idx = 0; idx < HUGE_MAX_HSTATE; idx++)
90 res_counter_init(&h_cgroup->hugepage[idx], 89 res_counter_init(&h_cgroup->hugepage[idx],
91 &parent_h_cgroup->hugepage[idx]); 90 &parent_h_cgroup->hugepage[idx]);
@@ -97,11 +96,11 @@ static struct cgroup_subsys_state *hugetlb_cgroup_css_alloc(struct cgroup *cgrou
97 return &h_cgroup->css; 96 return &h_cgroup->css;
98} 97}
99 98
100static void hugetlb_cgroup_css_free(struct cgroup *cgroup) 99static void hugetlb_cgroup_css_free(struct cgroup_subsys_state *css)
101{ 100{
102 struct hugetlb_cgroup *h_cgroup; 101 struct hugetlb_cgroup *h_cgroup;
103 102
104 h_cgroup = hugetlb_cgroup_from_cgroup(cgroup); 103 h_cgroup = hugetlb_cgroup_from_css(css);
105 kfree(h_cgroup); 104 kfree(h_cgroup);
106} 105}
107 106
@@ -150,9 +149,9 @@ out:
150 * Force the hugetlb cgroup to empty the hugetlb resources by moving them to 149 * Force the hugetlb cgroup to empty the hugetlb resources by moving them to
151 * the parent cgroup. 150 * the parent cgroup.
152 */ 151 */
153static void hugetlb_cgroup_css_offline(struct cgroup *cgroup) 152static void hugetlb_cgroup_css_offline(struct cgroup_subsys_state *css)
154{ 153{
155 struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_cgroup(cgroup); 154 struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(css);
156 struct hstate *h; 155 struct hstate *h;
157 struct page *page; 156 struct page *page;
158 int idx = 0; 157 int idx = 0;