Skip to content

Commit 32ee5bc

Browse files
rhvgoyalhtejun
authored andcommitted
blk-throttle: Account for child group's start time in parent while bio climbs up
With the planned proper hierarchy support, a bio will climb up the tree before actually being dispatched. This makes sure bio is also subjected to parent's throttling limits, if any. It might happen that parent is idle and when bio is transferred to parent, a new slice starts fresh. But that is incorrect as parents wait time should have started when bio was queued in child group and causes IOs to be throttled more than configured as they climb the hierarchy. Given the fact that we have not written hierarchical algorithm in a way where child's and parents time slices are synchronized, we transfer the child's start time to parent if parent was idling. If parent was busy doing dispatch of other bios all this while, this is not an issue. Child's slice start time is passed to parent. Parent looks at its last expired slice start time. If child's start time is after parents old start time, that means parent had been idle and after parent went idle, child had an IO queued. So use child's start time as parent start time. If parent's start time is after child's start time, that means, when IO got queued in child group, parent was not idle. But later it dispatched some IO, its slice got trimmed and then it went idle. After a while child's request got shifted in parent group. In this case use parent's old start time as new start time as that's the duration of slice we did not use. This logic is far from perfect as if there are multiple childs then first child transferring the bio decides the start time while a bio might have queued up even earlier in other child, which is yet to be transferred up to parent. In that case we will lose time and bandwidth in parent. This patch is just an approximation to make situation somewhat better. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent c5cc207 commit 32ee5bc

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,28 @@ static bool throtl_schedule_next_dispatch(struct throtl_service_queue *sq,
633633
return false;
634634
}
635635

636+
static inline void throtl_start_new_slice_with_credit(struct throtl_grp *tg,
637+
bool rw, unsigned long start)
638+
{
639+
tg->bytes_disp[rw] = 0;
640+
tg->io_disp[rw] = 0;
641+
642+
/*
643+
* Previous slice has expired. We must have trimmed it after last
644+
* bio dispatch. That means since start of last slice, we never used
645+
* that bandwidth. Do try to make use of that bandwidth while giving
646+
* credit.
647+
*/
648+
if (time_after_eq(start, tg->slice_start[rw]))
649+
tg->slice_start[rw] = start;
650+
651+
tg->slice_end[rw] = jiffies + throtl_slice;
652+
throtl_log(&tg->service_queue,
653+
"[%c] new slice with credit start=%lu end=%lu jiffies=%lu",
654+
rw == READ ? 'R' : 'W', tg->slice_start[rw],
655+
tg->slice_end[rw], jiffies);
656+
}
657+
636658
static inline void throtl_start_new_slice(struct throtl_grp *tg, bool rw)
637659
{
638660
tg->bytes_disp[rw] = 0;
@@ -992,6 +1014,16 @@ static void tg_update_disptime(struct throtl_grp *tg)
9921014
tg->flags &= ~THROTL_TG_WAS_EMPTY;
9931015
}
9941016

1017+
static void start_parent_slice_with_credit(struct throtl_grp *child_tg,
1018+
struct throtl_grp *parent_tg, bool rw)
1019+
{
1020+
if (throtl_slice_used(parent_tg, rw)) {
1021+
throtl_start_new_slice_with_credit(parent_tg, rw,
1022+
child_tg->slice_start[rw]);
1023+
}
1024+
1025+
}
1026+
9951027
static void tg_dispatch_one_bio(struct throtl_grp *tg, bool rw)
9961028
{
9971029
struct throtl_service_queue *sq = &tg->service_queue;
@@ -1020,6 +1052,7 @@ static void tg_dispatch_one_bio(struct throtl_grp *tg, bool rw)
10201052
*/
10211053
if (parent_tg) {
10221054
throtl_add_bio_tg(bio, &tg->qnode_on_parent[rw], parent_tg);
1055+
start_parent_slice_with_credit(tg, parent_tg, rw);
10231056
} else {
10241057
throtl_qnode_add_bio(bio, &tg->qnode_on_parent[rw],
10251058
&parent_sq->queued[rw]);

0 commit comments

Comments
 (0)