aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup_freezer.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-08 20:11:27 -0400
committerTejun Heo <tj@kernel.org>2013-08-08 20:11:27 -0400
commitbd8815a6d802fc16a7a106e170593aa05dc17e72 (patch)
tree6be9383cac4c468fe77b3a598cdd1664dba4afb4 /kernel/cgroup_freezer.c
parent95109b627ba6a043c181fa5fa45d1c754dd44fbc (diff)
cgroup: make css_for_each_descendant() and friends include the origin css in the iteration
Previously, all css descendant iterators didn't include the origin (root of subtree) css in the iteration. The reasons were maintaining consistency with css_for_each_child() and that at the time of introduction more use cases needed skipping the origin anyway; however, given that css_is_descendant() considers self to be a descendant, omitting the origin css has become more confusing and looking at the accumulated use cases rather clearly indicates that including origin would result in simpler code overall. While this is a change which can easily lead to subtle bugs, cgroup API including the iterators has recently gone through major restructuring and no out-of-tree changes will be applicable without adjustments making this a relatively acceptable opportunity for this type of change. The conversions are mostly straight-forward. If the iteration block had explicit origin handling before or after, it's moved inside the iteration. If not, if (pos == origin) continue; is added. Some conversions add extra reference get/put around origin handling by consolidating origin handling and the rest. While the extra ref operations aren't strictly necessary, this shouldn't cause any noticeable difference. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Acked-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Aristeu Rozanski <aris@redhat.com> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: Jens Axboe <axboe@kernel.dk> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com>
Diffstat (limited to 'kernel/cgroup_freezer.c')
-rw-r--r--kernel/cgroup_freezer.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 224da9aa27f5..f0ff64d0ebaa 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -311,7 +311,6 @@ static int freezer_read(struct cgroup_subsys_state *css, struct cftype *cft,
311 /* update states bottom-up */ 311 /* update states bottom-up */
312 css_for_each_descendant_post(pos, css) 312 css_for_each_descendant_post(pos, css)
313 update_if_frozen(pos); 313 update_if_frozen(pos);
314 update_if_frozen(css);
315 314
316 rcu_read_unlock(); 315 rcu_read_unlock();
317 316
@@ -391,11 +390,6 @@ static void freezer_change_state(struct freezer *freezer, bool freeze)
391{ 390{
392 struct cgroup_subsys_state *pos; 391 struct cgroup_subsys_state *pos;
393 392
394 /* update @freezer */
395 spin_lock_irq(&freezer->lock);
396 freezer_apply_state(freezer, freeze, CGROUP_FREEZING_SELF);
397 spin_unlock_irq(&freezer->lock);
398
399 /* 393 /*
400 * Update all its descendants in pre-order traversal. Each 394 * Update all its descendants in pre-order traversal. Each
401 * descendant will try to inherit its parent's FREEZING state as 395 * descendant will try to inherit its parent's FREEZING state as
@@ -406,14 +400,23 @@ static void freezer_change_state(struct freezer *freezer, bool freeze)
406 struct freezer *pos_f = css_freezer(pos); 400 struct freezer *pos_f = css_freezer(pos);
407 struct freezer *parent = parent_freezer(pos_f); 401 struct freezer *parent = parent_freezer(pos_f);
408 402
409 /*
410 * Our update to @parent->state is already visible which is
411 * all we need. No need to lock @parent. For more info on
412 * synchronization, see freezer_post_create().
413 */
414 spin_lock_irq(&pos_f->lock); 403 spin_lock_irq(&pos_f->lock);
415 freezer_apply_state(pos_f, parent->state & CGROUP_FREEZING, 404
416 CGROUP_FREEZING_PARENT); 405 if (pos_f == freezer) {
406 freezer_apply_state(pos_f, freeze,
407 CGROUP_FREEZING_SELF);
408 } else {
409 /*
410 * Our update to @parent->state is already visible
411 * which is all we need. No need to lock @parent.
412 * For more info on synchronization, see
413 * freezer_post_create().
414 */
415 freezer_apply_state(pos_f,
416 parent->state & CGROUP_FREEZING,
417 CGROUP_FREEZING_PARENT);
418 }
419
417 spin_unlock_irq(&pos_f->lock); 420 spin_unlock_irq(&pos_f->lock);
418 } 421 }
419 rcu_read_unlock(); 422 rcu_read_unlock();