cgroup: clarify css sibling linkage is protected by cgroup_mutex or RCU
Patch series "Improve mem_cgroup_iter()", v4. Incremental cgroup iteration is being used again [1]. This patchset improves the reliability of mem_cgroup_iter(). It also improves simplicity and code readability. [1] https://lore.kernel.org/20240514202641.2821494-1-hannes@cmpxchg.org/ This patch (of 5): Explicitly document that css sibling/descendant linkage is protected by cgroup_mutex or RCU. Also, document in css_next_descendant_pre() and similar functions that it isn't necessary to hold a ref on @pos. The following changes in this patchset rely on this clarification for simplification in memcg iteration code. Link: https://lkml.kernel.org/r/20240905003058.1859929-1-kinseyho@google.com Link: https://lkml.kernel.org/r/20240905003058.1859929-2-kinseyho@google.com Suggested-by: Yosry Ahmed <yosryahmed@google.com> Reviewed-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Kinsey Ho <kinseyho@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: Tejun Heo <tj@kernel.org> Cc: Zefan Li <lizefan.x@bytedance.com> Cc: Hugh Dickins <hughd@google.com> Cc: T.J. Mercier <tjmercier@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
6e94da943b
commit
0e40cf2a8b
@ -172,7 +172,11 @@ struct cgroup_subsys_state {
|
|||||||
/* reference count - access via css_[try]get() and css_put() */
|
/* reference count - access via css_[try]get() and css_put() */
|
||||||
struct percpu_ref refcnt;
|
struct percpu_ref refcnt;
|
||||||
|
|
||||||
/* siblings list anchored at the parent's ->children */
|
/*
|
||||||
|
* siblings list anchored at the parent's ->children
|
||||||
|
*
|
||||||
|
* linkage is protected by cgroup_mutex or RCU
|
||||||
|
*/
|
||||||
struct list_head sibling;
|
struct list_head sibling;
|
||||||
struct list_head children;
|
struct list_head children;
|
||||||
|
|
||||||
|
@ -4602,8 +4602,9 @@ struct cgroup_subsys_state *css_next_child(struct cgroup_subsys_state *pos,
|
|||||||
*
|
*
|
||||||
* While this function requires cgroup_mutex or RCU read locking, it
|
* While this function requires cgroup_mutex or RCU read locking, it
|
||||||
* doesn't require the whole traversal to be contained in a single critical
|
* doesn't require the whole traversal to be contained in a single critical
|
||||||
* section. This function will return the correct next descendant as long
|
* section. Additionally, it isn't necessary to hold onto a reference to @pos.
|
||||||
* as both @pos and @root are accessible and @pos is a descendant of @root.
|
* This function will return the correct next descendant as long as both @pos
|
||||||
|
* and @root are accessible and @pos is a descendant of @root.
|
||||||
*
|
*
|
||||||
* If a subsystem synchronizes ->css_online() and the start of iteration, a
|
* If a subsystem synchronizes ->css_online() and the start of iteration, a
|
||||||
* css which finished ->css_online() is guaranteed to be visible in the
|
* css which finished ->css_online() is guaranteed to be visible in the
|
||||||
@ -4651,8 +4652,9 @@ EXPORT_SYMBOL_GPL(css_next_descendant_pre);
|
|||||||
*
|
*
|
||||||
* While this function requires cgroup_mutex or RCU read locking, it
|
* While this function requires cgroup_mutex or RCU read locking, it
|
||||||
* doesn't require the whole traversal to be contained in a single critical
|
* doesn't require the whole traversal to be contained in a single critical
|
||||||
* section. This function will return the correct rightmost descendant as
|
* section. Additionally, it isn't necessary to hold onto a reference to @pos.
|
||||||
* long as @pos is accessible.
|
* This function will return the correct rightmost descendant as long as @pos
|
||||||
|
* is accessible.
|
||||||
*/
|
*/
|
||||||
struct cgroup_subsys_state *
|
struct cgroup_subsys_state *
|
||||||
css_rightmost_descendant(struct cgroup_subsys_state *pos)
|
css_rightmost_descendant(struct cgroup_subsys_state *pos)
|
||||||
@ -4696,9 +4698,9 @@ css_leftmost_descendant(struct cgroup_subsys_state *pos)
|
|||||||
*
|
*
|
||||||
* While this function requires cgroup_mutex or RCU read locking, it
|
* While this function requires cgroup_mutex or RCU read locking, it
|
||||||
* doesn't require the whole traversal to be contained in a single critical
|
* doesn't require the whole traversal to be contained in a single critical
|
||||||
* section. This function will return the correct next descendant as long
|
* section. Additionally, it isn't necessary to hold onto a reference to @pos.
|
||||||
* as both @pos and @cgroup are accessible and @pos is a descendant of
|
* This function will return the correct next descendant as long as both @pos
|
||||||
* @cgroup.
|
* and @cgroup are accessible and @pos is a descendant of @cgroup.
|
||||||
*
|
*
|
||||||
* If a subsystem synchronizes ->css_online() and the start of iteration, a
|
* If a subsystem synchronizes ->css_online() and the start of iteration, a
|
||||||
* css which finished ->css_online() is guaranteed to be visible in the
|
* css which finished ->css_online() is guaranteed to be visible in the
|
||||||
|
Loading…
Reference in New Issue
Block a user