Skip to content

Commit eead005

Browse files
YuKuai-huaweiaxboe
authored andcommitted
blk-throttle: consider 'carryover_ios/bytes' in throtl_trim_slice()
Currently, 'carryover_ios/bytes' is not handled in throtl_trim_slice(), for consequence, 'carryover_ios/bytes' will be used to throttle bio multiple times, for example: 1) set iops limit to 100, and slice start is 0, slice end is 100ms; 2) current time is 0, and 10 ios are dispatched, those io won't be throttled and io_disp is 10; 3) still at current time 0, update iops limit to 1000, carryover_ios is updated to (0 - 10) = -10; 4) in this slice(0 - 100ms), io_allowed = 100 + (-10) = 90, which means only 90 ios can be dispatched without waiting; 5) assume that io is throttled in slice(0 - 100ms), and throtl_trim_slice() update silce to (100ms - 200ms). In this case, 'carryover_ios/bytes' is not cleared and still only 90 ios can be dispatched between 100ms - 200ms. Fix this problem by updating 'carryover_ios/bytes' in throtl_trim_slice(). Fixes: a880ae9 ("blk-throttle: fix io hung due to configuration updates") Reported-by: zhuxiaohui <zhuxiaohui.400@bytedance.com> Link: https://lore.kernel.org/all/20230812072116.42321-1-zhuxiaohui.400@bytedance.com/ Signed-off-by: Yu Kuai <yukuai3@huawei.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20230816012708.1193747-5-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e8368b5 commit eead005

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

block/blk-throttle.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,9 @@ static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
729729
/* Trim the used slices and adjust slice start accordingly */
730730
static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
731731
{
732-
unsigned long time_elapsed, io_trim;
733-
u64 bytes_trim;
732+
unsigned long time_elapsed;
733+
long long bytes_trim;
734+
int io_trim;
734735

735736
BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
736737

@@ -758,25 +759,29 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
758759
return;
759760

760761
bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
761-
time_elapsed);
762-
io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed);
763-
if (!bytes_trim && !io_trim)
762+
time_elapsed) +
763+
tg->carryover_bytes[rw];
764+
io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed) +
765+
tg->carryover_ios[rw];
766+
if (bytes_trim <= 0 && io_trim <= 0)
764767
return;
765768

766-
if (tg->bytes_disp[rw] >= bytes_trim)
769+
tg->carryover_bytes[rw] = 0;
770+
if ((long long)tg->bytes_disp[rw] >= bytes_trim)
767771
tg->bytes_disp[rw] -= bytes_trim;
768772
else
769773
tg->bytes_disp[rw] = 0;
770774

771-
if (tg->io_disp[rw] >= io_trim)
775+
tg->carryover_ios[rw] = 0;
776+
if ((int)tg->io_disp[rw] >= io_trim)
772777
tg->io_disp[rw] -= io_trim;
773778
else
774779
tg->io_disp[rw] = 0;
775780

776781
tg->slice_start[rw] += time_elapsed;
777782

778783
throtl_log(&tg->service_queue,
779-
"[%c] trim slice nr=%lu bytes=%llu io=%lu start=%lu end=%lu jiffies=%lu",
784+
"[%c] trim slice nr=%lu bytes=%lld io=%d start=%lu end=%lu jiffies=%lu",
780785
rw == READ ? 'R' : 'W', time_elapsed / tg->td->throtl_slice,
781786
bytes_trim, io_trim, tg->slice_start[rw], tg->slice_end[rw],
782787
jiffies);

0 commit comments

Comments
 (0)