Skip to content

Commit 9f5ede3

Browse files
Ming Leiaxboe
authored andcommitted
block: throttle split bio in case of iops limit
Commit 111be88 ("block-throttle: avoid double charge") marks bio as BIO_THROTTLED unconditionally if __blk_throtl_bio() is called on this bio, then this bio won't be called into __blk_throtl_bio() any more. This way is to avoid double charge in case of bio splitting. It is reasonable for read/write throughput limit, but not reasonable for IOPS limit because block layer provides io accounting against split bio. Chunguang Xu has already observed this issue and fixed it in commit 4f1e963 ("blk-throtl: optimize IOPS throttle for large IO scenarios"). However, that patch only covers bio splitting in __blk_queue_split(), and we have other kind of bio splitting, such as bio_split() & submit_bio_noacct() and other ways. This patch tries to fix the issue in one generic way by always charging the bio for iops limit in blk_throtl_bio(). This way is reasonable: re-submission & fast-cloned bio is charged if it is submitted to same disk/queue, and BIO_THROTTLED will be cleared if bio->bi_bdev is changed. This new approach can get much more smooth/stable iops limit compared with commit 4f1e963 ("blk-throtl: optimize IOPS throttle for large IO scenarios") since that commit can't throttle current split bios actually. Also this way won't cause new double bio iops charge in blk_throtl_dispatch_work_fn() in which blk_throtl_bio() won't be called any more. Reported-by: Ning Li <lining2020x@163.com> Acked-by: Tejun Heo <tj@kernel.org> Cc: Chunguang Xu <brookxu@tencent.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20220216044514.2903784-7-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d24c670 commit 9f5ede3

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

block/blk-merge.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ void __blk_queue_split(struct request_queue *q, struct bio **bio,
368368
trace_block_split(split, (*bio)->bi_iter.bi_sector);
369369
submit_bio_noacct(*bio);
370370
*bio = split;
371-
372-
blk_throtl_charge_bio_split(*bio);
373371
}
374372
}
375373

block/blk-throttle.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
807807
unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
808808
unsigned int bio_size = throtl_bio_data_size(bio);
809809

810-
if (bps_limit == U64_MAX) {
810+
/* no need to throttle if this bio's bytes have been accounted */
811+
if (bps_limit == U64_MAX || bio_flagged(bio, BIO_THROTTLED)) {
811812
if (wait)
812813
*wait = 0;
813814
return true;
@@ -919,9 +920,12 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
919920
unsigned int bio_size = throtl_bio_data_size(bio);
920921

921922
/* Charge the bio to the group */
922-
tg->bytes_disp[rw] += bio_size;
923+
if (!bio_flagged(bio, BIO_THROTTLED)) {
924+
tg->bytes_disp[rw] += bio_size;
925+
tg->last_bytes_disp[rw] += bio_size;
926+
}
927+
923928
tg->io_disp[rw]++;
924-
tg->last_bytes_disp[rw] += bio_size;
925929
tg->last_io_disp[rw]++;
926930

927931
/*

block/blk-throttle.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ static inline bool blk_throtl_bio(struct bio *bio)
170170
{
171171
struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
172172

173-
if (bio_flagged(bio, BIO_THROTTLED))
174-
return false;
175173
if (!tg->has_rules[bio_data_dir(bio)])
176174
return false;
177175

0 commit comments

Comments
 (0)