Skip to content

Commit 3287286

Browse files
Ming Leimartinkpetersen
authored andcommitted
scsi: core: avoid host-wide host_busy counter for scsi_mq
It isn't necessary to check the host depth in scsi_queue_rq() any more since it has been respected by blk-mq before calling scsi_queue_rq() via getting driver tag. Lots of LUNs may attach to same host and per-host IOPS may reach millions, so we should avoid expensive atomic operations on the host-wide counter in the IO path. This patch implements scsi_host_busy() via blk_mq_tagset_busy_iter() for reading the count of busy IOs for scsi_mq. It is observed that IOPS is increased by 15% in IO test on scsi_debug (32 LUNs, 32 submit queues, 1024 can_queue, libaio/dio) in a dual-socket system. [mkp: clarified commit message] Cc: Omar Sandoval <[email protected]>, Cc: "Martin K. Petersen" <[email protected]>, Cc: James Bottomley <[email protected]>, Cc: Christoph Hellwig <[email protected]>, Cc: Don Brace <[email protected]> Cc: Kashyap Desai <[email protected]> Cc: Mike Snitzer <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Laurence Oberman <[email protected]> Cc: Bart Van Assche <[email protected]> Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent c84b023 commit 3287286

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

drivers/scsi/hosts.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,35 @@ struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost)
563563
}
564564
EXPORT_SYMBOL(scsi_host_get);
565565

566+
struct scsi_host_mq_in_flight {
567+
int cnt;
568+
};
569+
570+
static void scsi_host_check_in_flight(struct request *rq, void *data,
571+
bool reserved)
572+
{
573+
struct scsi_host_mq_in_flight *in_flight = data;
574+
575+
if (blk_mq_request_started(rq))
576+
in_flight->cnt++;
577+
}
578+
566579
/**
567580
* scsi_host_busy - Return the host busy counter
568581
* @shost: Pointer to Scsi_Host to inc.
569582
**/
570583
int scsi_host_busy(struct Scsi_Host *shost)
571584
{
572-
return atomic_read(&shost->host_busy);
585+
struct scsi_host_mq_in_flight in_flight = {
586+
.cnt = 0,
587+
};
588+
589+
if (!shost->use_blk_mq)
590+
return atomic_read(&shost->host_busy);
591+
592+
blk_mq_tagset_busy_iter(&shost->tag_set, scsi_host_check_in_flight,
593+
&in_flight);
594+
return in_flight.cnt;
573595
}
574596
EXPORT_SYMBOL(scsi_host_busy);
575597

drivers/scsi/scsi_lib.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ static void scsi_dec_host_busy(struct Scsi_Host *shost)
345345
unsigned long flags;
346346

347347
rcu_read_lock();
348-
atomic_dec(&shost->host_busy);
348+
if (!shost->use_blk_mq)
349+
atomic_dec(&shost->host_busy);
349350
if (unlikely(scsi_host_in_recovery(shost))) {
350351
spin_lock_irqsave(shost->host_lock, flags);
351352
if (shost->host_failed || shost->host_eh_scheduled)
@@ -444,7 +445,12 @@ static inline bool scsi_target_is_busy(struct scsi_target *starget)
444445

445446
static inline bool scsi_host_is_busy(struct Scsi_Host *shost)
446447
{
447-
if (shost->can_queue > 0 &&
448+
/*
449+
* blk-mq can handle host queue busy efficiently via host-wide driver
450+
* tag allocation
451+
*/
452+
453+
if (!shost->use_blk_mq && shost->can_queue > 0 &&
448454
atomic_read(&shost->host_busy) >= shost->can_queue)
449455
return true;
450456
if (atomic_read(&shost->host_blocked) > 0)
@@ -1600,9 +1606,12 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
16001606
if (scsi_host_in_recovery(shost))
16011607
return 0;
16021608

1603-
busy = atomic_inc_return(&shost->host_busy) - 1;
1609+
if (!shost->use_blk_mq)
1610+
busy = atomic_inc_return(&shost->host_busy) - 1;
1611+
else
1612+
busy = 0;
16041613
if (atomic_read(&shost->host_blocked) > 0) {
1605-
if (busy)
1614+
if (busy || scsi_host_busy(shost))
16061615
goto starved;
16071616

16081617
/*
@@ -1616,7 +1625,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
16161625
"unblocking host at zero depth\n"));
16171626
}
16181627

1619-
if (shost->can_queue > 0 && busy >= shost->can_queue)
1628+
if (!shost->use_blk_mq && shost->can_queue > 0 && busy >= shost->can_queue)
16201629
goto starved;
16211630
if (shost->host_self_blocked)
16221631
goto starved;
@@ -1702,7 +1711,9 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
17021711
* with the locks as normal issue path does.
17031712
*/
17041713
atomic_inc(&sdev->device_busy);
1705-
atomic_inc(&shost->host_busy);
1714+
1715+
if (!shost->use_blk_mq)
1716+
atomic_inc(&shost->host_busy);
17061717
if (starget->can_queue > 0)
17071718
atomic_inc(&starget->target_busy);
17081719

0 commit comments

Comments
 (0)