Skip to content

Commit 29cb955

Browse files
YuKuai-huaweiaxboe
authored andcommitted
blk-throttle: fix lower bps rate by throtl_trim_slice()
The bio submission time may be a few jiffies more than the expected waiting time, due to 'extra_bytes' can't be divided in tg_within_bps_limit(), and also due to timer wakeup delay. In this case, adjust slice_start to jiffies will discard the extra wait time, causing lower rate than expected. Current in-tree code already covers deviation by rounddown(), but turns out it is not enough, because jiffies - slice_start can be a multiple of throtl_slice. For example, assume bps_limit is 1000bytes, 1 jiffes is 10ms, and slice is 20ms(2 jiffies), expected rate is 1000 / 1000 * 20 = 20 bytes per slice. If user issues two 21 bytes IO, then wait time will be 30ms for the first IO: bytes_allowed = 20, extra_bytes = 1; jiffy_wait = 1 + 2 = 3 jiffies and consider extra 1 jiffies by timer, throtl_trim_slice() will be called at: jiffies = 40ms slice_start = 0ms, slice_end= 40ms bytes_disp = 21 In this case, before the patch, real rate in the first two slices is 10.5 bytes per slice, and slice will be updated to: jiffies = 40ms slice_start = 40ms, slice_end = 60ms, bytes_disp = 0; Hence the second IO will have to wait another 30ms; With the patch, the real rate in the first slice is 20 bytes per slice, which is the same as expected, and slice will be updated: jiffies=40ms, slice_start = 20ms, slice_end = 60ms, bytes_disp = 1; And now, there is still 19 bytes allowed in the second slice, and the second IO will only have to wait 10ms; This problem will cause blktests throtl/001 failure in case of CONFIG_HZ_100=y, fix it by preserving one extra finished slice in throtl_trim_slice(). Fixes: e43473b ("blkio: Core implementation of throttle policy") Reported-by: Ming Lei <[email protected]> Closes: https://lore.kernel.org/linux-block/[email protected]/ Reviewed-by: Ming Lei <[email protected]> Acked-by: Tejun Heo <[email protected]> Signed-off-by: Yu Kuai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 80bdfbb commit 29cb955

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

block/blk-throttle.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,23 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
599599
* sooner, then we need to reduce slice_end. A high bogus slice_end
600600
* is bad because it does not allow new slice to start.
601601
*/
602-
603602
throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice);
604603

605604
time_elapsed = rounddown(jiffies - tg->slice_start[rw],
606605
tg->td->throtl_slice);
607-
if (!time_elapsed)
606+
/* Don't trim slice until at least 2 slices are used */
607+
if (time_elapsed < tg->td->throtl_slice * 2)
608608
return;
609609

610+
/*
611+
* The bio submission time may be a few jiffies more than the expected
612+
* waiting time, due to 'extra_bytes' can't be divided in
613+
* tg_within_bps_limit(), and also due to timer wakeup delay. In this
614+
* case, adjust slice_start will discard the extra wait time, causing
615+
* lower rate than expected. Therefore, other than the above rounddown,
616+
* one extra slice is preserved for deviation.
617+
*/
618+
time_elapsed -= tg->td->throtl_slice;
610619
bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
611620
time_elapsed) +
612621
tg->carryover_bytes[rw];

0 commit comments

Comments
 (0)