From 5969c17afc8a42ace855fc485dddbb95114f05f0 Mon Sep 17 00:00:00 2001 From: Jinke Han Date: Mon, 8 May 2023 01:06:31 +0800 Subject: [PATCH] blk-throttle: Fix io statistics for cgroup v1 ANBZ: #8460 commit ad7c3b41e86b59943a903d23c7b037d820e6270c upstream. After commit f382fb0bcef4 ("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. [backport note] This fix cgroupV1 blk-throttle io statistic if no throl-rule config. Fixes commit(c3df7c83: anolis: blk-throttle: avoid double bps statistics). Attention, we should use BIO_CGROUP_ACCT to account bps. blk_cgroup_bio_start() controls cgroupV2 statictic via bis->cur.bytes, and also set BIO_CGROUP_ACCT flag, we also should avoid set it in cgroupV1. Fixes: a7b36ee6ba29 ("block: move blk-throtl fast path inline") Tested-by: Andrea Righi Signed-off-by: Jinke Han Acked-by: Muchun Song Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20230507170631.89607-1-hanjinke.666@bytedance.com Signed-off-by: Jens Axboe Signed-off-by: Ferry Meng --- block/blk-cgroup.c | 6 ++++-- block/blk-throttle.c | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index c623632c1cda..5dbac576145c 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1915,6 +1915,9 @@ void blk_cgroup_bio_start(struct bio *bio) int rwd = blk_cgroup_io_type(bio), cpu; struct blkg_iostat_set *bis; + if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) + return; + cpu = get_cpu(); bis = per_cpu_ptr(bio->bi_blkg->iostat_cpu, cpu); u64_stats_update_begin(&bis->sync); @@ -1930,8 +1933,7 @@ void blk_cgroup_bio_start(struct bio *bio) bis->cur.ios[rwd]++; u64_stats_update_end(&bis->sync); - if (cgroup_subsys_on_dfl(io_cgrp_subsys)) - cgroup_rstat_updated(bio->bi_blkg->blkcg->css.cgroup, cpu); + cgroup_rstat_updated(bio->bi_blkg->blkcg->css.cgroup, cpu); put_cpu(); } diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 9a7beae397d6..d54f112bb18b 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -2473,9 +2473,11 @@ bool blk_throtl_bio(struct bio *bio, wait_queue_head_t **waitq, rcu_read_lock(); if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) { - if (!bio_flagged(bio, BIO_BPS_THROTTLED)) + 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); } -- Gitee