Skip to content

Commit ad7c3b4

Browse files
Jinke Hanaxboe
authored andcommitted
blk-throttle: Fix io statistics for cgroup v1
After commit f382fb0 ("block: remove legacy IO schedulers"), blkio.throttle.io_serviced and blkio.throttle.io_service_bytes become the only stable io stats interface of cgroup v1, and these statistics are done in the blk-throttle code. But the current code only counts the bios that are actually throttled. When the user does not add the throttle limit, the io stats for cgroup v1 has nothing. I fix it according to the statistical method of v2, and made it count all ios accurately. Fixes: a7b36ee ("block: move blk-throtl fast path inline") Tested-by: Andrea Righi <andrea.righi@canonical.com> Signed-off-by: Jinke Han <hanjinke.666@bytedance.com> Acked-by: Muchun Song <songmuchun@bytedance.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20230507170631.89607-1-hanjinke.666@bytedance.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2c55559 commit ad7c3b4

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

block/blk-cgroup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,9 @@ void blk_cgroup_bio_start(struct bio *bio)
20622062
struct blkg_iostat_set *bis;
20632063
unsigned long flags;
20642064

2065+
if (!cgroup_subsys_on_dfl(io_cgrp_subsys))
2066+
return;
2067+
20652068
/* Root-level stats are sourced from system-wide IO stats */
20662069
if (!cgroup_parent(blkcg->css.cgroup))
20672070
return;
@@ -2093,8 +2096,7 @@ void blk_cgroup_bio_start(struct bio *bio)
20932096
}
20942097

20952098
u64_stats_update_end_irqrestore(&bis->sync, flags);
2096-
if (cgroup_subsys_on_dfl(io_cgrp_subsys))
2097-
cgroup_rstat_updated(blkcg->css.cgroup, cpu);
2099+
cgroup_rstat_updated(blkcg->css.cgroup, cpu);
20982100
put_cpu();
20992101
}
21002102

block/blk-throttle.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,12 +2178,6 @@ bool __blk_throtl_bio(struct bio *bio)
21782178

21792179
rcu_read_lock();
21802180

2181-
if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
2182-
blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf,
2183-
bio->bi_iter.bi_size);
2184-
blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1);
2185-
}
2186-
21872181
spin_lock_irq(&q->queue_lock);
21882182

21892183
throtl_update_latency_buckets(td);

block/blk-throttle.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ static inline bool blk_should_throtl(struct bio *bio)
185185
struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
186186
int rw = bio_data_dir(bio);
187187

188+
if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
189+
if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
190+
bio_set_flag(bio, BIO_CGROUP_ACCT);
191+
blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf,
192+
bio->bi_iter.bi_size);
193+
}
194+
blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1);
195+
}
196+
188197
/* iops limit is always counted */
189198
if (tg->has_rules_iops[rw])
190199
return true;

0 commit comments

Comments
 (0)