[PATCH 1/1] blk-throttle: fix throttle configuring not effective

From: zhuxiaohui
Date: Sat Aug 12 2023 - 03:21:28 EST


when updating block throttle limit with persistence and stable io
pressure, especially a relative high io pressure, fio test e.g.,
there may never be a change to start a new slice, and carryover_ios &
carryover_bytes will not be cleared.

As a result, when reconfiguring block throttle limit, we can notice that
the actual iops and throughput is a random value far away from what is
set

So we need to update carryover value when dispatching bio

Signed-off-by: zhuxiaohui <zhuxiaohui.400@xxxxxxxxxxxxx>
---
block/blk-throttle.c | 26 ++++++++++++++++++++++++++
block/blk-throttle.h | 4 ++--
2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 7397ff199d66..13c9d87a7201 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -821,6 +821,30 @@ static void tg_update_carryover(struct throtl_grp *tg)
tg->carryover_ios[READ], tg->carryover_ios[WRITE]);
}

+static void tg_charge_carryover(struct throtl_grp *tg, struct bio *bio)
+{
+ bool rw = bio_data_dir(bio);
+
+ if (unlikely(tg->carryover_bytes[rw])) {
+ unsigned int bio_size = throtl_bio_data_size(bio);
+ unsigned int carryout_size = abs(tg->carryover_bytes[rw]);
+
+ carryout_size = min(carryout_size, bio_size);
+
+ if (tg->carryover_bytes[rw] < 0)
+ tg->carryover_bytes[rw] += carryout_size;
+ else
+ tg->carryover_bytes[rw] -= carryout_size;
+ }
+
+ if (unlikely(tg->carryover_ios[rw])) {
+ if (tg->carryover_ios[rw] < 0)
+ tg->carryover_ios[rw] += 1;
+ else
+ tg->carryover_ios[rw] -= 1;
+ }
+}
+
static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio,
u32 iops_limit)
{
@@ -965,6 +989,8 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)

tg->io_disp[rw]++;
tg->last_io_disp[rw]++;
+
+ tg_charge_carryover(tg, bio);
}

/**
diff --git a/block/blk-throttle.h b/block/blk-throttle.h
index d1ccbfe9f797..8f1642becb23 100644
--- a/block/blk-throttle.h
+++ b/block/blk-throttle.h
@@ -127,8 +127,8 @@ struct throtl_grp {
* bytes/ios are waited already in previous configuration, and they will
* be used to calculate wait time under new configuration.
*/
- uint64_t carryover_bytes[2];
- unsigned int carryover_ios[2];
+ int64_t carryover_bytes[2];
+ int carryover_ios[2];

unsigned long last_check_time;

--
2.39.2