Commit 81c7a63a authored by Yu Kuai's avatar Yu Kuai Committed by Jens Axboe

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: default avatarYu Kuai <yukuai3@huawei.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20220921095309.1481289-3-yukuai1@huaweicloud.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 85496749
...@@ -421,11 +421,16 @@ static void tg_update_has_rules(struct throtl_grp *tg) ...@@ -421,11 +421,16 @@ static void tg_update_has_rules(struct throtl_grp *tg)
struct throtl_data *td = tg->td; struct throtl_data *td = tg->td;
int rw; int rw;
for (rw = READ; rw <= WRITE; rw++) for (rw = READ; rw <= WRITE; rw++) {
tg->has_rules[rw] = (parent_tg && parent_tg->has_rules[rw]) || tg->has_rules_iops[rw] =
(parent_tg && parent_tg->has_rules_iops[rw]) ||
(td->limit_valid[td->limit_index] && (td->limit_valid[td->limit_index] &&
(tg_bps_limit(tg, rw) != U64_MAX || tg_iops_limit(tg, rw) != UINT_MAX);
tg_iops_limit(tg, rw) != UINT_MAX)); tg->has_rules_bps[rw] =
(parent_tg && parent_tg->has_rules_bps[rw]) ||
(td->limit_valid[td->limit_index] &&
(tg_bps_limit(tg, rw) != U64_MAX));
}
} }
static void throtl_pd_online(struct blkg_policy_data *pd) static void throtl_pd_online(struct blkg_policy_data *pd)
......
...@@ -98,7 +98,8 @@ struct throtl_grp { ...@@ -98,7 +98,8 @@ struct throtl_grp {
unsigned int flags; unsigned int flags;
/* are there any throtl rules between this group and td? */ /* are there any throtl rules between this group and td? */
bool has_rules[2]; bool has_rules_bps[2];
bool has_rules_iops[2];
/* internally used bytes per second rate limits */ /* internally used bytes per second rate limits */
uint64_t bps[2][LIMIT_CNT]; uint64_t bps[2][LIMIT_CNT];
...@@ -178,11 +179,26 @@ void blk_throtl_exit(struct request_queue *q); ...@@ -178,11 +179,26 @@ void blk_throtl_exit(struct request_queue *q);
void blk_throtl_register_queue(struct request_queue *q); void blk_throtl_register_queue(struct request_queue *q);
bool __blk_throtl_bio(struct bio *bio); bool __blk_throtl_bio(struct bio *bio);
void blk_throtl_cancel_bios(struct request_queue *q); void blk_throtl_cancel_bios(struct request_queue *q);
static inline bool blk_throtl_bio(struct bio *bio)
static inline bool blk_should_throtl(struct bio *bio)
{ {
struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg); struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
int rw = bio_data_dir(bio);
/* iops limit is always counted */
if (tg->has_rules_iops[rw])
return true;
if (tg->has_rules_bps[rw] && !bio_flagged(bio, BIO_BPS_THROTTLED))
return true;
return false;
}
static inline bool blk_throtl_bio(struct bio *bio)
{
if (!tg->has_rules[bio_data_dir(bio)]) if (!blk_should_throtl(bio))
return false; return false;
return __blk_throtl_bio(bio); return __blk_throtl_bio(bio);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment