From: Mike Christie <michael.christie@oracle.com>
To: martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
james.bottomley@hansenpartnership.com,
virtualization@lists.linux.dev, mst@redhat.com,
pbonzini@redhat.com, stefanha@redhat.com, eperezma@redhat.com
Cc: Mike Christie <michael.christie@oracle.com>
Subject: [PATCH 3/4] scsi: Support scsi_devices without a device wide limit
Date: Fri, 17 Apr 2026 17:57:23 -0500 [thread overview]
Message-ID: <20260417230751.117836-4-michael.christie@oracle.com> (raw)
In-Reply-To: <20260417230751.117836-1-michael.christie@oracle.com>
For virtio-scsi, we export a wide variety of non-scsi devices like
NVMe (local and RDMA/TCP based) drives and block based devices using
ublk. And then it's common to have multiple high perf devices im a LVM
volume. The problem for these setups, is we can easily hit the 4096
scsi_device queue depth limit so we end up throttling IO in the guest
when the real device can handle more IO.
In these situations we don't have a device wide limit that maps to
cmd_per_lun. We have per hw queue limits or on the host we are doing
more dynamic throttling. To allow for these types of devices, this
patch allows drivers to set SCSI_UNLIMITED_CMD_PER_LUN for the
cmd_per_lun. When set, we will then only be limited by the per hw
queue limits.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
drivers/scsi/hosts.c | 5 +++--
drivers/scsi/scsi_scan.c | 25 ++++++++++++++-----------
include/scsi/scsi_host.h | 4 ++++
3 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index e047747d4ecf..c93c59e847c5 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -238,8 +238,9 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
}
/* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */
- shost->cmd_per_lun = min_t(int, shost->cmd_per_lun,
- shost->can_queue);
+ if (shost->cmd_per_lun != SCSI_UNLIMITED_CMD_PER_LUN)
+ shost->cmd_per_lun = min_t(int, shost->cmd_per_lun,
+ shost->can_queue);
error = scsi_init_sense_cache(shost);
if (error)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 7b11bc7de0e3..ecc3638c1909 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -352,18 +352,20 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
if (scsi_device_is_pseudo_dev(sdev))
return sdev;
- depth = sdev->host->cmd_per_lun ?: 1;
+ if (sdev->host->cmd_per_lun != SCSI_UNLIMITED_CMD_PER_LUN) {
+ depth = sdev->host->cmd_per_lun ?: 1;
- /*
- * Use .can_queue as budget map's depth because we have to
- * support adjusting queue depth from sysfs. Meantime use
- * default device queue depth to figure out sbitmap shift
- * since we use this queue depth most of times.
- */
- if (scsi_realloc_sdev_budget_map(sdev, depth))
- goto out_device_destroy;
+ /*
+ * Use .can_queue as budget map's depth because we have to
+ * support adjusting queue depth from sysfs. Meantime use
+ * default device queue depth to figure out sbitmap shift
+ * since we use this queue depth most of times.
+ */
+ if (scsi_realloc_sdev_budget_map(sdev, depth))
+ goto out_device_destroy;
- scsi_change_queue_depth(sdev, depth);
+ scsi_change_queue_depth(sdev, depth);
+ }
if (shost->hostt->sdev_init) {
ret = shost->hostt->sdev_init(sdev);
@@ -1108,7 +1110,8 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
* Set up budget map again since memory consumption of the map depends
* on actual queue depth.
*/
- if (hostt->sdev_configure)
+ if (hostt->sdev_configure &&
+ sdev->host->cmd_per_lun != SCSI_UNLIMITED_CMD_PER_LUN)
scsi_realloc_sdev_budget_map(sdev, sdev->queue_depth);
if (sdev->scsi_level >= SCSI_3)
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 7c747b566bc3..7555898dba25 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -443,6 +443,7 @@ struct scsi_host_template {
*/
#define SCSI_DEFAULT_MAX_SECTORS 1024
+#define SCSI_UNLIMITED_CMD_PER_LUN -1
/*
* True if this host adapter can make good use of linked commands.
* This will allow more than one command to be queued to a given
@@ -451,6 +452,9 @@ struct scsi_host_template {
* command block per lun, 2 for two, etc. Do not set this to 0.
* You should make sure that the host adapter will do the right thing
* before you try setting this above 1.
+ *
+ * Adapters that do not have a device limit can set this to
+ * SCSI_UNLIMITED_CMD_PER_LUN.
*/
short cmd_per_lun;
--
2.47.1
next prev parent reply other threads:[~2026-04-17 23:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 22:57 [PATCH 0/4] scsi: Support devices that don't have a cmd_per_lun limit Mike Christie
2026-04-17 22:57 ` [PATCH 1/4] scsi: Fix can_queue comments Mike Christie
2026-04-20 8:28 ` John Garry
2026-04-17 22:57 ` [PATCH 2/4] scsi: qedi: Fix command overqueueing Mike Christie
2026-04-20 16:45 ` Bart Van Assche
2026-04-20 17:47 ` Mike Christie
2026-04-20 18:02 ` Bart Van Assche
2026-04-20 18:48 ` Mike Christie
2026-04-17 22:57 ` Mike Christie [this message]
2026-04-20 16:51 ` [PATCH 3/4] scsi: Support scsi_devices without a device wide limit Bart Van Assche
2026-04-22 13:15 ` Hannes Reinecke
2026-04-22 18:06 ` Mike Christie
2026-04-23 10:02 ` John Garry
2026-04-23 10:32 ` Hannes Reinecke
2026-04-27 1:33 ` Martin K. Petersen
2026-04-17 22:57 ` [PATCH 4/4] virtio-scsi: " Mike Christie
2026-04-20 17:30 ` Stefan Hajnoczi
2026-04-20 17:37 ` Bart Van Assche
2026-04-20 17:33 ` [PATCH 0/4] scsi: Support devices that don't have a cmd_per_lun limit Stefan Hajnoczi
2026-04-22 18:05 ` Mike Christie
2026-04-23 9:45 ` Hannes Reinecke
2026-04-23 16:40 ` Bart Van Assche
2026-04-24 5:45 ` Hannes Reinecke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260417230751.117836-4-michael.christie@oracle.com \
--to=michael.christie@oracle.com \
--cc=eperezma@redhat.com \
--cc=james.bottomley@hansenpartnership.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox