Skip to contentSkip to conversation

scsi: avoid to run synchronize_rcu for each device in scsi_host_block

PATCH Superseded Ming Lei 3 participants 3 messages Apr 22, 2020 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 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.

So use scsi_internal_device_block() to implement scsi_host_block(), and just run once synchronize_rcu() because scsi never supports tagset of BLK_MQ_F_BLOCKING.

Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Dexuan Cui <[email protected]>
Cc Hannes Reinecke <[email protected]>
---
 drivers/scsi/scsi_lib.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +12 -1
index 47835c4b4ee0..089ac92ac6c3 100644
@@ -2841,11 +2841,22 @@ 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() one time for every 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;
 	}
+
+	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
#1 lore raw
Quoted 3 lines · Ming Lei

So use scsi_internal_device_block() to implement scsi_host_block(), and just run once synchronize_rcu() because scsi never supports tagset of BLK_MQ_F_BLOCKING.

Please add a reference to BLK_MQ_F_BLOCKING as a comment in the modified code.

Thanks,

Bart.

#2 lore raw
In reply to Ming Lei
Quoted 8 lines · Ming Lei

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.

So use scsi_internal_device_block() to implement scsi_host_block(),

scsi_internal_device_block()
=?=>
scsi_internal_device_block_nowait()

Quoted 41 lines

and just run once synchronize_rcu() because scsi never supports tagset of BLK_MQ_F_BLOCKING.

Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Dexuan Cui <[email protected]>
Cc Hannes Reinecke <[email protected]>
---
  drivers/scsi/scsi_lib.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +12 -1
index 47835c4b4ee0..089ac92ac6c3 100644
@@ -2841,11 +2841,22 @@ 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() one time for every 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;
  	}
+
+	WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);
+
+	if (!ret)
+		synchronize_rcu();
  	return ret;
  }
  EXPORT_SYMBOL_GPL(scsi_host_block);
Signature · 11 lines
Mit freundlichen Gruessen / Kind regards
Steffen Maier

Linux on IBM Z Development

https://www.ibm.com/privacy/us/en/
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Matthias Hartmann
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294