Skip to content

Commit 1f57f8d

Browse files
committed
blk-mq: don't queue more if we get a busy return
Some devices have different queue limits depending on the type of IO. A classic case is SATA NCQ, where some commands can queue, but others cannot. If we have NCQ commands inflight and encounter a non-queueable command, the driver returns busy. Currently we attempt to dispatch more from the scheduler, if we were able to queue some commands. But for the case where we ended up stopping due to BUSY, we should not attempt to retrieve more from the scheduler. If we do, we can get into a situation where we attempt to queue a non-queueable command, get BUSY, then successfully retrieve more commands from that scheduler and queue those. This can repeat forever, starving the non-queuable command indefinitely. Fix this by NOT attempting to pull more commands from the scheduler, if we get a BUSY return. This should also be more optimal in terms of letting requests stay in the scheduler for as long as possible, if we get a BUSY due to the regular out-of-tags condition. Reviewed-by: Omar Sandoval <[email protected]> Reviewed-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 297ba57 commit 1f57f8d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

block/blk-mq.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,9 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx **hctx,
10751075

10761076
#define BLK_MQ_RESOURCE_DELAY 3 /* ms units */
10771077

1078+
/*
1079+
* Returns true if we did some work AND can potentially do more.
1080+
*/
10781081
bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
10791082
bool got_budget)
10801083
{
@@ -1205,8 +1208,17 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
12051208
blk_mq_run_hw_queue(hctx, true);
12061209
else if (needs_restart && (ret == BLK_STS_RESOURCE))
12071210
blk_mq_delay_run_hw_queue(hctx, BLK_MQ_RESOURCE_DELAY);
1211+
1212+
return false;
12081213
}
12091214

1215+
/*
1216+
* If the host/device is unable to accept more work, inform the
1217+
* caller of that.
1218+
*/
1219+
if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE)
1220+
return false;
1221+
12101222
return (queued + errors) != 0;
12111223
}
12121224

0 commit comments

Comments
 (0)