Skip to content

Commit

Permalink
blk-throttle: Fix io statistics for cgroup v1
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jinke Han <[email protected]>
Acked-by: Muchun Song <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Jinke Han authored and axboe committed Jun 25, 2023
1 parent 2c55559 commit ad7c3b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions block/blk-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,9 @@ void blk_cgroup_bio_start(struct bio *bio)
struct blkg_iostat_set *bis;
unsigned long flags;

if (!cgroup_subsys_on_dfl(io_cgrp_subsys))
return;

/* Root-level stats are sourced from system-wide IO stats */
if (!cgroup_parent(blkcg->css.cgroup))
return;
Expand Down Expand Up @@ -2093,8 +2096,7 @@ void blk_cgroup_bio_start(struct bio *bio)
}

u64_stats_update_end_irqrestore(&bis->sync, flags);
if (cgroup_subsys_on_dfl(io_cgrp_subsys))
cgroup_rstat_updated(blkcg->css.cgroup, cpu);
cgroup_rstat_updated(blkcg->css.cgroup, cpu);
put_cpu();
}

Expand Down
6 changes: 0 additions & 6 deletions block/blk-throttle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2178,12 +2178,6 @@ bool __blk_throtl_bio(struct bio *bio)

rcu_read_lock();

if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf,
bio->bi_iter.bi_size);
blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1);
}

spin_lock_irq(&q->queue_lock);

throtl_update_latency_buckets(td);
Expand Down
9 changes: 9 additions & 0 deletions block/blk-throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ static inline bool blk_should_throtl(struct bio *bio)
struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
int rw = bio_data_dir(bio);

if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
bio_set_flag(bio, BIO_CGROUP_ACCT);
blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf,
bio->bi_iter.bi_size);
}
blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1);
}

/* iops limit is always counted */
if (tg->has_rules_iops[rw])
return true;
Expand Down

0 comments on commit ad7c3b4

Please sign in to comment.