Skip to content

Commit 492eb21

Browse files
committed
cgroup: make hierarchy iterators deal with cgroup_subsys_state instead of cgroup
cgroup is currently in the process of transitioning to using css (cgroup_subsys_state) as the primary handle instead of cgroup in subsystem API. For hierarchy iterators, this is beneficial because * In most cases, css is the only thing subsystems care about anyway. * On the planned unified hierarchy, iterations for different subsystems will need to skip over different subtrees of the hierarchy depending on which subsystems are enabled on each cgroup. Passing around css makes it unnecessary to explicitly specify the subsystem in question as css is intersection between cgroup and subsystem * For the planned unified hierarchy, css's would need to be created and destroyed dynamically independent from cgroup hierarchy. Having cgroup core manage css iteration makes enforcing deref rules a lot easier. Most subsystem conversions are straight-forward. Noteworthy changes are * blkio: cgroup_to_blkcg() is no longer used. Removed. * freezer: cgroup_freezer() is no longer used. Removed. * devices: cgroup_to_devcgroup() is no longer used. Removed. 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> 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>
1 parent f48e392 commit 492eb21

File tree

9 files changed

+187
-187
lines changed

9 files changed

+187
-187
lines changed

block/blk-cgroup.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,15 @@ u64 blkg_stat_recursive_sum(struct blkg_policy_data *pd, int off)
614614
{
615615
struct blkcg_policy *pol = blkcg_policy[pd->plid];
616616
struct blkcg_gq *pos_blkg;
617-
struct cgroup *pos_cgrp;
617+
struct cgroup_subsys_state *pos_css;
618618
u64 sum;
619619

620620
lockdep_assert_held(pd->blkg->q->queue_lock);
621621

622622
sum = blkg_stat_read((void *)pd + off);
623623

624624
rcu_read_lock();
625-
blkg_for_each_descendant_pre(pos_blkg, pos_cgrp, pd_to_blkg(pd)) {
625+
blkg_for_each_descendant_pre(pos_blkg, pos_css, pd_to_blkg(pd)) {
626626
struct blkg_policy_data *pos_pd = blkg_to_pd(pos_blkg, pol);
627627
struct blkg_stat *stat = (void *)pos_pd + off;
628628

@@ -649,7 +649,7 @@ struct blkg_rwstat blkg_rwstat_recursive_sum(struct blkg_policy_data *pd,
649649
{
650650
struct blkcg_policy *pol = blkcg_policy[pd->plid];
651651
struct blkcg_gq *pos_blkg;
652-
struct cgroup *pos_cgrp;
652+
struct cgroup_subsys_state *pos_css;
653653
struct blkg_rwstat sum;
654654
int i;
655655

@@ -658,7 +658,7 @@ struct blkg_rwstat blkg_rwstat_recursive_sum(struct blkg_policy_data *pd,
658658
sum = blkg_rwstat_read((void *)pd + off);
659659

660660
rcu_read_lock();
661-
blkg_for_each_descendant_pre(pos_blkg, pos_cgrp, pd_to_blkg(pd)) {
661+
blkg_for_each_descendant_pre(pos_blkg, pos_css, pd_to_blkg(pd)) {
662662
struct blkg_policy_data *pos_pd = blkg_to_pd(pos_blkg, pol);
663663
struct blkg_rwstat *rwstat = (void *)pos_pd + off;
664664
struct blkg_rwstat tmp;

block/blk-cgroup.h

+9-16
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,6 @@ static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
184184
return css ? container_of(css, struct blkcg, css) : NULL;
185185
}
186186

187-
static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup)
188-
{
189-
return css_to_blkcg(cgroup_css(cgroup, blkio_subsys_id));
190-
}
191-
192187
static inline struct blkcg *task_blkcg(struct task_struct *tsk)
193188
{
194189
return css_to_blkcg(task_css(tsk, blkio_subsys_id));
@@ -289,32 +284,31 @@ struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg, struct request_queue *q,
289284
/**
290285
* blkg_for_each_descendant_pre - pre-order walk of a blkg's descendants
291286
* @d_blkg: loop cursor pointing to the current descendant
292-
* @pos_cgrp: used for iteration
287+
* @pos_css: used for iteration
293288
* @p_blkg: target blkg to walk descendants of
294289
*
295290
* Walk @c_blkg through the descendants of @p_blkg. Must be used with RCU
296291
* read locked. If called under either blkcg or queue lock, the iteration
297292
* is guaranteed to include all and only online blkgs. The caller may
298-
* update @pos_cgrp by calling cgroup_rightmost_descendant() to skip
299-
* subtree.
293+
* update @pos_css by calling css_rightmost_descendant() to skip subtree.
300294
*/
301-
#define blkg_for_each_descendant_pre(d_blkg, pos_cgrp, p_blkg) \
302-
cgroup_for_each_descendant_pre((pos_cgrp), (p_blkg)->blkcg->css.cgroup) \
303-
if (((d_blkg) = __blkg_lookup(cgroup_to_blkcg(pos_cgrp), \
295+
#define blkg_for_each_descendant_pre(d_blkg, pos_css, p_blkg) \
296+
css_for_each_descendant_pre((pos_css), &(p_blkg)->blkcg->css) \
297+
if (((d_blkg) = __blkg_lookup(css_to_blkcg(pos_css), \
304298
(p_blkg)->q, false)))
305299

306300
/**
307301
* blkg_for_each_descendant_post - post-order walk of a blkg's descendants
308302
* @d_blkg: loop cursor pointing to the current descendant
309-
* @pos_cgrp: used for iteration
303+
* @pos_css: used for iteration
310304
* @p_blkg: target blkg to walk descendants of
311305
*
312306
* Similar to blkg_for_each_descendant_pre() but performs post-order
313307
* traversal instead. Synchronization rules are the same.
314308
*/
315-
#define blkg_for_each_descendant_post(d_blkg, pos_cgrp, p_blkg) \
316-
cgroup_for_each_descendant_post((pos_cgrp), (p_blkg)->blkcg->css.cgroup) \
317-
if (((d_blkg) = __blkg_lookup(cgroup_to_blkcg(pos_cgrp), \
309+
#define blkg_for_each_descendant_post(d_blkg, pos_css, p_blkg) \
310+
css_for_each_descendant_post((pos_css), &(p_blkg)->blkcg->css) \
311+
if (((d_blkg) = __blkg_lookup(css_to_blkcg(pos_css), \
318312
(p_blkg)->q, false)))
319313

320314
/**
@@ -577,7 +571,6 @@ static inline int blkcg_activate_policy(struct request_queue *q,
577571
static inline void blkcg_deactivate_policy(struct request_queue *q,
578572
const struct blkcg_policy *pol) { }
579573

580-
static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup) { return NULL; }
581574
static inline struct blkcg *bio_blkcg(struct bio *bio) { return NULL; }
582575

583576
static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,

block/blk-throttle.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ static int tg_set_conf(struct cgroup_subsys_state *css, struct cftype *cft,
13491349
struct throtl_grp *tg;
13501350
struct throtl_service_queue *sq;
13511351
struct blkcg_gq *blkg;
1352-
struct cgroup *pos_cgrp;
1352+
struct cgroup_subsys_state *pos_css;
13531353
int ret;
13541354

13551355
ret = blkg_conf_prep(blkcg, &blkcg_policy_throtl, buf, &ctx);
@@ -1380,7 +1380,7 @@ static int tg_set_conf(struct cgroup_subsys_state *css, struct cftype *cft,
13801380
* blk-throttle.
13811381
*/
13821382
tg_update_has_rules(tg);
1383-
blkg_for_each_descendant_pre(blkg, pos_cgrp, ctx.blkg)
1383+
blkg_for_each_descendant_pre(blkg, pos_css, ctx.blkg)
13841384
tg_update_has_rules(blkg_to_tg(blkg));
13851385

13861386
/*
@@ -1623,7 +1623,7 @@ void blk_throtl_drain(struct request_queue *q)
16231623
{
16241624
struct throtl_data *td = q->td;
16251625
struct blkcg_gq *blkg;
1626-
struct cgroup *pos_cgrp;
1626+
struct cgroup_subsys_state *pos_css;
16271627
struct bio *bio;
16281628
int rw;
16291629

@@ -1636,7 +1636,7 @@ void blk_throtl_drain(struct request_queue *q)
16361636
* better to walk service_queue tree directly but blkg walk is
16371637
* easier.
16381638
*/
1639-
blkg_for_each_descendant_post(blkg, pos_cgrp, td->queue->root_blkg)
1639+
blkg_for_each_descendant_post(blkg, pos_css, td->queue->root_blkg)
16401640
tg_drain_bios(&blkg_to_tg(blkg)->service_queue);
16411641

16421642
tg_drain_bios(&td_root_tg(td)->service_queue);

include/linux/cgroup.h

+46-42
Original file line numberDiff line numberDiff line change
@@ -779,68 +779,72 @@ static inline struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id)
779779
return idr_find(&ss->root->cgroup_idr, id);
780780
}
781781

782-
struct cgroup *cgroup_next_child(struct cgroup *pos, struct cgroup *cgrp);
782+
struct cgroup_subsys_state *css_next_child(struct cgroup_subsys_state *pos,
783+
struct cgroup_subsys_state *parent);
783784

784785
/**
785-
* cgroup_for_each_child - iterate through children of a cgroup
786-
* @pos: the cgroup * to use as the loop cursor
787-
* @cgrp: cgroup whose children to walk
786+
* css_for_each_child - iterate through children of a css
787+
* @pos: the css * to use as the loop cursor
788+
* @parent: css whose children to walk
788789
*
789-
* Walk @cgrp's children. Must be called under rcu_read_lock(). A child
790-
* cgroup which hasn't finished ->css_online() or already has finished
790+
* Walk @parent's children. Must be called under rcu_read_lock(). A child
791+
* css which hasn't finished ->css_online() or already has finished
791792
* ->css_offline() may show up during traversal and it's each subsystem's
792793
* responsibility to verify that each @pos is alive.
793794
*
794795
* If a subsystem synchronizes against the parent in its ->css_online() and
795-
* before starting iterating, a cgroup which finished ->css_online() is
796+
* before starting iterating, a css which finished ->css_online() is
796797
* guaranteed to be visible in the future iterations.
797798
*
798799
* It is allowed to temporarily drop RCU read lock during iteration. The
799800
* caller is responsible for ensuring that @pos remains accessible until
800801
* the start of the next iteration by, for example, bumping the css refcnt.
801802
*/
802-
#define cgroup_for_each_child(pos, cgrp) \
803-
for ((pos) = cgroup_next_child(NULL, (cgrp)); (pos); \
804-
(pos) = cgroup_next_child((pos), (cgrp)))
803+
#define css_for_each_child(pos, parent) \
804+
for ((pos) = css_next_child(NULL, (parent)); (pos); \
805+
(pos) = css_next_child((pos), (parent)))
805806

806-
struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,
807-
struct cgroup *cgroup);
808-
struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos);
807+
struct cgroup_subsys_state *
808+
css_next_descendant_pre(struct cgroup_subsys_state *pos,
809+
struct cgroup_subsys_state *css);
810+
811+
struct cgroup_subsys_state *
812+
css_rightmost_descendant(struct cgroup_subsys_state *pos);
809813

810814
/**
811-
* cgroup_for_each_descendant_pre - pre-order walk of a cgroup's descendants
812-
* @pos: the cgroup * to use as the loop cursor
813-
* @cgroup: cgroup whose descendants to walk
815+
* css_for_each_descendant_pre - pre-order walk of a css's descendants
816+
* @pos: the css * to use as the loop cursor
817+
* @root: css whose descendants to walk
814818
*
815-
* Walk @cgroup's descendants. Must be called under rcu_read_lock(). A
816-
* descendant cgroup which hasn't finished ->css_online() or already has
819+
* Walk @root's descendants. Must be called under rcu_read_lock(). A
820+
* descendant css which hasn't finished ->css_online() or already has
817821
* finished ->css_offline() may show up during traversal and it's each
818822
* subsystem's responsibility to verify that each @pos is alive.
819823
*
820824
* If a subsystem synchronizes against the parent in its ->css_online() and
821825
* before starting iterating, and synchronizes against @pos on each
822-
* iteration, any descendant cgroup which finished ->css_online() is
826+
* iteration, any descendant css which finished ->css_online() is
823827
* guaranteed to be visible in the future iterations.
824828
*
825829
* In other words, the following guarantees that a descendant can't escape
826830
* state updates of its ancestors.
827831
*
828-
* my_online(@cgrp)
832+
* my_online(@css)
829833
* {
830-
* Lock @cgrp->parent and @cgrp;
831-
* Inherit state from @cgrp->parent;
834+
* Lock @css's parent and @css;
835+
* Inherit state from the parent;
832836
* Unlock both.
833837
* }
834838
*
835-
* my_update_state(@cgrp)
839+
* my_update_state(@css)
836840
* {
837-
* Lock @cgrp;
838-
* Update @cgrp's state;
839-
* Unlock @cgrp;
841+
* Lock @css;
842+
* Update @css's state;
843+
* Unlock @css;
840844
*
841-
* cgroup_for_each_descendant_pre(@pos, @cgrp) {
845+
* css_for_each_descendant_pre(@pos, @css) {
842846
* Lock @pos;
843-
* Verify @pos is alive and inherit state from @pos->parent;
847+
* Verify @pos is alive and inherit state from @pos's parent;
844848
* Unlock @pos;
845849
* }
846850
* }
@@ -851,8 +855,7 @@ struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos);
851855
* visible by walking order and, as long as inheriting operations to the
852856
* same @pos are atomic to each other, multiple updates racing each other
853857
* still result in the correct state. It's guaranateed that at least one
854-
* inheritance happens for any cgroup after the latest update to its
855-
* parent.
858+
* inheritance happens for any css after the latest update to its parent.
856859
*
857860
* If checking parent's state requires locking the parent, each inheriting
858861
* iteration should lock and unlock both @pos->parent and @pos.
@@ -865,25 +868,26 @@ struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos);
865868
* caller is responsible for ensuring that @pos remains accessible until
866869
* the start of the next iteration by, for example, bumping the css refcnt.
867870
*/
868-
#define cgroup_for_each_descendant_pre(pos, cgroup) \
869-
for (pos = cgroup_next_descendant_pre(NULL, (cgroup)); (pos); \
870-
pos = cgroup_next_descendant_pre((pos), (cgroup)))
871+
#define css_for_each_descendant_pre(pos, css) \
872+
for ((pos) = css_next_descendant_pre(NULL, (css)); (pos); \
873+
(pos) = css_next_descendant_pre((pos), (css)))
871874

872-
struct cgroup *cgroup_next_descendant_post(struct cgroup *pos,
873-
struct cgroup *cgroup);
875+
struct cgroup_subsys_state *
876+
css_next_descendant_post(struct cgroup_subsys_state *pos,
877+
struct cgroup_subsys_state *css);
874878

875879
/**
876-
* cgroup_for_each_descendant_post - post-order walk of a cgroup's descendants
877-
* @pos: the cgroup * to use as the loop cursor
878-
* @cgroup: cgroup whose descendants to walk
880+
* css_for_each_descendant_post - post-order walk of a css's descendants
881+
* @pos: the css * to use as the loop cursor
882+
* @css: css whose descendants to walk
879883
*
880-
* Similar to cgroup_for_each_descendant_pre() but performs post-order
884+
* Similar to css_for_each_descendant_pre() but performs post-order
881885
* traversal instead. Note that the walk visibility guarantee described in
882886
* pre-order walk doesn't apply the same to post-order walks.
883887
*/
884-
#define cgroup_for_each_descendant_post(pos, cgroup) \
885-
for (pos = cgroup_next_descendant_post(NULL, (cgroup)); (pos); \
886-
pos = cgroup_next_descendant_post((pos), (cgroup)))
888+
#define css_for_each_descendant_post(pos, css) \
889+
for ((pos) = css_next_descendant_post(NULL, (css)); (pos); \
890+
(pos) = css_next_descendant_post((pos), (css)))
887891

888892
/* A cgroup_iter should be treated as an opaque object */
889893
struct cgroup_iter {

0 commit comments

Comments
 (0)