[SRU][K][PATCH 1/1] UBUNTU: SAUCE: blk-throttle: Fix io statistics for cgroup v1

Andrea Righi andrea.righi at canonical.com
Tue May 9 05:18:20 UTC 2023


From: Jinke Han <hanjinke.666 at bytedance.com>

BugLink: https://bugs.launchpad.net/bugs/2016186

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.

Fixes: a7b36ee6ba29 ("block: move blk-throtl fast path inline")
Tested-by: Andrea Righi <andrea.righi at canonical.com>
Signed-off-by: Jinke Han <hanjinke.666 at bytedance.com>
(backported from https://lore.kernel.org/lkml/20230507170631.89607-1-hanjinke.666@bytedance.com/t/)
[ arighi: patch blk_throtl_bio() instead of blk_should_throtl() and adjust blkcg stats accounting ]
Signed-off-by: Andrea Righi <andrea.righi at canonical.com>
---
 block/blk-cgroup.c   | 6 ++++--
 block/blk-throttle.c | 6 ------
 block/blk-throttle.h | 9 +++++++++
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index dbee14c70981..bb7f6ef84e44 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -851,6 +851,9 @@ static void blkcg_rstat_flush(struct cgroup_subsys_state *css, int cpu)
 	struct blkcg *blkcg = css_to_blkcg(css);
 	struct blkcg_gq *blkg;
 
+	if (!cgroup_subsys_on_dfl(io_cgrp_subsys))
+		return;
+
 	/* Root-level stats are sourced from system-wide IO stats */
 	if (!cgroup_parent(css->cgroup))
 		return;
@@ -2013,8 +2016,7 @@ void blk_cgroup_bio_start(struct bio *bio)
 	bis->cur.ios[rwd]++;
 
 	u64_stats_update_end_irqrestore(&bis->sync, flags);
-	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 acdd85a07f92..de3c79fce829 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -2091,12 +2091,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);
diff --git a/block/blk-throttle.h b/block/blk-throttle.h
index ee7299e6dea9..19c478e5604a 100644
--- a/block/blk-throttle.h
+++ b/block/blk-throttle.h
@@ -174,6 +174,15 @@ static inline bool blk_throtl_bio(struct bio *bio)
 {
 	struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
 
+	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);
+	}
+
 	/* no need to throttle bps any more if the bio has been throttled */
 	if (bio_flagged(bio, BIO_BPS_THROTTLED) &&
 	    !(tg->flags & THROTL_TG_HAS_IOPS_LIMIT))
-- 
2.39.2




More information about the kernel-team mailing list