scsi: avoid to run synchronize_rcu for each device in scsi_host_block
PATCH v2 1/1 scsi: avoid to run synchronize_rcu for each device in scsi_host_block
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.
---
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(-)
drivers/scsi/scsi_lib.c +16 -1
@@ -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);
Signature · 1 line
2.25.2
Quoted 48 lines · Ming Lei
scsi_host_block()callsscsi_internal_device_block()for eachscsi_device, andscsi_internal_device_block()callsblk_mq_quiesce_queue()for each LUN. Howeversynchronize_rcuis run fromblk_mq_quiesce_queue().This way may become unnecessary slow in case of lots of LUNs.
Use
scsi_internal_device_block_nowait()to implementscsi_host_block(), so it is enough to runsynchronize_rcu()once since scsi never supports blk-mq'sBLK_MQ_F_BLOCKING.Cc Steffen Maier <[email protected]>Cc Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Dexuan Cui <[email protected]>Cc Hannes Reinecke <[email protected]>Signed-off-by Ming Lei <[email protected]>---
V2:
- fix commit log as pointed by Steffen
- add comment onBLK_MQ_F_BLOCKINGas suggested by Bartdrivers/scsi/scsi_lib.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)drivers/scsi/scsi_lib.c +9
-1@@ -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 ; } + +/*
drivers/scsi/scsi_lib.c scsi_host_block(struct Scsi_Host *shost) · line 2866
Quoted 10 lines
drivers/scsi/scsi_lib.c +7
-0+* 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.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Looks good,
Martin K. Petersen
AppliedMing,
Quoted 4 lines
scsi_host_block()callsscsi_internal_device_block()for eachscsi_device, andscsi_internal_device_block()callsblk_mq_quiesce_queue()for each LUN. Howeversynchronize_rcuis run fromblk_mq_quiesce_queue().
Applied to 5.8/scsi-queue, thank you!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering