From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
John Garry <john.g.garry@oracle.com>,
Hannes Reinecke <hare@suse.de>,
Bart Van Assche <bvanassche@acm.org>,
Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@infradead.org>,
Ming Lei <ming.lei@redhat.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Subject: [PATCH v2 5/5] scsi: core: Improve IOPS in case of host-wide tags
Date: Mon, 17 Nov 2025 14:52:04 -0800 [thread overview]
Message-ID: <20251117225205.2024479-6-bvanassche@acm.org> (raw)
In-Reply-To: <20251117225205.2024479-1-bvanassche@acm.org>
The SCSI core uses the budget map to restrict the number of commands
that are in flight per logical unit. That limit check can be left out if
host->cmd_per_lun >= host->can_queue and if the host tag set is shared
across all hardware queues or if there is only one hardware queue Since
scsi_mq_get_budget() shows up in all CPU profiles for fast SCSI devices,
do not allocate a budget map if cmd_per_lun >= can_queue and if the host
tag set is shared across all hardware queues.
For the following test this patch increases IOPS by 5%:
modprobe scsi_debug delay=0 no_rwlock=1 host_max_queue=192 submit_queues=$(nproc)
fio --bs=4096 --disable_clat=1 --disable_slat=1 --group_reporting=1 \
--gtod_reduce=1 --invalidate=1 --ioengine=io_uring --ioscheduler=none \
--norandommap --runtime=60 --rw=randread --thread --time_based=1 \
--buffered=0 --numjobs=1 --iodepth=192 --iodepth_batch=24 --name=/dev/sda \
--filename=/dev/sda
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Hannes Reinecke <hare@suse.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi.c | 3 ++-
drivers/scsi/scsi_scan.c | 18 +++++++++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 76cdad063f7b..3daa32c9e790 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -229,7 +229,8 @@ int scsi_change_queue_depth(struct scsi_device *sdev, int depth)
if (sdev->request_queue)
blk_set_queue_depth(sdev->request_queue, depth);
- sbitmap_resize(&sdev->budget_map, sdev->queue_depth);
+ if (sdev->budget_map.map)
+ sbitmap_resize(&sdev->budget_map, sdev->queue_depth);
return sdev->queue_depth;
}
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 7acbfcfc2172..99b82e28f292 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -215,9 +215,17 @@ static void scsi_unlock_floptical(struct scsi_device *sdev,
SCSI_TIMEOUT, 3, NULL);
}
+static bool scsi_needs_budget_map(struct Scsi_Host *shost, unsigned int depth)
+{
+ if (shost->host_tagset || shost->tag_set.nr_hw_queues == 1)
+ return depth < shost->can_queue;
+ return true;
+}
+
static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
unsigned int depth)
{
+ struct Scsi_Host *shost = sdev->host;
int new_shift = sbitmap_calculate_shift(depth);
bool need_alloc = !sdev->budget_map.map;
bool need_free = false;
@@ -225,6 +233,13 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
int ret;
struct sbitmap sb_backup;
+ if (!scsi_needs_budget_map(shost, depth)) {
+ memflags = blk_mq_freeze_queue(sdev->request_queue);
+ sbitmap_free(&sdev->budget_map);
+ blk_mq_unfreeze_queue(sdev->request_queue, memflags);
+ return 0;
+ }
+
depth = min_t(unsigned int, depth, scsi_device_max_queue_depth(sdev));
/*
@@ -1120,7 +1135,8 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
scsi_cdl_check(sdev);
sdev->max_queue_depth = sdev->queue_depth;
- WARN_ON_ONCE(sdev->max_queue_depth > sdev->budget_map.depth);
+ WARN_ON_ONCE(sdev->budget_map.map &&
+ sdev->max_queue_depth > sdev->budget_map.depth);
/*
* Ok, the device is now all set up, we can
next prev parent reply other threads:[~2025-11-17 22:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-17 22:51 [PATCH v2 0/5] Increase SCSI IOPS Bart Van Assche
2025-11-17 22:52 ` [PATCH v2 1/5] block: Rename busy_tag_iter_fn into blk_mq_rq_iter_fn Bart Van Assche
2025-11-17 22:52 ` [PATCH v2 2/5] block: Introduce __blk_mq_tagset_iter() Bart Van Assche
2025-11-17 22:52 ` [PATCH v2 3/5] block: Introduce blk_mq_tagset_iter() Bart Van Assche
2025-11-17 22:52 ` [PATCH v2 4/5] scsi: core: Generalize scsi_device_busy() Bart Van Assche
2025-11-17 22:52 ` Bart Van Assche [this message]
2025-11-21 21:17 ` [PATCH v2 0/5] Increase SCSI IOPS Bart Van Assche
-- strict thread matches above, loose matches on Subject: below --
2025-11-24 18:21 Bart Van Assche
2025-11-24 18:22 ` [PATCH v2 5/5] scsi: core: Improve IOPS in case of host-wide tags Bart Van Assche
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=20251117225205.2024479-6-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=hch@infradead.org \
--cc=john.g.garry@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ming.lei@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).