[PATCH] nvme-pci: refactoring nvme_queue_rqs

Irvin Cote irvincoteg at gmail.com
Tue May 2 01:13:01 PDT 2023


When dealing with the queue_rqs callback, the block
layer guarantees that it only provides with us with
requests from the same queue (cf include/linux/blk-mq.h).
Therefore, we can reduce the code for nvme_queue_rqs.
We retrieve the nvmeq once because it is the same for all
the requests. Then the only thing the for loop does is 
test the requests and move them accordingly to requeue 
list. Finally we submit rqlist once outside the loop.

Signed-off-by: Irvin Cote <irvincoteg at gmail.com>
---
 drivers/nvme/host/pci.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 7f25c0fe3a0b..f6cbcb63fc5d 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -934,8 +934,9 @@ static void nvme_queue_rqs(struct request **rqlist)
 	struct request *req, *next, *prev = NULL;
 	struct request *requeue_list = NULL;
 
+	struct nvme_queue *nvmeq = *rqlist->mq_hctx->driver_data;
+
 	rq_list_for_each_safe(rqlist, req, next) {
-		struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
 
 		if (!nvme_prep_rq_batch(nvmeq, req)) {
 			/* detach 'req' and add to remainder list */
@@ -946,16 +947,11 @@ static void nvme_queue_rqs(struct request **rqlist)
 				continue;
 		}
 
-		if (!next || req->mq_hctx != next->mq_hctx) {
-			/* detach rest of list, and submit */
-			req->rq_next = NULL;
-			nvme_submit_cmds(nvmeq, rqlist);
-			*rqlist = next;
-			prev = NULL;
-		} else
-			prev = req;
+		prev = req;
 	}
 
+	nvme_submit_cmds(nvmeq, rqlist);
+
 	*rqlist = requeue_list;
 }
 
-- 
2.39.2




More information about the Linux-nvme mailing list