aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-16 13:22:49 -0400
committerTejun Heo <tj@kernel.org>2014-05-16 13:22:49 -0400
commit0cb51d71c1fa9234afe4213089844be76ec1765a (patch)
tree3878362e74b45e486bab5e6398acec5bb775e6cf /kernel/cgroup.c
parent1fed1b2e36ba1aa0257004a97e75bbdb70f216b5 (diff)
cgroup: move cgroup->serial_nr into cgroup_subsys_state
We're moving towards using cgroup_subsys_states as the fundamental structural blocks. All csses including the cgroup->self and actual ones now form trees through css->children and ->sibling which follow the same rules as what cgroup->children and ->sibling followed. This patch moves cgroup->serial_nr which is used to implement css iteration into css. Note that all csses, regardless of their types, allocate their serial numbers from the same monotonically increasing counter. This doesn't affect the ordering needed by css iteration or cause any other material behavior changes. This will be used to update css iteration. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index dcb06e181ce4..d5af128ec1ec 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -157,14 +157,13 @@ static int cgroup_root_count;
157static DEFINE_IDR(cgroup_hierarchy_idr); 157static DEFINE_IDR(cgroup_hierarchy_idr);
158 158
159/* 159/*
160 * Assign a monotonically increasing serial number to cgroups. It 160 * Assign a monotonically increasing serial number to csses. It guarantees
161 * guarantees cgroups with bigger numbers are newer than those with smaller 161 * cgroups with bigger numbers are newer than those with smaller numbers.
162 * numbers. Also, as cgroups are always appended to the parent's 162 * Also, as csses are always appended to the parent's ->children list, it
163 * ->children list, it guarantees that sibling cgroups are always sorted in 163 * guarantees that sibling csses are always sorted in the ascending serial
164 * the ascending serial number order on the list. Protected by 164 * number order on the list. Protected by cgroup_mutex.
165 * cgroup_mutex.
166 */ 165 */
167static u64 cgroup_serial_nr_next = 1; 166static u64 css_serial_nr_next = 1;
168 167
169/* This flag indicates whether tasks in the fork and exit paths should 168/* This flag indicates whether tasks in the fork and exit paths should
170 * check for fork/exit handlers to call. This avoids us having to do 169 * check for fork/exit handlers to call. This avoids us having to do
@@ -3133,7 +3132,7 @@ css_next_child(struct cgroup_subsys_state *pos_css,
3133 next = list_entry_rcu(pos->self.sibling.next, struct cgroup, self.sibling); 3132 next = list_entry_rcu(pos->self.sibling.next, struct cgroup, self.sibling);
3134 } else { 3133 } else {
3135 list_for_each_entry_rcu(next, &cgrp->self.children, self.sibling) 3134 list_for_each_entry_rcu(next, &cgrp->self.children, self.sibling)
3136 if (next->serial_nr > pos->serial_nr) 3135 if (next->self.serial_nr > pos->self.serial_nr)
3137 break; 3136 break;
3138 } 3137 }
3139 3138
@@ -4168,6 +4167,8 @@ static void css_release(struct percpu_ref *ref)
4168static void init_and_link_css(struct cgroup_subsys_state *css, 4167static void init_and_link_css(struct cgroup_subsys_state *css,
4169 struct cgroup_subsys *ss, struct cgroup *cgrp) 4168 struct cgroup_subsys *ss, struct cgroup *cgrp)
4170{ 4169{
4170 lockdep_assert_held(&cgroup_mutex);
4171
4171 cgroup_get(cgrp); 4172 cgroup_get(cgrp);
4172 4173
4173 memset(css, 0, sizeof(*css)); 4174 memset(css, 0, sizeof(*css));
@@ -4175,6 +4176,7 @@ static void init_and_link_css(struct cgroup_subsys_state *css,
4175 css->ss = ss; 4176 css->ss = ss;
4176 INIT_LIST_HEAD(&css->sibling); 4177 INIT_LIST_HEAD(&css->sibling);
4177 INIT_LIST_HEAD(&css->children); 4178 INIT_LIST_HEAD(&css->children);
4179 css->serial_nr = css_serial_nr_next++;
4178 4180
4179 if (cgroup_parent(cgrp)) { 4181 if (cgroup_parent(cgrp)) {
4180 css->parent = cgroup_css(cgroup_parent(cgrp), ss); 4182 css->parent = cgroup_css(cgroup_parent(cgrp), ss);
@@ -4348,7 +4350,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
4348 */ 4350 */
4349 kernfs_get(kn); 4351 kernfs_get(kn);
4350 4352
4351 cgrp->serial_nr = cgroup_serial_nr_next++; 4353 cgrp->self.serial_nr = css_serial_nr_next++;
4352 4354
4353 /* allocation complete, commit to creation */ 4355 /* allocation complete, commit to creation */
4354 list_add_tail_rcu(&cgrp->self.sibling, &cgroup_parent(cgrp)->self.children); 4356 list_add_tail_rcu(&cgrp->self.sibling, &cgroup_parent(cgrp)->self.children);