Avoid that scsi-mq queue processing stalls
Subsystems (2)
cover Avoid that scsi-mq queue processing stalls
Hello Jens,
The three patches in this patch series fix the queue lockup I reported a few days ago on the linux-block mailing list. Please consider these patches for kernel v4.11.
Thanks,
Bart.
Bart Van Assche (3):
blk-mq: Introduce blk_mq_ops.restart_queues
scsi: Add scsi_restart_queues()
scsi: Ensure that scsi_run_queue() runs all hardware queues
block/blk-mq-sched.c | 11 +++-------- block/blk-mq-sched.h | 14 -------------- drivers/scsi/scsi_lib.c | 20 +++++++++++++++++--- include/linux/blk-mq.h | 4 ++++ include/linux/blkdev.h | 1 - 5 files changed, 24 insertions(+), 26 deletions(-)
Signature · 1 line
2.12.0
PATCH 1/3 blk-mq: Introduce blk_mq_ops.restart_queues
If a tag set is shared among multiple request queues, leave it to the block driver to restart queues. Hence remove QUEUE_FLAG_RESTART and introduce blk_mq_ops.restart_queues. Remove blk_mq_sched_mark_restart_queue() because this function has no callers.
--- block/blk-mq-sched.c | 11 +++-------- block/blk-mq-sched.h | 14 -------------- include/linux/blk-mq.h | 4 ++++ include/linux/blkdev.h | 1 - 4 files changed, 7 insertions(+), 23 deletions(-)
block/blk-mq-sched.c +3 -8
@@ -329,16 +329,11 @@ static void blk_mq_sched_restart_hctx(struct blk_mq_hw_ctx *hctx)void blk_mq_sched_restart_queues (struct blk_mq_hw_ctx *hctx) {struct request_queue *q = hctx->queue; -unsigned int i; -if (test_bit (QUEUE_FLAG_RESTART , &q->queue_flags)) { -if (test_and_clear_bit (QUEUE_FLAG_RESTART , &q->queue_flags)) { -queue_for_each_hw_ctx (q, hctx, i) -blk_mq_sched_restart_hctx (hctx); - } - }else { +if (q->mq_ops->restart_queues) + q->mq_ops->restart_queues (q); +else blk_mq_sched_restart_hctx (hctx); - } }/*
block/blk-mq-sched.h +0 -14
@@ -131,20 +131,6 @@ static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)set_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state); } -/* -* Mark a hardware queue and the request queue it belongs to as needing a -* restart. -*/ -static inline void blk_mq_sched_mark_restart_queue (struct blk_mq_hw_ctx *hctx) -{ -struct request_queue *q = hctx->queue; - -if (!test_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state)) -set_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state); -if (!test_bit (QUEUE_FLAG_RESTART , &q->queue_flags)) -set_bit (QUEUE_FLAG_RESTART , &q->queue_flags); -} -static inline bool blk_mq_sched_needs_restart (struct blk_mq_hw_ctx *hctx) {return test_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state);
include/linux/blk-mq.h +4 -0
@@ -86,6 +86,7 @@ struct blk_mq_queue_data { };typedef int (queue_rq_fn )(struct blk_mq_hw_ctx *,const struct blk_mq_queue_data *); +typedef void (restart_fn )(struct request_queue *q);typedef enum blk_eh_timer_return (timeout_fn )(struct request *,bool );typedef int (init_hctx_fn )(struct blk_mq_hw_ctx *,void *,unsigned int );typedef void (exit_hctx_fn )(struct blk_mq_hw_ctx *,unsigned int );
@@ -108,6 +109,9 @@ struct blk_mq_ops {*/ queue_rq_fn *queue_rq; +/* Called upon request completion to rerun all queues */ +restart_fn *restart_queues; +/* * Called on request timeout */
include/linux/blkdev.h +0 -1
@@ -615,7 +615,6 @@ struct request_queue {#define QUEUE_FLAG_FLUSH_NQ 25/* flush not queueuable */ #define QUEUE_FLAG_DAX 26/* device supports DAX */ #define QUEUE_FLAG_STATS 27/* track rq completion times */ -#define QUEUE_FLAG_RESTART 28/* queue needs restart at completion */ #define QUEUE_FLAG_POLL_STATS 29/* collecting stats for hybrid polling */ #define QUEUE_FLAG_REGISTERED 30/* queue has been registered to a disk */
Signature · 1 line
2.12.0
PATCH 2/3 scsi: Add scsi_restart_queues()
In reply to Bart Van AsscheThis patch avoids that if multiple SCSI devices are associated with a SCSI host that a queue can get stuck if scsi_queue_rq() returns "busy".
--- drivers/scsi/scsi_lib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/scsi/scsi_lib.c +16 -0
@@ -555,6 +555,21 @@ void scsi_run_host_queues(struct Scsi_Host *shost)scsi_run_queue (sdev->request_queue); } +static void scsi_restart_queues (struct request_queue *q) +{ +struct scsi_device *sdev = q->queuedata; +struct Scsi_Host *shost = sdev->host; +unsigned long flags; + +spin_lock_irqsave (shost->host_lock, flags); +__shost_for_each_device (sdev, shost) { + q = sdev->request_queue; +if (q->mq_ops && !blk_queue_dying (q)) +blk_mq_run_hw_queues (q, true); + } +spin_unlock_irqrestore (shost->host_lock, flags); +} +static void scsi_uninit_cmd (struct scsi_cmnd *cmd) {if (!blk_rq_is_passthrough (cmd->request)) {
@@ -2156,6 +2171,7 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)static const struct blk_mq_ops scsi_mq_ops = { .queue_rq = scsi_queue_rq, + .restart_queues = scsi_restart_queues, .complete = scsi_softirq_done, .timeout = scsi_timeout, .init_request = scsi_init_request,
Signature · 1 line
2.12.0
PATCH 3/3 scsi: Ensure that scsi_run_queue() runs all hardware queues
In reply to Bart Van Asschecommit 52d7f1b5c2f3 ("blk-mq: Avoid that requeueing starts stopped queues") removed the blk_mq_stop_hw_queue() call from scsi_queue_rq() for the BLK_MQ_RQ_QUEUE_BUSY case. blk_mq_start_stopped_hw_queues() only runs queues that had been stopped. Hence change the blk_mq_start_stopped_hw_queues() call in scsi_run_queue() into blk_mq_run_hw_queues(). Remove the blk_mq_start_stopped_hw_queues() call from scsi_end_request() because __blk_mq_finish_request() already runs all hardware queues if needed.
--- drivers/scsi/scsi_lib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/scsi/scsi_lib.c +1 -3
@@ -496,7 +496,7 @@ static void scsi_run_queue(struct request_queue *q)scsi_starved_list_run (sdev->host);if (q->mq_ops) -blk_mq_start_stopped_hw_queues (q, false); +blk_mq_run_hw_queues (q, false);else blk_run_queue (q); }
@@ -681,8 +681,6 @@ static bool scsi_end_request(struct request *req, int error,if (scsi_target (sdev)->single_lun || !list_empty (&sdev->host->starved_list))kblockd_schedule_work (&sdev->requeue_work); -else -blk_mq_start_stopped_hw_queues (q, true); }else {unsigned long flags;
Signature · 1 line
2.12.0
Re: [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues
Looks good,
Re: [PATCH 1/3] blk-mq: Introduce blk_mq_ops.restart_queues
In reply to Bart Van AsscheQuoted 11 lines · Bart Van Assche
If a tag set is shared among multiple request queues, leave it to the block driver to restart queues. Hence remove
QUEUE_FLAG_RESTARTand introduce blk_mq_ops.restart_queues. Removeblk_mq_sched_mark_restart_queue()because this function has no callers.Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Martin K. Petersen <[email protected]>Cc James Bottomley <[email protected]>
Quoted 7 lines
--- block/blk-mq-sched.c | 11 +++-------- block/blk-mq-sched.h | 14 -------------- include/linux/blk-mq.h | 4 ++++ include/linux/blkdev.h | 1 - 4 files changed, 7 insertions(+), 23 deletions(-)
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG N�rnberg)
Re: [PATCH 2/3] scsi: Add scsi_restart_queues()
In reply to Bart Van AsscheQuoted 4 lines · Bart Van Assche
This patch avoids that if multiple SCSI devices are associated with a SCSI host that a queue can get stuck if
scsi_queue_rq()returns "busy".
Quoted 9 lines
Signed-off-by Bart Van Assche <[email protected]>Cc Martin K. Petersen <[email protected]>Cc James Bottomley <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>--- drivers/scsi/scsi_lib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG N�rnberg)
Re: [PATCH 3/3] scsi: Ensure that scsi_run_queue() runs all hardware queues
In reply to Bart Van AsscheQuoted 16 lines · Bart Van Assche
commit
52d7f1b5c2f3("blk-mq: Avoid that requeueing starts stopped queues") removed theblk_mq_stop_hw_queue()call fromscsi_queue_rq()for theBLK_MQ_RQ_QUEUE_BUSYcase.blk_mq_start_stopped_hw_queues()only runs queues that had been stopped. Hence change theblk_mq_start_stopped_hw_queues()call inscsi_run_queue()intoblk_mq_run_hw_queues(). Remove theblk_mq_start_stopped_hw_queues()call fromscsi_end_request()because__blk_mq_finish_request()already runs all hardware queues if needed.Fixes commit 52d7f1b5c2f3 ("blk-mq: Avoid that requeueing starts stopped queues")Signed-off-by Bart Van Assche <[email protected]>Cc Martin K. Petersen <[email protected]>Cc James Bottomley <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Sagi Grimberg <[email protected]>
Quoted 4 lines
--- drivers/scsi/scsi_lib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG N�rnberg)