Skip to content

Commit b5e02b4

Browse files
Algodev-githubaxboe
authored andcommitted
block, bfq: check also in-flight I/O in dispatch plugging
Consider a sync bfq_queue Q that remains empty while in service, and suppose that, when this happens, there is a fair amount of already in-flight I/O not belonging to Q. In such a situation, I/O dispatching may need to be plugged (until new I/O arrives for Q), for the following reason. The drive may decide to serve in-flight non-Q's I/O requests before Q's ones, thereby delaying the arrival of new I/O requests for Q (recall that Q is sync). If I/O-dispatching is not plugged, then, while Q remains empty, a basically uncontrolled amount of I/O from other queues may be dispatched too, possibly causing the service of Q's I/O to be delayed even longer in the drive. This problem gets more and more serious as the speed and the queue depth of the drive grow, because, as these two quantities grow, the probability to find no queue busy but many requests in flight grows too. If Q has the same weight and priority as the other queues, then the above delay is unlikely to cause any issue, because all queues tend to undergo the same treatment. So, since not plugging I/O dispatching is convenient for throughput, it is better not to plug. Things change in case Q has a higher weight or priority than some other queue, because Q's service guarantees may simply be violated. For this reason, commit 1de0c4c ("block, bfq: reduce idling only in symmetric scenarios") does plug I/O in such an asymmetric scenario. Plugging minimizes the delay induced by already in-flight I/O, and enables Q to recover the bandwidth it may lose because of this delay. Yet the above commit does not cover the case of weight-raised queues, for efficiency concerns. For weight-raised queues, I/O-dispatch plugging is activated simply if not all bfq_queues are weight-raised. But this check does not handle the case of in-flight requests, because a bfq_queue may become non busy *before* all its in-flight requests are completed. This commit performs I/O-dispatch plugging for weight-raised queues if there are some in-flight requests. As a practical example of the resulting recover of control, under write load on a Samsung SSD 970 PRO, gnome-terminal starts in 1.5 seconds after this fix, against 15 seconds before the fix (as a reference, gnome-terminal takes about 35 seconds to start with any of the other I/O schedulers). Fixes: 1de0c4c ("block, bfq: reduce idling only in symmetric scenarios") Signed-off-by: Paolo Valente <paolo.valente@linaro.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1624b0b commit b5e02b4

1 file changed

Lines changed: 43 additions & 24 deletions

File tree

‎block/bfq-iosched.c‎

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,38 +3354,57 @@ static void bfq_dispatch_remove(struct request_queue *q, struct request *rq)
33543354
* there is no active group, then the primary expectation for
33553355
* this device is probably a high throughput.
33563356
*
3357-
* We are now left only with explaining the additional
3358-
* compound condition that is checked below for deciding
3359-
* whether the scenario is asymmetric. To explain this
3360-
* compound condition, we need to add that the function
3357+
* We are now left only with explaining the two sub-conditions in the
3358+
* additional compound condition that is checked below for deciding
3359+
* whether the scenario is asymmetric. To explain the first
3360+
* sub-condition, we need to add that the function
33613361
* bfq_asymmetric_scenario checks the weights of only
3362-
* non-weight-raised queues, for efficiency reasons (see
3363-
* comments on bfq_weights_tree_add()). Then the fact that
3364-
* bfqq is weight-raised is checked explicitly here. More
3365-
* precisely, the compound condition below takes into account
3366-
* also the fact that, even if bfqq is being weight-raised,
3367-
* the scenario is still symmetric if all queues with requests
3368-
* waiting for completion happen to be
3369-
* weight-raised. Actually, we should be even more precise
3370-
* here, and differentiate between interactive weight raising
3371-
* and soft real-time weight raising.
3362+
* non-weight-raised queues, for efficiency reasons (see comments on
3363+
* bfq_weights_tree_add()). Then the fact that bfqq is weight-raised
3364+
* is checked explicitly here. More precisely, the compound condition
3365+
* below takes into account also the fact that, even if bfqq is being
3366+
* weight-raised, the scenario is still symmetric if all queues with
3367+
* requests waiting for completion happen to be
3368+
* weight-raised. Actually, we should be even more precise here, and
3369+
* differentiate between interactive weight raising and soft real-time
3370+
* weight raising.
3371+
*
3372+
* The second sub-condition checked in the compound condition is
3373+
* whether there is a fair amount of already in-flight I/O not
3374+
* belonging to bfqq. If so, I/O dispatching is to be plugged, for the
3375+
* following reason. The drive may decide to serve in-flight
3376+
* non-bfqq's I/O requests before bfqq's ones, thereby delaying the
3377+
* arrival of new I/O requests for bfqq (recall that bfqq is sync). If
3378+
* I/O-dispatching is not plugged, then, while bfqq remains empty, a
3379+
* basically uncontrolled amount of I/O from other queues may be
3380+
* dispatched too, possibly causing the service of bfqq's I/O to be
3381+
* delayed even longer in the drive. This problem gets more and more
3382+
* serious as the speed and the queue depth of the drive grow,
3383+
* because, as these two quantities grow, the probability to find no
3384+
* queue busy but many requests in flight grows too. By contrast,
3385+
* plugging I/O dispatching minimizes the delay induced by already
3386+
* in-flight I/O, and enables bfqq to recover the bandwidth it may
3387+
* lose because of this delay.
33723388
*
33733389
* As a side note, it is worth considering that the above
3374-
* device-idling countermeasures may however fail in the
3375-
* following unlucky scenario: if idling is (correctly)
3376-
* disabled in a time period during which all symmetry
3377-
* sub-conditions hold, and hence the device is allowed to
3378-
* enqueue many requests, but at some later point in time some
3379-
* sub-condition stops to hold, then it may become impossible
3380-
* to let requests be served in the desired order until all
3381-
* the requests already queued in the device have been served.
3390+
* device-idling countermeasures may however fail in the following
3391+
* unlucky scenario: if I/O-dispatch plugging is (correctly) disabled
3392+
* in a time period during which all symmetry sub-conditions hold, and
3393+
* therefore the device is allowed to enqueue many requests, but at
3394+
* some later point in time some sub-condition stops to hold, then it
3395+
* may become impossible to make requests be served in the desired
3396+
* order until all the requests already queued in the device have been
3397+
* served. The last sub-condition commented above somewhat mitigates
3398+
* this problem for weight-raised queues.
33823399
*/
33833400
static bool idling_needed_for_service_guarantees(struct bfq_data *bfqd,
33843401
struct bfq_queue *bfqq)
33853402
{
33863403
return (bfqq->wr_coeff > 1 &&
3387-
bfqd->wr_busy_queues <
3388-
bfq_tot_busy_queues(bfqd)) ||
3404+
(bfqd->wr_busy_queues <
3405+
bfq_tot_busy_queues(bfqd) ||
3406+
bfqd->rq_in_driver >=
3407+
bfqq->dispatched + 4)) ||
33893408
bfq_asymmetric_scenario(bfqd, bfqq);
33903409
}
33913410

0 commit comments

Comments
 (0)