Skip to content

Commit 591f69d

Browse files
brookxu-txgregkh
authored andcommitted
blk-throtl: optimize IOPS throttle for large IO scenarios
[ Upstream commit 4f1e963 ] After patch 54efd50 (block: make generic_make_request handle arbitrarily sized bios), the IO through io-throttle may be larger, and these IOs may be further split into more small IOs. However, IOPS throttle does not seem to be aware of this change, which makes the calculation of IOPS of large IOs incomplete, resulting in disk-side IOPS that does not meet expectations. Maybe we should fix this problem. We can reproduce it by set max_sectors_kb of disk to 128, set blkio.write_iops_throttle to 100, run a dd instance inside blkio and use iostat to watch IOPS: dd if=/dev/zero of=/dev/sdb bs=1M count=1000 oflag=direct As a result, without this change the average IOPS is 1995, with this change the IOPS is 98. Signed-off-by: Chunguang Xu <brookxu@tencent.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/65869aaad05475797d63b4c3fed4f529febe3c26.1627876014.git.brookxu@tencent.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cf13537 commit 591f69d

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎block/blk-merge.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ void __blk_queue_split(struct bio **bio, unsigned int *nr_segs)
341341
trace_block_split(q, split, (*bio)->bi_iter.bi_sector);
342342
submit_bio_noacct(*bio);
343343
*bio = split;
344+
345+
blk_throtl_charge_bio_split(*bio);
344346
}
345347
}
346348

‎block/blk-throttle.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ struct throtl_grp {
178178
unsigned int bad_bio_cnt; /* bios exceeding latency threshold */
179179
unsigned long bio_cnt_reset_time;
180180

181+
atomic_t io_split_cnt[2];
182+
atomic_t last_io_split_cnt[2];
183+
181184
struct blkg_rwstat stat_bytes;
182185
struct blkg_rwstat stat_ios;
183186
};
@@ -771,6 +774,8 @@ static inline void throtl_start_new_slice_with_credit(struct throtl_grp *tg,
771774
tg->bytes_disp[rw] = 0;
772775
tg->io_disp[rw] = 0;
773776

777+
atomic_set(&tg->io_split_cnt[rw], 0);
778+
774779
/*
775780
* Previous slice has expired. We must have trimmed it after last
776781
* bio dispatch. That means since start of last slice, we never used
@@ -793,6 +798,9 @@ static inline void throtl_start_new_slice(struct throtl_grp *tg, bool rw)
793798
tg->io_disp[rw] = 0;
794799
tg->slice_start[rw] = jiffies;
795800
tg->slice_end[rw] = jiffies + tg->td->throtl_slice;
801+
802+
atomic_set(&tg->io_split_cnt[rw], 0);
803+
796804
throtl_log(&tg->service_queue,
797805
"[%c] new slice start=%lu end=%lu jiffies=%lu",
798806
rw == READ ? 'R' : 'W', tg->slice_start[rw],
@@ -1025,6 +1033,9 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio,
10251033
jiffies + tg->td->throtl_slice);
10261034
}
10271035

1036+
if (iops_limit != UINT_MAX)
1037+
tg->io_disp[rw] += atomic_xchg(&tg->io_split_cnt[rw], 0);
1038+
10281039
if (tg_with_in_bps_limit(tg, bio, bps_limit, &bps_wait) &&
10291040
tg_with_in_iops_limit(tg, bio, iops_limit, &iops_wait)) {
10301041
if (wait)
@@ -2046,12 +2057,14 @@ static void throtl_downgrade_check(struct throtl_grp *tg)
20462057
}
20472058

20482059
if (tg->iops[READ][LIMIT_LOW]) {
2060+
tg->last_io_disp[READ] += atomic_xchg(&tg->last_io_split_cnt[READ], 0);
20492061
iops = tg->last_io_disp[READ] * HZ / elapsed_time;
20502062
if (iops >= tg->iops[READ][LIMIT_LOW])
20512063
tg->last_low_overflow_time[READ] = now;
20522064
}
20532065

20542066
if (tg->iops[WRITE][LIMIT_LOW]) {
2067+
tg->last_io_disp[WRITE] += atomic_xchg(&tg->last_io_split_cnt[WRITE], 0);
20552068
iops = tg->last_io_disp[WRITE] * HZ / elapsed_time;
20562069
if (iops >= tg->iops[WRITE][LIMIT_LOW])
20572070
tg->last_low_overflow_time[WRITE] = now;
@@ -2170,6 +2183,25 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td)
21702183
}
21712184
#endif
21722185

2186+
void blk_throtl_charge_bio_split(struct bio *bio)
2187+
{
2188+
struct blkcg_gq *blkg = bio->bi_blkg;
2189+
struct throtl_grp *parent = blkg_to_tg(blkg);
2190+
struct throtl_service_queue *parent_sq;
2191+
bool rw = bio_data_dir(bio);
2192+
2193+
do {
2194+
if (!parent->has_rules[rw])
2195+
break;
2196+
2197+
atomic_inc(&parent->io_split_cnt[rw]);
2198+
atomic_inc(&parent->last_io_split_cnt[rw]);
2199+
2200+
parent_sq = parent->service_queue.parent_sq;
2201+
parent = sq_to_tg(parent_sq);
2202+
} while (parent);
2203+
}
2204+
21732205
bool blk_throtl_bio(struct bio *bio)
21742206
{
21752207
struct request_queue *q = bio->bi_disk->queue;

‎block/blk.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,13 @@ int create_task_io_context(struct task_struct *task, gfp_t gfp_mask, int node);
299299
extern int blk_throtl_init(struct request_queue *q);
300300
extern void blk_throtl_exit(struct request_queue *q);
301301
extern void blk_throtl_register_queue(struct request_queue *q);
302+
extern void blk_throtl_charge_bio_split(struct bio *bio);
302303
bool blk_throtl_bio(struct bio *bio);
303304
#else /* CONFIG_BLK_DEV_THROTTLING */
304305
static inline int blk_throtl_init(struct request_queue *q) { return 0; }
305306
static inline void blk_throtl_exit(struct request_queue *q) { }
306307
static inline void blk_throtl_register_queue(struct request_queue *q) { }
308+
static inline void blk_throtl_charge_bio_split(struct bio *bio) { }
307309
static inline bool blk_throtl_bio(struct bio *bio) { return false; }
308310
#endif /* CONFIG_BLK_DEV_THROTTLING */
309311
#ifdef CONFIG_BLK_DEV_THROTTLING_LOW

0 commit comments

Comments
 (0)