Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 81c7a63

Browse files
YuKuai-huaweiaxboe
authored andcommitted
blk-throttle: improve bypassing bios checkings
"tg->has_rules" is extended to "tg->has_rules_iops/bps", thus bios that don't need to be throttled can be checked accurately. With this patch, bio will be throttled if: 1) Bio is read/write, and corresponding read/write iops limit exist. 2) If corresponding doesn't exist, corresponding bps limit exist and bio is not throttled before. Signed-off-by: Yu Kuai <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 8549674 commit 81c7a63

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

block/blk-throttle.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,16 @@ static void tg_update_has_rules(struct throtl_grp *tg)
421421
struct throtl_data *td = tg->td;
422422
int rw;
423423

424-
for (rw = READ; rw <= WRITE; rw++)
425-
tg->has_rules[rw] = (parent_tg && parent_tg->has_rules[rw]) ||
424+
for (rw = READ; rw <= WRITE; rw++) {
425+
tg->has_rules_iops[rw] =
426+
(parent_tg && parent_tg->has_rules_iops[rw]) ||
426427
(td->limit_valid[td->limit_index] &&
427-
(tg_bps_limit(tg, rw) != U64_MAX ||
428-
tg_iops_limit(tg, rw) != UINT_MAX));
428+
tg_iops_limit(tg, rw) != UINT_MAX);
429+
tg->has_rules_bps[rw] =
430+
(parent_tg && parent_tg->has_rules_bps[rw]) ||
431+
(td->limit_valid[td->limit_index] &&
432+
(tg_bps_limit(tg, rw) != U64_MAX));
433+
}
429434
}
430435

431436
static void throtl_pd_online(struct blkg_policy_data *pd)

block/blk-throttle.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ struct throtl_grp {
9898
unsigned int flags;
9999

100100
/* are there any throtl rules between this group and td? */
101-
bool has_rules[2];
101+
bool has_rules_bps[2];
102+
bool has_rules_iops[2];
102103

103104
/* internally used bytes per second rate limits */
104105
uint64_t bps[2][LIMIT_CNT];
@@ -178,11 +179,26 @@ void blk_throtl_exit(struct request_queue *q);
178179
void blk_throtl_register_queue(struct request_queue *q);
179180
bool __blk_throtl_bio(struct bio *bio);
180181
void blk_throtl_cancel_bios(struct request_queue *q);
181-
static inline bool blk_throtl_bio(struct bio *bio)
182+
183+
static inline bool blk_should_throtl(struct bio *bio)
182184
{
183185
struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
186+
int rw = bio_data_dir(bio);
187+
188+
/* iops limit is always counted */
189+
if (tg->has_rules_iops[rw])
190+
return true;
191+
192+
if (tg->has_rules_bps[rw] && !bio_flagged(bio, BIO_BPS_THROTTLED))
193+
return true;
194+
195+
return false;
196+
}
197+
198+
static inline bool blk_throtl_bio(struct bio *bio)
199+
{
184200

185-
if (!tg->has_rules[bio_data_dir(bio)])
201+
if (!blk_should_throtl(bio))
186202
return false;
187203

188204
return __blk_throtl_bio(bio);

0 commit comments

Comments
 (0)