All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block
@ 2020-04-23  2:07 Ming Lei
  2020-04-23  5:41 ` Hannes Reinecke
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ming Lei @ 2020-04-23  2:07 UTC (permalink / raw)
  To: James Bottomley, linux-scsi, Martin K . Petersen
  Cc: Ming Lei, Steffen Maier, Bart Van Assche, Christoph Hellwig,
	Dexuan Cui, Hannes Reinecke

scsi_host_block() calls scsi_internal_device_block() for each
scsi_device, and scsi_internal_device_block() calls
blk_mq_quiesce_queue() for each LUN. However synchronize_rcu is
run from blk_mq_quiesce_queue().

This way may become unnecessary slow in case of lots of LUNs.

Use scsi_internal_device_block_nowait() to implement scsi_host_block(),
so it is enough to run synchronize_rcu() once since scsi never
supports blk-mq's BLK_MQ_F_BLOCKING.

Cc: Steffen Maier <maier@linux.ibm.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Hannes Reinecke <hare@suse.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
V2:
	- fix commit log as pointed by Steffen
	- add comment on BLK_MQ_F_BLOCKING as suggested by Bart

 drivers/scsi/scsi_lib.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 47835c4b4ee0..86007a523145 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2841,11 +2841,26 @@ scsi_host_block(struct Scsi_Host *shost)
 	struct scsi_device *sdev;
 	int ret = 0;
 
+	/*
+	 * Call scsi_internal_device_block_nowait then we can avoid to
+	 * run synchronize_rcu() for each LUN
+	 */
 	shost_for_each_device(sdev, shost) {
-		ret = scsi_internal_device_block(sdev);
+		mutex_lock(&sdev->state_mutex);
+		ret = scsi_internal_device_block_nowait(sdev);
+		mutex_unlock(&sdev->state_mutex);
 		if (ret)
 			break;
 	}
+
+	/*
+	 * SCSI never enables blk-mq's BLK_MQ_F_BLOCKING, so run
+	 * synchronize_rcu() once is enough
+	 */
+	WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);
+
+	if (!ret)
+		synchronize_rcu();
 	return ret;
 }
 EXPORT_SYMBOL_GPL(scsi_host_block);
-- 
2.25.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block
  2020-04-23  2:07 [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block Ming Lei
@ 2020-04-23  5:41 ` Hannes Reinecke
  2020-04-24  6:47 ` Christoph Hellwig
  2020-04-24 18:12 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2020-04-23  5:41 UTC (permalink / raw)
  To: Ming Lei, James Bottomley, linux-scsi, Martin K . Petersen
  Cc: Steffen Maier, Bart Van Assche, Christoph Hellwig, Dexuan Cui

On 4/23/20 4:07 AM, Ming Lei wrote:
> scsi_host_block() calls scsi_internal_device_block() for each
> scsi_device, and scsi_internal_device_block() calls
> blk_mq_quiesce_queue() for each LUN. However synchronize_rcu is
> run from blk_mq_quiesce_queue().
> 
> This way may become unnecessary slow in case of lots of LUNs.
> 
> Use scsi_internal_device_block_nowait() to implement scsi_host_block(),
> so it is enough to run synchronize_rcu() once since scsi never
> supports blk-mq's BLK_MQ_F_BLOCKING.
> 
> Cc: Steffen Maier <maier@linux.ibm.com>
> Cc: Bart Van Assche <bvanassche@acm.org>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Dexuan Cui <decui@microsoft.com>
> Cc: Hannes Reinecke <hare@suse.de>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> V2:
> 	- fix commit log as pointed by Steffen
> 	- add comment on BLK_MQ_F_BLOCKING as suggested by Bart
> 
>   drivers/scsi/scsi_lib.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 47835c4b4ee0..86007a523145 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -2841,11 +2841,26 @@ scsi_host_block(struct Scsi_Host *shost)
>   	struct scsi_device *sdev;
>   	int ret = 0;
>   
> +	/*
> +	 * Call scsi_internal_device_block_nowait then we can avoid to
> +	 * run synchronize_rcu() for each LUN
> +	 */
>   	shost_for_each_device(sdev, shost) {
> -		ret = scsi_internal_device_block(sdev);
> +		mutex_lock(&sdev->state_mutex);
> +		ret = scsi_internal_device_block_nowait(sdev);
> +		mutex_unlock(&sdev->state_mutex);
>   		if (ret)
>   			break;
>   	}
> +
> +	/*
> +	 * SCSI never enables blk-mq's BLK_MQ_F_BLOCKING, so run
> +	 * synchronize_rcu() once is enough
> +	 */
> +	WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);
> +
> +	if (!ret)
> +		synchronize_rcu();
>   	return ret;
>   }
>   EXPORT_SYMBOL_GPL(scsi_host_block);
> 
Looks good.

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke            Teamlead Storage & Networking
hare@suse.de                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block
  2020-04-23  2:07 [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block Ming Lei
  2020-04-23  5:41 ` Hannes Reinecke
@ 2020-04-24  6:47 ` Christoph Hellwig
  2020-04-24 18:12 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-04-24  6:47 UTC (permalink / raw)
  To: Ming Lei
  Cc: James Bottomley, linux-scsi, Martin K . Petersen, Steffen Maier,
	Bart Van Assche, Christoph Hellwig, Dexuan Cui, Hannes Reinecke

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block
  2020-04-23  2:07 [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block Ming Lei
  2020-04-23  5:41 ` Hannes Reinecke
  2020-04-24  6:47 ` Christoph Hellwig
@ 2020-04-24 18:12 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-04-24 18:12 UTC (permalink / raw)
  To: Ming Lei
  Cc: James Bottomley, linux-scsi, Martin K . Petersen, Steffen Maier,
	Bart Van Assche, Christoph Hellwig, Dexuan Cui, Hannes Reinecke


Ming,

> scsi_host_block() calls scsi_internal_device_block() for each
> scsi_device, and scsi_internal_device_block() calls
> blk_mq_quiesce_queue() for each LUN. However synchronize_rcu is
> run from blk_mq_quiesce_queue().

Applied to 5.8/scsi-queue, thank you!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-24 18:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23  2:07 [PATCH V2] scsi: avoid to run synchronize_rcu for each device in scsi_host_block Ming Lei
2020-04-23  5:41 ` Hannes Reinecke
2020-04-24  6:47 ` Christoph Hellwig
2020-04-24 18:12 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.