Skip to contentSkip to conversation

Add support for list issue

PATCH Superseded Jens Axboe 3 participants 16 messages Dec 3, 2021 – Dec 6, 2021

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

v2 cover Add support for list issue

Hi,

With the support in 5.16-rc1 for allocating and completing batches of IO, the one missing piece is passing down a list of requests for issue. Drivers can take advantage of this by defining an mq_ops->queue_rqs() hook.

This implements it for NVMe, allowing copy of multiple commands in one swoop.

This is good for around a 500K IOPS/core improvement in my testing, which is around a 5-6% improvement in efficiency.

Changes since v1:

- Addressed review comments
- Rebase on top of Ming's hctx lock change
- Clean ups
- Bypass for shared tags

Signature · 1 line
Jens Axboe
author maintainer
#1 lore raw

PATCH v2 1/4 block: add mq_ops->queue_rqs hook

If we have a list of requests in our plug list, send it to the driver in one go, if possible. The driver must set mq_ops->queue_rqs() to support this, if not the usual one-by-one path is used.

---
 block/blk-mq.c         | 24 +++++++++++++++++++++---
 include/linux/blk-mq.h |  8 ++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
block/blk-mq.c +21 -3
index 22ec21aa0c22..9ac9174a2ba4 100644
@@ -2513,6 +2513,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 {
 	struct blk_mq_hw_ctx *this_hctx;
 	struct blk_mq_ctx *this_ctx;
+	struct request *rq;
 	unsigned int depth;
 	LIST_HEAD(list);
 
@@ -2521,7 +2522,26 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 	plug->rq_count = 0;
 
 	if (!plug->multiple_queues && !plug->has_elevator && !from_schedule) {
-		blk_mq_run_dispatch_ops(plug->mq_list->q,
+		struct request_queue *q;
+
+		rq = plug->mq_list;
+		q = rq->q;
+
+		/*
+		 * Peek first request and see if we have a ->queue_rqs() hook.
+		 * If we do, we can dispatch the whole plug list in one go. We
+		 * already know at this point that all requests belong to the
+		 * same queue, caller must ensure that's the case.
+		 */
+		if (q->mq_ops->queue_rqs &&
+		    !(rq->mq_hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)) {
+			blk_mq_run_dispatch_ops(q,
+				q->mq_ops->queue_rqs(&plug->mq_list));
+			if (rq_list_empty(plug->mq_list))
+				return;
+		}
+
+		blk_mq_run_dispatch_ops(q,
 				blk_mq_plug_issue_direct(plug, false));
 		if (rq_list_empty(plug->mq_list))
 			return;
@@ -2531,8 +2551,6 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 	this_ctx = NULL;
 	depth = 0;
 	do {
-		struct request *rq;
-
 		rq = rq_list_pop(&plug->mq_list);
 
 		if (!this_hctx) {
include/linux/blk-mq.h +8 -0
index ecdc049b52fa..cdd183757ea0 100644
@@ -494,6 +494,14 @@ struct blk_mq_ops {
 	 */
 	void (*commit_rqs)(struct blk_mq_hw_ctx *);
 
+	/**
+	 * @queue_rqs: Queue a list of new requests. Driver is guaranteed
+	 * that each request belongs to the same queue. If the driver doesn't
+	 * empty the @rqlist completely, then the rest will be queued
+	 * individually by the block layer upon return.
+	 */
+	void (*queue_rqs)(struct request **rqlist);
+
 	/**
 	 * @get_budget: Reserve budget before queue request, once .queue_rq is
 	 * run, it is driver's responsibility to release the
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH v2 2/4 nvme: split command copy into a helper

In reply to Jens Axboe

We'll need it for batched submit as well.

---
 drivers/nvme/host/pci.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/nvme/host/pci.c +10 -4
index 8637538f3fd5..09ea21f75439 100644
@@ -500,6 +500,15 @@ static inline void nvme_write_sq_db(struct nvme_queue *nvmeq, bool write_sq)
 	nvmeq->last_sq_tail = nvmeq->sq_tail;
 }
 
+static inline void nvme_sq_copy_cmd(struct nvme_queue *nvmeq,
+				    struct nvme_command *cmd)
+{
+	memcpy(nvmeq->sq_cmds + (nvmeq->sq_tail << nvmeq->sqes), cmd,
+		sizeof(*cmd));
+	if (++nvmeq->sq_tail == nvmeq->q_depth)
+		nvmeq->sq_tail = 0;
+}
+
 /**
  * nvme_submit_cmd() - Copy a command into a queue and ring the doorbell
  * @nvmeq: The queue to use
@@ -510,10 +519,7 @@ static void nvme_submit_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd,
 			    bool write_sq)
 {
 	spin_lock(&nvmeq->sq_lock);
-	memcpy(nvmeq->sq_cmds + (nvmeq->sq_tail << nvmeq->sqes),
-	       cmd, sizeof(*cmd));
-	if (++nvmeq->sq_tail == nvmeq->q_depth)
-		nvmeq->sq_tail = 0;
+	nvme_sq_copy_cmd(nvmeq, cmd);
 	nvme_write_sq_db(nvmeq, write_sq);
 	spin_unlock(&nvmeq->sq_lock);
 }
Signature · 1 line
2.34.1
author maintainer
#10 lore raw

PATCH v2 3/4 nvme: separate command prep and issue

In reply to Jens Axboe

Add a nvme_prep_rq() helper to setup a command, and nvme_queue_rq() is adapted to use this helper.

---
 drivers/nvme/host/pci.c | 57 ++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 24 deletions(-)
drivers/nvme/host/pci.c +33 -24
index 09ea21f75439..6be6b1ab4285 100644
@@ -918,52 +918,32 @@ static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req,
 	return BLK_STS_OK;
 }
 
-/*
- * NOTE: ns is NULL when called on the admin queue.
- */
-static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
-			 const struct blk_mq_queue_data *bd)
+static blk_status_t nvme_prep_rq(struct nvme_dev *dev, struct request *req)
 {
-	struct nvme_ns *ns = hctx->queue->queuedata;
-	struct nvme_queue *nvmeq = hctx->driver_data;
-	struct nvme_dev *dev = nvmeq->dev;
-	struct request *req = bd->rq;
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
-	struct nvme_command *cmnd = &iod->cmd;
 	blk_status_t ret;
 
 	iod->aborted = 0;
 	iod->npages = -1;
 	iod->nents = 0;
 
-	/*
-	 * We should not need to do this, but we're still using this to
-	 * ensure we can drain requests on a dying queue.
-	 */
-	if (unlikely(!test_bit(NVMEQ_ENABLED, &nvmeq->flags)))
-		return BLK_STS_IOERR;
-
-	if (!nvme_check_ready(&dev->ctrl, req, true))
-		return nvme_fail_nonready_command(&dev->ctrl, req);
-
-	ret = nvme_setup_cmd(ns, req);
+	ret = nvme_setup_cmd(req->q->queuedata, req);
 	if (ret)
 		return ret;
 
 	if (blk_rq_nr_phys_segments(req)) {
-		ret = nvme_map_data(dev, req, cmnd);
+		ret = nvme_map_data(dev, req, &iod->cmd);
 		if (ret)
 			goto out_free_cmd;
 	}
 
 	if (blk_integrity_rq(req)) {
-		ret = nvme_map_metadata(dev, req, cmnd);
+		ret = nvme_map_metadata(dev, req, &iod->cmd);
 		if (ret)
 			goto out_unmap_data;
 	}
 
 	blk_mq_start_request(req);
-	nvme_submit_cmd(nvmeq, cmnd, bd->last);
 	return BLK_STS_OK;
 out_unmap_data:
 	nvme_unmap_data(dev, req);
@@ -972,6 +952,35 @@ static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
 	return ret;
 }
 
+/*
+ * NOTE: ns is NULL when called on the admin queue.
+ */
+static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
+			 const struct blk_mq_queue_data *bd)
+{
+	struct nvme_queue *nvmeq = hctx->driver_data;
+	struct nvme_dev *dev = nvmeq->dev;
+	struct request *req = bd->rq;
+	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
+	blk_status_t ret;
+
+	/*
+	 * We should not need to do this, but we're still using this to
+	 * ensure we can drain requests on a dying queue.
+	 */
+	if (unlikely(!test_bit(NVMEQ_ENABLED, &nvmeq->flags)))
+		return BLK_STS_IOERR;
+
+	if (unlikely(!nvme_check_ready(&dev->ctrl, req, true)))
+		return nvme_fail_nonready_command(&dev->ctrl, req);
+
+	ret = nvme_prep_rq(dev, req);
+	if (unlikely(ret))
+		return ret;
+	nvme_submit_cmd(nvmeq, &iod->cmd, bd->last);
+	return BLK_STS_OK;
+}
+
 static __always_inline void nvme_pci_unmap_rq(struct request *req)
 {
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
Signature · 1 line
2.34.1
author maintainer
#12 lore raw

PATCH v2 4/4 nvme: add support for mq_ops->queue_rqs()

In reply to Jens Axboe

This enables the block layer to send us a full plug list of requests that need submitting. The block layer guarantees that they all belong to the same queue, but we do have to check the hardware queue mapping for each request.

If errors are encountered, leave them in the passed in list. Then the block layer will handle them individually.

This is good for about a 4% improvement in peak performance, taking us from 9.6M to 10M IOPS/core.

---
 drivers/nvme/host/pci.c | 61 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
drivers/nvme/host/pci.c +61 -0
index 6be6b1ab4285..197aa45ef7ef 100644
@@ -981,6 +981,66 @@ static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
 	return BLK_STS_OK;
 }
 
+static void nvme_submit_cmds(struct nvme_queue *nvmeq, struct request **rqlist)
+{
+	spin_lock(&nvmeq->sq_lock);
+	while (!rq_list_empty(*rqlist)) {
+		struct request *req = rq_list_pop(rqlist);
+		struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
+
+		memcpy(nvmeq->sq_cmds + (nvmeq->sq_tail << nvmeq->sqes),
+				absolute_pointer(&iod->cmd), sizeof(iod->cmd));
+		if (++nvmeq->sq_tail == nvmeq->q_depth)
+			nvmeq->sq_tail = 0;
+	}
+	nvme_write_sq_db(nvmeq, true);
+	spin_unlock(&nvmeq->sq_lock);
+}
+
+static bool nvme_prep_rq_batch(struct nvme_queue *nvmeq, struct request *req)
+{
+	/*
+	 * We should not need to do this, but we're still using this to
+	 * ensure we can drain requests on a dying queue.
+	 */
+	if (unlikely(!test_bit(NVMEQ_ENABLED, &nvmeq->flags)))
+		return false;
+	if (unlikely(!nvme_check_ready(&nvmeq->dev->ctrl, req, true)))
+		return false;
+
+	req->mq_hctx->tags->rqs[req->tag] = req;
+	return nvme_prep_rq(nvmeq->dev, req) == BLK_STS_OK;
+}
+
+static void nvme_queue_rqs(struct request **rqlist)
+{
+	struct request *req = rq_list_peek(rqlist), *prev = NULL;
+	struct request *requeue_list = NULL;
+
+	do {
+		struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
+
+		if (!nvme_prep_rq_batch(nvmeq, req)) {
+			/* detach 'req' and add to remainder list */
+			if (prev)
+				prev->rq_next = req->rq_next;
+			rq_list_add(&requeue_list, req);
+		} else {
+			prev = req;
+		}
+
+		req = rq_list_next(req);
+		if (!req || (prev && req->mq_hctx != prev->mq_hctx)) {
+			/* detach rest of list, and submit */
+			prev->rq_next = NULL;
+			nvme_submit_cmds(nvmeq, rqlist);
+			*rqlist = req;
+		}
+	} while (req);
+
+	*rqlist = requeue_list;
+}
+
 static __always_inline void nvme_pci_unmap_rq(struct request *req)
 {
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
@@ -1678,6 +1738,7 @@ static const struct blk_mq_ops nvme_mq_admin_ops = {
 
 static const struct blk_mq_ops nvme_mq_ops = {
 	.queue_rq	= nvme_queue_rq,
+	.queue_rqs	= nvme_queue_rqs,
 	.complete	= nvme_pci_complete_rq,
 	.commit_rqs	= nvme_commit_rqs,
 	.init_hctx	= nvme_init_hctx,
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/4] block: add mq_ops->queue_rqs hook

In reply to Jens Axboe
Quoted 30 lines · Jens Axboe

If we have a list of requests in our plug list, send it to the driver in one go, if possible. The driver must set mq_ops->queue_rqs() to support this, if not the usual one-by-one path is used.

---
  block/blk-mq.c         | 24 +++++++++++++++++++++---
  include/linux/blk-mq.h |  8 ++++++++
  2 files changed, 29 insertions(+), 3 deletions(-)
block/blk-mq.c +4 -1
index 22ec21aa0c22..9ac9174a2ba4 100644
@@ -2513,6 +2513,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  {
  	struct blk_mq_hw_ctx *this_hctx;
  	struct blk_mq_ctx *this_ctx;
+	struct request *rq;
  	unsigned int depth;
  	LIST_HEAD(list);
 
@@ -2521,7 +2522,26 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  	plug->rq_count = 0;
 
  	if (!plug->multiple_queues && !plug->has_elevator && !from_schedule) {
-		blk_mq_run_dispatch_ops(plug->mq_list->q,
+		struct request_queue *q;
+
+		rq = plug->mq_list;

block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) · line 2537

Quoted 10 lines
block/blk-mq.c +10 -0
+		q = rq->q;
+
+		/*
+		 * Peek first request and see if we have a ->queue_rqs() hook.
+		 * If we do, we can dispatch the whole plug list in one go. We
+		 * already know at this point that all requests belong to the
+		 * same queue, caller must ensure that's the case.
+		 */
+		if (q->mq_ops->queue_rqs &&
+		    !(rq->mq_hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)) {

What is the dependency on shared tags here?
From what I've seen it's just about submitting requests; the only difference to shared tags is the way the tags are allocated. Care to explain?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v2 2/4
#7 lore raw

Re: [PATCH 2/4] nvme: split command copy into a helper

In reply to Jens Axboe
Quoted 31 lines · Jens Axboe

We'll need it for batched submit as well.

---
  drivers/nvme/host/pci.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
drivers/nvme/host/pci.c +9 -0
index 8637538f3fd5..09ea21f75439 100644
@@ -500,6 +500,15 @@ static inline void nvme_write_sq_db(struct nvme_queue *nvmeq, bool write_sq)
  	nvmeq->last_sq_tail = nvmeq->sq_tail;
  }
 
+static inline void nvme_sq_copy_cmd(struct nvme_queue *nvmeq,
+				    struct nvme_command *cmd)
+{
+	memcpy(nvmeq->sq_cmds + (nvmeq->sq_tail << nvmeq->sqes), cmd,
+		sizeof(*cmd));
+	if (++nvmeq->sq_tail == nvmeq->q_depth)
+		nvmeq->sq_tail = 0;
+}
+
  /**
   * nvme_submit_cmd() - Copy a command into a queue and ring the doorbell
   * @nvmeq: The queue to use
@@ -510,10 +519,7 @@ static void nvme_submit_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd,
  			    bool write_sq)

drivers/nvme/host/pci.c static void nvme_submit_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd, · line 525

Quoted 10 lines
drivers/nvme/host/pci.c +1 -4
  {
  	spin_lock(&nvmeq->sq_lock);
-	memcpy(nvmeq->sq_cmds + (nvmeq->sq_tail << nvmeq->sqes),
-	       cmd, sizeof(*cmd));
-	if (++nvmeq->sq_tail == nvmeq->q_depth)
-		nvmeq->sq_tail = 0;
+	nvme_sq_copy_cmd(nvmeq, cmd);
  	nvme_write_sq_db(nvmeq, write_sq);
  	spin_unlock(&nvmeq->sq_lock);
  }

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v2 3/4
#11 lore raw

Re: [PATCH 3/4] nvme: separate command prep and issue

In reply to Jens Axboe
Quoted 8 lines · Jens Axboe

Add a nvme_prep_rq() helper to setup a command, and nvme_queue_rq() is adapted to use this helper.

---
  drivers/nvme/host/pci.c | 57 ++++++++++++++++++++++++-----------------
  1 file changed, 33 insertions(+), 24 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v2 4/4
#13 lore raw

Re: [PATCH 4/4] nvme: add support for mq_ops->queue_rqs()

In reply to Jens Axboe
Quoted 8 lines · Jens Axboe

This enables the block layer to send us a full plug list of requests that need submitting. The block layer guarantees that they all belong to the same queue, but we do have to check the hardware queue mapping for each request.

If errors are encountered, leave them in the passed in list. Then the block layer will handle them individually.

Quoted 8 lines

This is good for about a 4% improvement in peak performance, taking us from 9.6M to 10M IOPS/core.

---
  drivers/nvme/host/pci.c | 61 +++++++++++++++++++++++++++++++++++++++++
  1 file changed, 61 insertions(+)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
author maintainer
#3 lore raw

Re: [PATCH 1/4] block: add mq_ops->queue_rqs hook

In reply to Hannes Reinecke
Quoted 38 lines · Hannes Reinecke
Quoted 37 lines · Jens Axboe

If we have a list of requests in our plug list, send it to the driver in one go, if possible. The driver must set mq_ops->queue_rqs() to support this, if not the usual one-by-one path is used.

---
  block/blk-mq.c         | 24 +++++++++++++++++++++---
  include/linux/blk-mq.h |  8 ++++++++
  2 files changed, 29 insertions(+), 3 deletions(-)
block/blk-mq.c +11 -1
index 22ec21aa0c22..9ac9174a2ba4 100644
@@ -2513,6 +2513,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  {
  	struct blk_mq_hw_ctx *this_hctx;
  	struct blk_mq_ctx *this_ctx;
+	struct request *rq;
  	unsigned int depth;
  	LIST_HEAD(list);
 
@@ -2521,7 +2522,26 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  	plug->rq_count = 0;
 
  	if (!plug->multiple_queues && !plug->has_elevator && !from_schedule) {
-		blk_mq_run_dispatch_ops(plug->mq_list->q,
+		struct request_queue *q;
+
+		rq = plug->mq_list;
+		q = rq->q;
+
+		/*
+		 * Peek first request and see if we have a ->queue_rqs() hook.
+		 * If we do, we can dispatch the whole plug list in one go. We
+		 * already know at this point that all requests belong to the
+		 * same queue, caller must ensure that's the case.
Quoted 8 lines

block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) · line 2537

Quoted 3 lines
block/blk-mq.c +3 -0
+		 */
+		if (q->mq_ops->queue_rqs &&
+		    !(rq->mq_hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)) {

What is the dependency on shared tags here?
From what I've seen it's just about submitting requests; the only
difference to shared tags is the way the tags are allocated. Care to explain?

For shared tags, we need to actively increment the use count per request. This path doesn't do that, so it's disabled for now. It could be done, but then it'd have to be in the caller, so I'd rather leave it for a future optimization if anyone cares enough about this for shared tags.

I can add a comment about it if that helps.

Signature · 1 line
Jens Axboe
#4 lore raw

Re: [PATCH 1/4] block: add mq_ops->queue_rqs hook

Quoted 48 lines · Jens Axboe
Quoted 38 lines · Hannes Reinecke
Quoted 37 lines · Jens Axboe

If we have a list of requests in our plug list, send it to the driver in one go, if possible. The driver must set mq_ops->queue_rqs() to support this, if not the usual one-by-one path is used.

---
   block/blk-mq.c         | 24 +++++++++++++++++++++---
   include/linux/blk-mq.h |  8 ++++++++
   2 files changed, 29 insertions(+), 3 deletions(-)
block/blk-mq.c +11 -1
index 22ec21aa0c22..9ac9174a2ba4 100644
@@ -2513,6 +2513,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
   {
   	struct blk_mq_hw_ctx *this_hctx;
   	struct blk_mq_ctx *this_ctx;
+	struct request *rq;
   	unsigned int depth;
   	LIST_HEAD(list);
 
@@ -2521,7 +2522,26 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
   	plug->rq_count = 0;
 
   	if (!plug->multiple_queues && !plug->has_elevator && !from_schedule) {
-		blk_mq_run_dispatch_ops(plug->mq_list->q,
+		struct request_queue *q;
+
+		rq = plug->mq_list;
+		q = rq->q;
+
+		/*
+		 * Peek first request and see if we have a ->queue_rqs() hook.
+		 * If we do, we can dispatch the whole plug list in one go. We
+		 * already know at this point that all requests belong to the
+		 * same queue, caller must ensure that's the case.
Quoted 8 lines

block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) · line 2537

Quoted 3 lines
block/blk-mq.c +3 -0
+		 */
+		if (q->mq_ops->queue_rqs &&
+		    !(rq->mq_hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)) {

What is the dependency on shared tags here?
From what I've seen it's just about submitting requests; the only
difference to shared tags is the way the tags are allocated. Care to explain?

Quoted 8 lines

For shared tags, we need to actively increment the use count per request. This path doesn't do that, so it's disabled for now. It could be done, but then it'd have to be in the caller, so I'd rather leave it for a future optimization if anyone cares enough about this for shared tags.

I can add a comment about it if that helps.

Please do.
It'll act as a reminder what needs to be done if and when one of the drivers requiring shared tags is looking at implementing queue_rqs.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
author maintainer
#5 lore raw

Re: [PATCH 1/4] block: add mq_ops->queue_rqs hook

Quoted 55 lines · Hannes Reinecke
Quoted 54 lines · Jens Axboe
Quoted 38 lines · Hannes Reinecke
Quoted 37 lines · Jens Axboe

If we have a list of requests in our plug list, send it to the driver in one go, if possible. The driver must set mq_ops->queue_rqs() to support this, if not the usual one-by-one path is used.

---
   block/blk-mq.c         | 24 +++++++++++++++++++++---
   include/linux/blk-mq.h |  8 ++++++++
   2 files changed, 29 insertions(+), 3 deletions(-)
block/blk-mq.c +11 -1
index 22ec21aa0c22..9ac9174a2ba4 100644
@@ -2513,6 +2513,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
   {
   	struct blk_mq_hw_ctx *this_hctx;
   	struct blk_mq_ctx *this_ctx;
+	struct request *rq;
   	unsigned int depth;
   	LIST_HEAD(list);
 
@@ -2521,7 +2522,26 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
   	plug->rq_count = 0;
 
   	if (!plug->multiple_queues && !plug->has_elevator && !from_schedule) {
-		blk_mq_run_dispatch_ops(plug->mq_list->q,
+		struct request_queue *q;
+
+		rq = plug->mq_list;
+		q = rq->q;
+
+		/*
+		 * Peek first request and see if we have a ->queue_rqs() hook.
+		 * If we do, we can dispatch the whole plug list in one go. We
+		 * already know at this point that all requests belong to the
+		 * same queue, caller must ensure that's the case.
Quoted 8 lines

block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) · line 2537

Quoted 3 lines
block/blk-mq.c +3 -0
+		 */
+		if (q->mq_ops->queue_rqs &&
+		    !(rq->mq_hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)) {

What is the dependency on shared tags here?
From what I've seen it's just about submitting requests; the only
difference to shared tags is the way the tags are allocated. Care to explain?

For shared tags, we need to actively increment the use count per request. This path doesn't do that, so it's disabled for now. It could be done, but then it'd have to be in the caller, so I'd rather leave it for a future optimization if anyone cares enough about this for shared tags.

Quoted 5 lines
Quoted 2 lines

I can add a comment about it if that helps.

Please do.
It'll act as a reminder what needs to be done if and when one of the drivers requiring shared tags is looking at implementing queue_rqs.

I added to the comment yesterday:

https://git.kernel.dk/cgit/linux-block/commit/?h=perf-wip&id=f9f526700607bf804fa8541c824ea54253f4241a

Signature · 1 line
Jens Axboe
#8 lore raw

Re: [PATCH 2/4] nvme: split command copy into a helper

In reply to Jens Axboe

As mentioned last time I really don't like the proliferation of tiny helpers with just two callers. See my patch I responded with for my alternative.

#14 lore raw

Re: [PATCH 4/4] nvme: add support for mq_ops->queue_rqs()

In reply to Jens Axboe
Quoted 10 lines · Jens Axboe

This enables the block layer to send us a full plug list of requests that need submitting. The block layer guarantees that they all belong to the same queue, but we do have to check the hardware queue mapping for each request.

If errors are encountered, leave them in the passed in list. Then the block layer will handle them individually.

This is good for about a 4% improvement in peak performance, taking us from 9.6M to 10M IOPS/core.

This looks pretty similar to my proposed cleanups (which is nice), but back then you mentioned the cleaner version was much slower. Do you know what brought the speed back in this version?

author maintainer
#9 lore raw

Re: [PATCH 2/4] nvme: split command copy into a helper

In reply to Christoph Hellwig
Quoted 3 lines · Christoph Hellwig

As mentioned last time I really don't like the proliferation of tiny helpers with just two callers. See my patch I responded with for my alternative.

I tend to agree with you, but for this particular case I really don't think it's better to not have the helper. I did try that version too, but you end up with several sites duplicating it. So while I agree in general, I don't think this one applies.

Signature · 1 line
Jens Axboe
author maintainer
#15 lore raw

Re: [PATCH 4/4] nvme: add support for mq_ops->queue_rqs()

In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Jens Axboe

This enables the block layer to send us a full plug list of requests that need submitting. The block layer guarantees that they all belong to the same queue, but we do have to check the hardware queue mapping for each request.

If errors are encountered, leave them in the passed in list. Then the block layer will handle them individually.

Quoted 6 lines
Quoted 2 lines

This is good for about a 4% improvement in peak performance, taking us from 9.6M to 10M IOPS/core.

This looks pretty similar to my proposed cleanups (which is nice), but back then you mentioned the cleaner version was much slower. Do you know what brought the speed back in this version?

Yes, it has that folded in and tweaked on top. Current version seems to be fine.

Signature · 1 line
Jens Axboe