aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/cgroup.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-16 13:22:51 -0400
committerTejun Heo <tj@kernel.org>2014-05-16 13:22:51 -0400
commitc2931b70a32c705b9bd5762f5044f9eac8a52bb3 (patch)
tree0a530060fd1b196eda8e2ff81bd4010bd559ff12 /include/linux/cgroup.h
parentde3f034182ecbf0efbcef7ab8b253c6c3049a592 (diff)
cgroup: iterate cgroup_subsys_states directly
Currently, css_next_child() is implemented as finding the next child cgroup which has the css enabled, which used to be the only way to do it as only cgroups participated in sibling lists and thus could be iteratd. This works as long as what's required during iteration is not missing online csses; however, it turns out that there are use cases where offlined but not yet released csses need to be iterated. This is difficult to implement through cgroup iteration the unified hierarchy as there may be multiple dying csses for the same subsystem associated with single cgroup. After the recent changes, the cgroup self and regular csses behave identically in how they're linked and unlinked from the sibling lists including assertion of CSS_RELEASED and css_next_child() can simply switch to iterating csses directly. This both simplifies the logic and ensures that all visible non-released csses are included in the iteration whether there are multiple dying csses for a subsystem or not. As all other iterators depend on css_next_child() for sibling iteration, this changes behaviors of all css iterators. Add and update explanations on the css states which are included in traversal to all iterators. As css iteration could always contain offlined csses, this shouldn't break any of the current users and new usages which need iteration of all on and offline csses can make use of the new semantics. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org>
Diffstat (limited to 'include/linux/cgroup.h')
-rw-r--r--include/linux/cgroup.h44
1 files changed, 26 insertions, 18 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 5375582ea5f6..f2ff578fc03a 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -764,14 +764,14 @@ struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss);
764 * @pos: the css * to use as the loop cursor 764 * @pos: the css * to use as the loop cursor
765 * @parent: css whose children to walk 765 * @parent: css whose children to walk
766 * 766 *
767 * Walk @parent's children. Must be called under rcu_read_lock(). A child 767 * Walk @parent's children. Must be called under rcu_read_lock().
768 * css which hasn't finished ->css_online() or already has finished
769 * ->css_offline() may show up during traversal and it's each subsystem's
770 * responsibility to verify that each @pos is alive.
771 * 768 *
772 * If a subsystem synchronizes against the parent in its ->css_online() and 769 * If a subsystem synchronizes ->css_online() and the start of iteration, a
773 * before starting iterating, a css which finished ->css_online() is 770 * css which finished ->css_online() is guaranteed to be visible in the
774 * guaranteed to be visible in the future iterations. 771 * future iterations and will stay visible until the last reference is put.
772 * A css which hasn't finished ->css_online() or already finished
773 * ->css_offline() may show up during traversal. It's each subsystem's
774 * responsibility to synchronize against on/offlining.
775 * 775 *
776 * It is allowed to temporarily drop RCU read lock during iteration. The 776 * It is allowed to temporarily drop RCU read lock during iteration. The
777 * caller is responsible for ensuring that @pos remains accessible until 777 * caller is responsible for ensuring that @pos remains accessible until
@@ -794,17 +794,16 @@ css_rightmost_descendant(struct cgroup_subsys_state *pos);
794 * @root: css whose descendants to walk 794 * @root: css whose descendants to walk
795 * 795 *
796 * Walk @root's descendants. @root is included in the iteration and the 796 * Walk @root's descendants. @root is included in the iteration and the
797 * first node to be visited. Must be called under rcu_read_lock(). A 797 * first node to be visited. Must be called under rcu_read_lock().
798 * descendant css which hasn't finished ->css_online() or already has
799 * finished ->css_offline() may show up during traversal and it's each
800 * subsystem's responsibility to verify that each @pos is alive.
801 * 798 *
802 * If a subsystem synchronizes against the parent in its ->css_online() and 799 * If a subsystem synchronizes ->css_online() and the start of iteration, a
803 * before starting iterating, and synchronizes against @pos on each 800 * css which finished ->css_online() is guaranteed to be visible in the
804 * iteration, any descendant css which finished ->css_online() is 801 * future iterations and will stay visible until the last reference is put.
805 * guaranteed to be visible in the future iterations. 802 * A css which hasn't finished ->css_online() or already finished
803 * ->css_offline() may show up during traversal. It's each subsystem's
804 * responsibility to synchronize against on/offlining.
806 * 805 *
807 * In other words, the following guarantees that a descendant can't escape 806 * For example, the following guarantees that a descendant can't escape
808 * state updates of its ancestors. 807 * state updates of its ancestors.
809 * 808 *
810 * my_online(@css) 809 * my_online(@css)
@@ -860,8 +859,17 @@ css_next_descendant_post(struct cgroup_subsys_state *pos,
860 * 859 *
861 * Similar to css_for_each_descendant_pre() but performs post-order 860 * Similar to css_for_each_descendant_pre() but performs post-order
862 * traversal instead. @root is included in the iteration and the last 861 * traversal instead. @root is included in the iteration and the last
863 * node to be visited. Note that the walk visibility guarantee described 862 * node to be visited.
864 * in pre-order walk doesn't apply the same to post-order walks. 863 *
864 * If a subsystem synchronizes ->css_online() and the start of iteration, a
865 * css which finished ->css_online() is guaranteed to be visible in the
866 * future iterations and will stay visible until the last reference is put.
867 * A css which hasn't finished ->css_online() or already finished
868 * ->css_offline() may show up during traversal. It's each subsystem's
869 * responsibility to synchronize against on/offlining.
870 *
871 * Note that the walk visibility guarantee example described in pre-order
872 * walk doesn't apply the same to post-order walks.
865 */ 873 */
866#define css_for_each_descendant_post(pos, css) \ 874#define css_for_each_descendant_post(pos, css) \
867 for ((pos) = css_next_descendant_post(NULL, (css)); (pos); \ 875 for ((pos) = css_next_descendant_post(NULL, (css)); (pos); \