public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Minor ublk optimizations
@ 2025-03-28 18:04 Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 1/5] ublk: remove unused cmd argument to ublk_dispatch_req() Caleb Sander Mateos
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Caleb Sander Mateos @ 2025-03-28 18:04 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, linux-kernel, Caleb Sander Mateos

A few cleanups on top of Ming's recent patch set that implemented
->queue_rqs() for ublk:
https://lore.kernel.org/linux-block/20250327095123.179113-1-ming.lei@redhat.com/T/#u

Caleb Sander Mateos (5):
  ublk: remove unused cmd argument to ublk_dispatch_req()
  ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop
  ublk: get ubq from pdu in ublk_cmd_list_tw_cb()
  ublk: avoid redundant io->cmd in ublk_queue_cmd_list()
  ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb()

 drivers/block/ublk_drv.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] ublk: remove unused cmd argument to ublk_dispatch_req()
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
@ 2025-03-28 18:04 ` Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 2/5] ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop Caleb Sander Mateos
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Caleb Sander Mateos @ 2025-03-28 18:04 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, linux-kernel, Caleb Sander Mateos

ublk_dispatch_req() never uses its struct io_uring_cmd *cmd argument.
Drop it so callers don't have to pass a value.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 drivers/block/ublk_drv.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 355a59c78539..39efe443e235 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1183,11 +1183,10 @@ static inline void __ublk_abort_rq(struct ublk_queue *ubq,
 	else
 		blk_mq_end_request(rq, BLK_STS_IOERR);
 }
 
 static void ublk_dispatch_req(struct ublk_queue *ubq,
-			      struct io_uring_cmd *cmd,
 			      struct request *req,
 			      unsigned int issue_flags)
 {
 	int tag = req->tag;
 	struct ublk_io *io = &ubq->ios[tag];
@@ -1271,11 +1270,11 @@ static void ublk_cmd_tw_cb(struct io_uring_cmd *cmd,
 	struct ublk_queue *ubq = pdu->ubq;
 	int tag = pdu->tag;
 	struct request *req = blk_mq_tag_to_rq(
 		ubq->dev->tag_set.tags[ubq->q_id], tag);
 
-	ublk_dispatch_req(ubq, cmd, req, issue_flags);
+	ublk_dispatch_req(ubq, req, issue_flags);
 }
 
 static void ublk_queue_cmd(struct ublk_queue *ubq, struct request *rq)
 {
 	struct ublk_io *io = &ubq->ios[rq->tag];
@@ -1290,15 +1289,13 @@ static void ublk_cmd_list_tw_cb(struct io_uring_cmd *cmd,
 	struct request *rq = pdu->req_list;
 	struct ublk_queue *ubq = rq->mq_hctx->driver_data;
 	struct request *next;
 
 	while (rq) {
-		struct ublk_io *io = &ubq->ios[rq->tag];
-
 		next = rq->rq_next;
 		rq->rq_next = NULL;
-		ublk_dispatch_req(ubq, io->cmd, rq, issue_flags);
+		ublk_dispatch_req(ubq, rq, issue_flags);
 		rq = next;
 	}
 }
 
 static void ublk_queue_cmd_list(struct ublk_queue *ubq, struct rq_list *l)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/5] ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 1/5] ublk: remove unused cmd argument to ublk_dispatch_req() Caleb Sander Mateos
@ 2025-03-28 18:04 ` Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 3/5] ublk: get ubq from pdu in ublk_cmd_list_tw_cb() Caleb Sander Mateos
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Caleb Sander Mateos @ 2025-03-28 18:04 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, linux-kernel, Caleb Sander Mateos

ublk_cmd_list_tw_cb() is always performed on a non-empty request list.
So don't check whether rq is NULL on the first iteration of the loop,
just on subsequent iterations.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 drivers/block/ublk_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 39efe443e235..8b9780c0feab 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1288,16 +1288,16 @@ static void ublk_cmd_list_tw_cb(struct io_uring_cmd *cmd,
 	struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
 	struct request *rq = pdu->req_list;
 	struct ublk_queue *ubq = rq->mq_hctx->driver_data;
 	struct request *next;
 
-	while (rq) {
+	do {
 		next = rq->rq_next;
 		rq->rq_next = NULL;
 		ublk_dispatch_req(ubq, rq, issue_flags);
 		rq = next;
-	}
+	} while (rq);
 }
 
 static void ublk_queue_cmd_list(struct ublk_queue *ubq, struct rq_list *l)
 {
 	struct request *rq = rq_list_peek(l);
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/5] ublk: get ubq from pdu in ublk_cmd_list_tw_cb()
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 1/5] ublk: remove unused cmd argument to ublk_dispatch_req() Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 2/5] ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop Caleb Sander Mateos
@ 2025-03-28 18:04 ` Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 4/5] ublk: avoid redundant io->cmd in ublk_queue_cmd_list() Caleb Sander Mateos
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Caleb Sander Mateos @ 2025-03-28 18:04 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, linux-kernel, Caleb Sander Mateos

Save a few pointer dereferences by obtaining struct ublk_queue *ubq from
the ublk_uring_cmd_pdu instead of the request's mq_hctx.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 drivers/block/ublk_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 8b9780c0feab..9276d1fcc100 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1285,11 +1285,11 @@ static void ublk_queue_cmd(struct ublk_queue *ubq, struct request *rq)
 static void ublk_cmd_list_tw_cb(struct io_uring_cmd *cmd,
 		unsigned int issue_flags)
 {
 	struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
 	struct request *rq = pdu->req_list;
-	struct ublk_queue *ubq = rq->mq_hctx->driver_data;
+	struct ublk_queue *ubq = pdu->ubq;
 	struct request *next;
 
 	do {
 		next = rq->rq_next;
 		rq->rq_next = NULL;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/5] ublk: avoid redundant io->cmd in ublk_queue_cmd_list()
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
                   ` (2 preceding siblings ...)
  2025-03-28 18:04 ` [PATCH 3/5] ublk: get ubq from pdu in ublk_cmd_list_tw_cb() Caleb Sander Mateos
@ 2025-03-28 18:04 ` Caleb Sander Mateos
  2025-03-28 18:04 ` [PATCH 5/5] ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb() Caleb Sander Mateos
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Caleb Sander Mateos @ 2025-03-28 18:04 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, linux-kernel, Caleb Sander Mateos

ublk_queue_cmd_list() loads io->cmd twice. The intervening stores
prevent the compiler from combining the loads. Since struct ublk_io *io
is only used to compute io->cmd, replace the variable with io->cmd.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 drivers/block/ublk_drv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 9276d1fcc100..23250471562a 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1299,16 +1299,16 @@ static void ublk_cmd_list_tw_cb(struct io_uring_cmd *cmd,
 }
 
 static void ublk_queue_cmd_list(struct ublk_queue *ubq, struct rq_list *l)
 {
 	struct request *rq = rq_list_peek(l);
-	struct ublk_io *io = &ubq->ios[rq->tag];
-	struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(io->cmd);
+	struct io_uring_cmd *cmd = ubq->ios[rq->tag].cmd;
+	struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
 
 	pdu->req_list = rq;
 	rq_list_init(l);
-	io_uring_cmd_complete_in_task(io->cmd, ublk_cmd_list_tw_cb);
+	io_uring_cmd_complete_in_task(cmd, ublk_cmd_list_tw_cb);
 }
 
 static enum blk_eh_timer_return ublk_timeout(struct request *rq)
 {
 	struct ublk_queue *ubq = rq->mq_hctx->driver_data;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/5] ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb()
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
                   ` (3 preceding siblings ...)
  2025-03-28 18:04 ` [PATCH 4/5] ublk: avoid redundant io->cmd in ublk_queue_cmd_list() Caleb Sander Mateos
@ 2025-03-28 18:04 ` Caleb Sander Mateos
  2025-03-28 19:20 ` [PATCH 0/5] Minor ublk optimizations Jens Axboe
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Caleb Sander Mateos @ 2025-03-28 18:04 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, linux-kernel, Caleb Sander Mateos

Pass struct request *rq to ublk_cmd_tw_cb() through ublk_uring_cmd_pdu,
mirroring how it works for ublk_cmd_list_tw_cb(). This saves some
pointer dereferences, as well as the bounds check in blk_mq_tag_to_rq().

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 drivers/block/ublk_drv.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 23250471562a..466a23b89379 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -87,11 +87,14 @@ struct ublk_uring_cmd_pdu {
 	 *
 	 * It should have been stored to request payload, but we do want
 	 * to avoid extra pre-allocation, and uring_cmd payload is always
 	 * free for us
 	 */
-	struct request *req_list;
+	union {
+		struct request *req;
+		struct request *req_list;
+	};
 
 	/*
 	 * The following two are valid in this cmd whole lifetime, and
 	 * setup in ublk uring_cmd handler
 	 */
@@ -1266,22 +1269,21 @@ static void ublk_dispatch_req(struct ublk_queue *ubq,
 static void ublk_cmd_tw_cb(struct io_uring_cmd *cmd,
 			   unsigned int issue_flags)
 {
 	struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
 	struct ublk_queue *ubq = pdu->ubq;
-	int tag = pdu->tag;
-	struct request *req = blk_mq_tag_to_rq(
-		ubq->dev->tag_set.tags[ubq->q_id], tag);
 
-	ublk_dispatch_req(ubq, req, issue_flags);
+	ublk_dispatch_req(ubq, pdu->req, issue_flags);
 }
 
 static void ublk_queue_cmd(struct ublk_queue *ubq, struct request *rq)
 {
-	struct ublk_io *io = &ubq->ios[rq->tag];
+	struct io_uring_cmd *cmd = ubq->ios[rq->tag].cmd;
+	struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
 
-	io_uring_cmd_complete_in_task(io->cmd, ublk_cmd_tw_cb);
+	pdu->req = rq;
+	io_uring_cmd_complete_in_task(cmd, ublk_cmd_tw_cb);
 }
 
 static void ublk_cmd_list_tw_cb(struct io_uring_cmd *cmd,
 		unsigned int issue_flags)
 {
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] Minor ublk optimizations
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
                   ` (4 preceding siblings ...)
  2025-03-28 18:04 ` [PATCH 5/5] ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb() Caleb Sander Mateos
@ 2025-03-28 19:20 ` Jens Axboe
  2025-03-29  0:23 ` Ming Lei
  2025-03-29 11:57 ` Jens Axboe
  7 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2025-03-28 19:20 UTC (permalink / raw)
  To: Caleb Sander Mateos, Ming Lei; +Cc: linux-block, linux-kernel

On 3/28/25 12:04 PM, Caleb Sander Mateos wrote:
> A few cleanups on top of Ming's recent patch set that implemented
> ->queue_rqs() for ublk:
> https://lore.kernel.org/linux-block/20250327095123.179113-1-ming.lei@redhat.com/T/#u
> 
> Caleb Sander Mateos (5):
>   ublk: remove unused cmd argument to ublk_dispatch_req()
>   ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop
>   ublk: get ubq from pdu in ublk_cmd_list_tw_cb()
>   ublk: avoid redundant io->cmd in ublk_queue_cmd_list()
>   ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb()

All look like reasonable cleanups to me.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] Minor ublk optimizations
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
                   ` (5 preceding siblings ...)
  2025-03-28 19:20 ` [PATCH 0/5] Minor ublk optimizations Jens Axboe
@ 2025-03-29  0:23 ` Ming Lei
  2025-03-29 11:57 ` Jens Axboe
  7 siblings, 0 replies; 9+ messages in thread
From: Ming Lei @ 2025-03-29  0:23 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Jens Axboe, linux-block, linux-kernel

On Fri, Mar 28, 2025 at 12:04:06PM -0600, Caleb Sander Mateos wrote:
> A few cleanups on top of Ming's recent patch set that implemented
> ->queue_rqs() for ublk:
> https://lore.kernel.org/linux-block/20250327095123.179113-1-ming.lei@redhat.com/T/#u
> 
> Caleb Sander Mateos (5):
>   ublk: remove unused cmd argument to ublk_dispatch_req()
>   ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop
>   ublk: get ubq from pdu in ublk_cmd_list_tw_cb()
>   ublk: avoid redundant io->cmd in ublk_queue_cmd_list()
>   ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb()
> 
>  drivers/block/ublk_drv.c | 33 ++++++++++++++++-----------------
>  1 file changed, 16 insertions(+), 17 deletions(-)

All are nice cleanup, and pass builtin ublk selftest.

Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] Minor ublk optimizations
  2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
                   ` (6 preceding siblings ...)
  2025-03-29  0:23 ` Ming Lei
@ 2025-03-29 11:57 ` Jens Axboe
  7 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2025-03-29 11:57 UTC (permalink / raw)
  To: Ming Lei, Caleb Sander Mateos; +Cc: linux-block, linux-kernel


On Fri, 28 Mar 2025 12:04:06 -0600, Caleb Sander Mateos wrote:
> A few cleanups on top of Ming's recent patch set that implemented
> ->queue_rqs() for ublk:
> https://lore.kernel.org/linux-block/20250327095123.179113-1-ming.lei@redhat.com/T/#u
> 
> Caleb Sander Mateos (5):
>   ublk: remove unused cmd argument to ublk_dispatch_req()
>   ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop
>   ublk: get ubq from pdu in ublk_cmd_list_tw_cb()
>   ublk: avoid redundant io->cmd in ublk_queue_cmd_list()
>   ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb()
> 
> [...]

Applied, thanks!

[1/5] ublk: remove unused cmd argument to ublk_dispatch_req()
      commit: dfbce8b798fb848a42706e2e544b78b3db22aaae
[2/5] ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop
      commit: 9d7fa99189709b80eb16094aad18f7e492b835de
[3/5] ublk: get ubq from pdu in ublk_cmd_list_tw_cb()
      commit: 6a87fc437a034e4be2a63d8dfd4d2985c6c574bc
[4/5] ublk: avoid redundant io->cmd in ublk_queue_cmd_list()
      commit: 108d8aecaeeb52f5fbe98ac94da534954db1da44
[5/5] ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb()
      commit: 00cfc05cf81f58b1bc2650e18228350a094b1f6d

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-03-29 11:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-28 18:04 [PATCH 0/5] Minor ublk optimizations Caleb Sander Mateos
2025-03-28 18:04 ` [PATCH 1/5] ublk: remove unused cmd argument to ublk_dispatch_req() Caleb Sander Mateos
2025-03-28 18:04 ` [PATCH 2/5] ublk: skip 1 NULL check in ublk_cmd_list_tw_cb() loop Caleb Sander Mateos
2025-03-28 18:04 ` [PATCH 3/5] ublk: get ubq from pdu in ublk_cmd_list_tw_cb() Caleb Sander Mateos
2025-03-28 18:04 ` [PATCH 4/5] ublk: avoid redundant io->cmd in ublk_queue_cmd_list() Caleb Sander Mateos
2025-03-28 18:04 ` [PATCH 5/5] ublk: store req in ublk_uring_cmd_pdu for ublk_cmd_tw_cb() Caleb Sander Mateos
2025-03-28 19:20 ` [PATCH 0/5] Minor ublk optimizations Jens Axboe
2025-03-29  0:23 ` Ming Lei
2025-03-29 11:57 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox