Skip to contentSkip to conversation

nvme-pci: deduplicate empty request list checks in nvme_queue_rqs()

PATCH In review Caleb Sander Mateos 2 participants 4 messages Nov 19, 2025 – Nov 20, 2025 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-pci: deduplicate empty request list checks in nvme_queue_rqs()

nvme_queue_rqs() checks that nvmeq is non-NULL before calling nvme_submit_cmds() and nvme_submit_cmds() checks that submit_list is non-empty before doing anything. A NULL nvmeq means no requests were processed from the rqlist in nvme_queue_rqs() since the last call to nvme_submit_cmds(), which implies submit_list is empty. So just check that submit_list is non-empty before calling nvme_submit_cmds() and drop the check for NULL nvmeq.

---
 drivers/nvme/host/pci.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/nvme/host/pci.c +4 -6
index 15c12e6cba88..8b562563ef89 100644
@@ -1199,13 +1199,10 @@ static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
 
 static void nvme_submit_cmds(struct nvme_queue *nvmeq, struct rq_list *rqlist)
 {
 	struct request *req;
 
-	if (rq_list_empty(rqlist))
-		return;
-
 	spin_lock(&nvmeq->sq_lock);
 	while ((req = rq_list_pop(rqlist))) {
 		struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
 
 		nvme_sq_copy_cmd(nvmeq, &iod->cmd);
@@ -1230,25 +1227,26 @@ static bool nvme_prep_rq_batch(struct nvme_queue *nvmeq, struct request *req)
 
 static void nvme_queue_rqs(struct rq_list *rqlist)
 {
 	struct rq_list submit_list = { };
 	struct rq_list requeue_list = { };
-	struct nvme_queue *nvmeq = NULL;
+	struct nvme_queue *nvmeq;
 	struct request *req;
 
 	while ((req = rq_list_pop(rqlist))) {
-		if (nvmeq && nvmeq != req->mq_hctx->driver_data)
+		if (!rq_list_empty(&submit_list) &&
+		    nvmeq != req->mq_hctx->driver_data)
 			nvme_submit_cmds(nvmeq, &submit_list);
 		nvmeq = req->mq_hctx->driver_data;
 
 		if (nvme_prep_rq_batch(nvmeq, req))
 			rq_list_add_tail(&submit_list, req);
 		else
 			rq_list_add_tail(&requeue_list, req);
 	}
 
-	if (nvmeq)
+	if (!rq_list_empty(&submit_list))
 		nvme_submit_cmds(nvmeq, &submit_list);
 	*rqlist = requeue_list;
 }
 
 static __always_inline void nvme_pci_unmap_rq(struct request *req)
Signature · 1 line
2.45.2
#1 lore raw
Quoted 7 lines · Caleb Sander Mateos

nvme_queue_rqs() checks that nvmeq is non-NULL before calling nvme_submit_cmds() and nvme_submit_cmds() checks that submit_list is non-empty before doing anything. A NULL nvmeq means no requests were processed from the rqlist in nvme_queue_rqs() since the last call to nvme_submit_cmds(), which implies submit_list is empty. So just check that submit_list is non-empty before calling nvme_submit_cmds() and drop the check for NULL nvmeq.

What is the rationale for this? I had a hard time understanding the logic in the new version, so I don't think this helps with readability at least.

#2 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Caleb Sander Mateos

nvme_queue_rqs() checks that nvmeq is non-NULL before calling nvme_submit_cmds() and nvme_submit_cmds() checks that submit_list is non-empty before doing anything. A NULL nvmeq means no requests were processed from the rqlist in nvme_queue_rqs() since the last call to nvme_submit_cmds(), which implies submit_list is empty. So just check that submit_list is non-empty before calling nvme_submit_cmds() and drop the check for NULL nvmeq.

Quoted 3 lines

What is the rationale for this? I had a hard time understanding the logic in the new version, so I don't think this helps with readability at least.

Just trying to avoid some branches. But if you prefer the current version, that's fine.

Best,
Caleb

#3 lore raw
Quoted 11 lines · Caleb Sander Mateos
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Caleb Sander Mateos

nvme_queue_rqs() checks that nvmeq is non-NULL before calling nvme_submit_cmds() and nvme_submit_cmds() checks that submit_list is non-empty before doing anything. A NULL nvmeq means no requests were processed from the rqlist in nvme_queue_rqs() since the last call to nvme_submit_cmds(), which implies submit_list is empty. So just check that submit_list is non-empty before calling nvme_submit_cmds() and drop the check for NULL nvmeq.

Quoted 6 lines
Quoted 3 lines

What is the rationale for this? I had a hard time understanding the logic in the new version, so I don't think this helps with readability at least.

Just trying to avoid some branches. But if you prefer the current version, that's fine.

I find the current version easier to follow. If there is a good reason for the new variant I'm ok with it.