|
| 1 | +From 4c5b35e202a3dd2c0d0bf0715c695ef3cc6d902e Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jinke Han < [email protected]> |
| 3 | +Date: Mon, 8 May 2023 01:06:31 +0800 |
| 4 | +Subject: [PATCH] blk-throttle: Fix io statistics for cgroup v1 |
| 5 | + |
| 6 | +After commit f382fb0bcef4 ("block: remove legacy IO schedulers"), |
| 7 | +blkio.throttle.io_serviced and blkio.throttle.io_service_bytes become |
| 8 | +the only stable io stats interface of cgroup v1, and these statistics |
| 9 | +are done in the blk-throttle code. But the current code only counts the |
| 10 | +bios that are actually throttled. When the user does not add the throttle |
| 11 | +limit, the io stats for cgroup v1 has nothing. I fix it according to the |
| 12 | +statistical method of v2, and made it count all ios accurately. |
| 13 | + |
| 14 | +Fixes: a7b36ee6ba29 ("block: move blk-throtl fast path inline") |
| 15 | +Tested-by: Andrea Righi < [email protected]> |
| 16 | +Signed-off-by: Jinke Han < [email protected]> |
| 17 | +Acked-by: Muchun Song < [email protected]> |
| 18 | +Acked-by: Tejun Heo < [email protected]> |
| 19 | +Link: https://lore.kernel.org/r/ [email protected] |
| 20 | +Signed-off-by: Jens Axboe < [email protected]> |
| 21 | +[bcressey: |
| 22 | + - backport to 6.1 |
| 23 | + - adjust context in blk_cgroup_bio_start |
| 24 | + - avoid changes from 3b8cc629 ("blk-cgroup: Optimize blkcg_rstat_flush()")] |
| 25 | +Signed-off-by: Ben Cressey < [email protected]> |
| 26 | +--- |
| 27 | + block/blk-cgroup.c | 6 ++++-- |
| 28 | + block/blk-throttle.c | 6 ------ |
| 29 | + block/blk-throttle.h | 9 +++++++++ |
| 30 | + 3 files changed, 13 insertions(+), 8 deletions(-) |
| 31 | + |
| 32 | +diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c |
| 33 | +index 1b7fd1fc2f33..435432c4a62e 100644 |
| 34 | +--- a/block/blk-cgroup.c |
| 35 | ++++ b/block/blk-cgroup.c |
| 36 | +@@ -1969,6 +1969,9 @@ void blk_cgroup_bio_start(struct bio *bio) |
| 37 | + struct blkg_iostat_set *bis; |
| 38 | + unsigned long flags; |
| 39 | + |
| 40 | ++ if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) |
| 41 | ++ return; |
| 42 | ++ |
| 43 | + cpu = get_cpu(); |
| 44 | + bis = per_cpu_ptr(bio->bi_blkg->iostat_cpu, cpu); |
| 45 | + flags = u64_stats_update_begin_irqsave(&bis->sync); |
| 46 | +@@ -1984,8 +1987,7 @@ void blk_cgroup_bio_start(struct bio *bio) |
| 47 | + bis->cur.ios[rwd]++; |
| 48 | + |
| 49 | + u64_stats_update_end_irqrestore(&bis->sync, flags); |
| 50 | +- if (cgroup_subsys_on_dfl(io_cgrp_subsys)) |
| 51 | +- cgroup_rstat_updated(bio->bi_blkg->blkcg->css.cgroup, cpu); |
| 52 | ++ cgroup_rstat_updated(bio->bi_blkg->blkcg->css.cgroup, cpu); |
| 53 | + put_cpu(); |
| 54 | + } |
| 55 | + |
| 56 | +diff --git a/block/blk-throttle.c b/block/blk-throttle.c |
| 57 | +index 62a3f62316df..ab847abe30b0 100644 |
| 58 | +--- a/block/blk-throttle.c |
| 59 | ++++ b/block/blk-throttle.c |
| 60 | +@@ -2176,12 +2176,6 @@ bool __blk_throtl_bio(struct bio *bio) |
| 61 | + |
| 62 | + rcu_read_lock(); |
| 63 | + |
| 64 | +- if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) { |
| 65 | +- blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf, |
| 66 | +- bio->bi_iter.bi_size); |
| 67 | +- blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1); |
| 68 | +- } |
| 69 | +- |
| 70 | + spin_lock_irq(&q->queue_lock); |
| 71 | + |
| 72 | + throtl_update_latency_buckets(td); |
| 73 | +diff --git a/block/blk-throttle.h b/block/blk-throttle.h |
| 74 | +index ef4b7a4de987..d1ccbfe9f797 100644 |
| 75 | +--- a/block/blk-throttle.h |
| 76 | ++++ b/block/blk-throttle.h |
| 77 | +@@ -185,6 +185,15 @@ static inline bool blk_should_throtl(struct bio *bio) |
| 78 | + struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg); |
| 79 | + int rw = bio_data_dir(bio); |
| 80 | + |
| 81 | ++ if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) { |
| 82 | ++ if (!bio_flagged(bio, BIO_CGROUP_ACCT)) { |
| 83 | ++ bio_set_flag(bio, BIO_CGROUP_ACCT); |
| 84 | ++ blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf, |
| 85 | ++ bio->bi_iter.bi_size); |
| 86 | ++ } |
| 87 | ++ blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1); |
| 88 | ++ } |
| 89 | ++ |
| 90 | + /* iops limit is always counted */ |
| 91 | + if (tg->has_rules_iops[rw]) |
| 92 | + return true; |
| 93 | +-- |
| 94 | +2.45.1 |
| 95 | + |
0 commit comments