Skip to content

Commit

Permalink
blk-cgroup: move congestion_count to struct blkcg
Browse files Browse the repository at this point in the history
The congestion_count was introduced into the struct cgroup by
commit d09d8df ("blkcg: add generic throttling mechanism"),
but since it is closely related to the blkio subsys, it is not
appropriate to put it in the struct cgroup, so let's move it to
struct blkcg. There should be no functional changes because blkcg
is per cgroup.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20240716133058.3491350-1-xiujianfeng@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Xiu Jianfeng authored and Jens Axboe committed Jul 19, 2024
1 parent 72d04bd commit 89ed6c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions block/blk-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -2182,12 +2182,13 @@ void blk_cgroup_bio_start(struct bio *bio)

bool blk_cgroup_congested(void)
{
struct cgroup_subsys_state *css;
struct blkcg *blkcg;
bool ret = false;

rcu_read_lock();
for (css = blkcg_css(); css; css = css->parent) {
if (atomic_read(&css->cgroup->congestion_count)) {
for (blkcg = css_to_blkcg(blkcg_css()); blkcg;
blkcg = blkcg_parent(blkcg)) {
if (atomic_read(&blkcg->congestion_count)) {
ret = true;
break;
}
Expand Down
10 changes: 6 additions & 4 deletions block/blk-cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct blkcg {
struct cgroup_subsys_state css;
spinlock_t lock;
refcount_t online_pin;
/* If there is block congestion on this cgroup. */
atomic_t congestion_count;

struct radix_tree_root blkg_tree;
struct blkcg_gq __rcu *blkg_hint;
Expand Down Expand Up @@ -374,7 +376,7 @@ static inline void blkcg_use_delay(struct blkcg_gq *blkg)
if (WARN_ON_ONCE(atomic_read(&blkg->use_delay) < 0))
return;
if (atomic_add_return(1, &blkg->use_delay) == 1)
atomic_inc(&blkg->blkcg->css.cgroup->congestion_count);
atomic_inc(&blkg->blkcg->congestion_count);
}

static inline int blkcg_unuse_delay(struct blkcg_gq *blkg)
Expand All @@ -399,7 +401,7 @@ static inline int blkcg_unuse_delay(struct blkcg_gq *blkg)
if (old == 0)
return 0;
if (old == 1)
atomic_dec(&blkg->blkcg->css.cgroup->congestion_count);
atomic_dec(&blkg->blkcg->congestion_count);
return 1;
}

Expand All @@ -418,7 +420,7 @@ static inline void blkcg_set_delay(struct blkcg_gq *blkg, u64 delay)

/* We only want 1 person setting the congestion count for this blkg. */
if (!old && atomic_try_cmpxchg(&blkg->use_delay, &old, -1))
atomic_inc(&blkg->blkcg->css.cgroup->congestion_count);
atomic_inc(&blkg->blkcg->congestion_count);

atomic64_set(&blkg->delay_nsec, delay);
}
Expand All @@ -435,7 +437,7 @@ static inline void blkcg_clear_delay(struct blkcg_gq *blkg)

/* We only want 1 person clearing the congestion count for this blkg. */
if (old && atomic_try_cmpxchg(&blkg->use_delay, &old, 0))
atomic_dec(&blkg->blkcg->css.cgroup->congestion_count);
atomic_dec(&blkg->blkcg->congestion_count);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions include/linux/cgroup-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,6 @@ struct cgroup {
/* used to store eBPF programs */
struct cgroup_bpf bpf;

/* If there is block congestion on this cgroup. */
atomic_t congestion_count;

/* Used to store internal freezer state */
struct cgroup_freezer_state freezer;

Expand Down

0 comments on commit 89ed6c9

Please sign in to comment.