Skip to contentSkip to conversation

blk-mq: don't insert passthrough request into sw queue

PATCH Applied Ming Lei 3 participants 3 messages Jun 21, 2023 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 blk-mq: don't insert passthrough request into sw queue

In case of real io scheduler, q->elevator is set, so blk_mq_run_hw_queue() may just check if scheduler queue has request to dispatch, see __blk_mq_sched_dispatch_requests(). Then IO hang may be caused because all passthorugh requests may stay in sw queue.

And any passthrough request should have been inserted to hctx->dispatch always.

Fixes d97217e7f024 ("blk-mq: don't queue plugged passthrough requests into scheduler")
---
 block/blk-mq.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
block/blk-mq.c +6 -1
index 4c02c28b4835..1628873d7587 100644
@@ -2750,7 +2750,12 @@ static void blk_mq_dispatch_plug_list(struct blk_plug *plug, bool from_sched)
 
 	percpu_ref_get(&this_hctx->queue->q_usage_counter);
 	/* passthrough requests should never be issued to the I/O scheduler */
-	if (this_hctx->queue->elevator && !is_passthrough) {
+	if (is_passthrough) {
+		spin_lock(&this_hctx->lock);
+		list_splice_tail_init(&list, &this_hctx->dispatch);
+		spin_unlock(&this_hctx->lock);
+		blk_mq_run_hw_queue(this_hctx, from_sched);
+	} else if (this_hctx->queue->elevator) {
 		this_hctx->queue->elevator->type->ops.insert_requests(this_hctx,
 				&list, 0);
 		blk_mq_run_hw_queue(this_hctx, from_sched);
Signature · 1 line
2.40.1
maintainer Applied
#1 lore raw
Quoted 9 lines · Ming Lei

In case of real io scheduler, q->elevator is set, so blk_mq_run_hw_queue() may just check if scheduler queue has request to dispatch, see __blk_mq_sched_dispatch_requests(). Then IO hang may be caused because all passthorugh requests may stay in sw queue.

And any passthrough request should have been inserted to hctx->dispatch always.

[...]

Applied, thanks!

[1/1] blk-mq: don't insert passthrough request into sw queue

      commit: 2293cae703cda162684ae966db6b1b4a11b5e88f

Best regards,

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Ming Lei

block/blk-mq.c static void blk_mq_dispatch_plug_list(struct blk_plug *plug, bool from_sched) · line 2761

Quoted 12 lines · Ming Lei

percpu_ref_get(&this_hctx->queue->q_usage_counter);
/* passthrough requests should never be issued to the I/O scheduler */

block/blk-mq.c +6 -1
-	if (this_hctx->queue->elevator && !is_passthrough) {
+	if (is_passthrough) {
+		spin_lock(&this_hctx->lock);
+		list_splice_tail_init(&list, &this_hctx->dispatch);
+		spin_unlock(&this_hctx->lock);
+		blk_mq_run_hw_queue(this_hctx, from_sched);
+	} else if (this_hctx->queue->elevator) {
  		this_hctx->queue->elevator->type->ops.insert_requests(this_hctx,
  				&list, 0);
  		blk_mq_run_hw_queue(this_hctx, from_sched);

The code change in this patch looks fine to me. However, with this patch applied the code and the source code comment just above the modified are now out of sync :-(

Bart.