From: Bart Van Assche <bvanassche@acm.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
Christoph Hellwig <hch@lst.de>,
Damien Le Moal <dlemoal@kernel.org>,
Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH v22 02/14] blk-mq: Always insert sequential zoned writes into a software queue
Date: Thu, 24 Jul 2025 14:56:51 -0700 [thread overview]
Message-ID: <20250724215703.2910510-3-bvanassche@acm.org> (raw)
In-Reply-To: <20250724215703.2910510-1-bvanassche@acm.org>
One of the optimizations in the block layer is that the software queues
are bypassed if it is expected that the block driver will accept a
request. This can cause request reordering even for requests submitted
from the same CPU core. This patch preserves the order for sequential
zoned writes submitted from a given CPU core by always inserting these
requests into the appropriate software queue.
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
block/blk-mq.c | 27 +++++++++++++++++++++++++--
include/linux/blk-mq.h | 11 +++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index b1d81839679f..445f2275eddb 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1537,6 +1537,27 @@ void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list)
}
EXPORT_SYMBOL(blk_mq_requeue_request);
+/*
+ * Whether the block layer should preserve the order of @rq relative to other
+ * requests submitted to the same software queue.
+ */
+static bool blk_mq_preserve_order(struct request *rq)
+{
+ return rq->q->limits.features & BLK_FEAT_ORDERED_HWQ &&
+ blk_rq_is_seq_zoned_write(rq);
+}
+
+static bool blk_mq_preserve_order_for_list(struct list_head *list)
+{
+ struct request *rq;
+
+ list_for_each_entry(rq, list, queuelist)
+ if (blk_mq_preserve_order(rq))
+ return true;
+
+ return false;
+}
+
static void blk_mq_requeue_work(struct work_struct *work)
{
struct request_queue *q =
@@ -2566,7 +2587,8 @@ static void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx,
* Try to issue requests directly if the hw queue isn't busy to save an
* extra enqueue & dequeue to the sw queue.
*/
- if (!hctx->dispatch_busy && !run_queue_async) {
+ if (!hctx->dispatch_busy && !run_queue_async &&
+ !blk_mq_preserve_order_for_list(list)) {
blk_mq_run_dispatch_ops(hctx->queue,
blk_mq_try_issue_list_directly(hctx, list));
if (list_empty(list))
@@ -3215,7 +3237,8 @@ void blk_mq_submit_bio(struct bio *bio)
hctx = rq->mq_hctx;
if ((rq->rq_flags & RQF_USE_SCHED) ||
- (hctx->dispatch_busy && (q->nr_hw_queues == 1 || !is_sync))) {
+ (hctx->dispatch_busy && (q->nr_hw_queues == 1 || !is_sync)) ||
+ blk_mq_preserve_order(rq)) {
blk_mq_insert_request(rq, 0);
blk_mq_run_hw_queue(hctx, true);
} else {
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 2a5a828f19a0..30d7cd1b0484 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -1191,4 +1191,15 @@ static inline int blk_rq_map_sg(struct request *rq, struct scatterlist *sglist)
}
void blk_dump_rq_flags(struct request *, char *);
+static inline bool blk_rq_is_seq_zoned_write(struct request *rq)
+{
+ switch (req_op(rq)) {
+ case REQ_OP_WRITE:
+ case REQ_OP_WRITE_ZEROES:
+ return bdev_zone_is_seq(rq->q->disk->part0, blk_rq_pos(rq));
+ default:
+ return false;
+ }
+}
+
#endif /* BLK_MQ_H */
next prev parent reply other threads:[~2025-07-24 21:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 21:56 [PATCH v22 00/14] Improve write performance for zoned UFS devices Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 01/14] block: Support block devices that preserve the order of write requests Bart Van Assche
2025-07-24 21:56 ` Bart Van Assche [this message]
2025-07-24 21:56 ` [PATCH v22 03/14] blk-mq: Restore the zone write order when requeuing Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 04/14] blk-zoned: Add an argument to blk_zone_plug_bio() Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 05/14] blk-zoned: Split an if-statement Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 06/14] blk-zoned: Move code from disk_zone_wplug_add_bio() into its caller Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 07/14] blk-zoned: Introduce a loop in blk_zone_wplug_bio_work() Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 08/14] blk-zoned: Support pipelining of zoned writes Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 09/14] null_blk: Add the preserves_write_order attribute Bart Van Assche
2025-07-24 21:56 ` [PATCH v22 10/14] scsi: core: Retry unaligned zoned writes Bart Van Assche
2025-07-24 21:57 ` [PATCH v22 11/14] scsi: sd: Increase retry count for " Bart Van Assche
2025-07-24 21:57 ` [PATCH v22 12/14] scsi: scsi_debug: Add the preserves_write_order module parameter Bart Van Assche
2025-07-24 21:57 ` [PATCH v22 13/14] scsi: scsi_debug: Support injecting unaligned write errors Bart Van Assche
2025-07-24 21:57 ` [PATCH v22 14/14] ufs: core: Inform the block layer about write ordering Bart Van Assche
2025-08-01 8:04 ` Can Guo
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=20250724215703.2910510-3-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--cc=dlemoal@kernel.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/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).