Skip to contentSkip to conversation

nvme-pci: check CQ after batch submission for Microsoft device

PATCH Superseded Ming Lei 3 participants 8 messages Nov 13, 2019 – Nov 14, 2019 NVMe

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

v2 cover nvme-pci: check CQ after batch submission for Microsoft device

Hi,

The two patches fix one performance regression on Microsoft Corporation device. The root cause is that Microsoft device applies aggressive interrupt coalescing, so single job fio performance drops much after we removes checking cq in f9dde187fa92("nvme-pci: remove cq check after submission").

Turns out this issue is very specific on Microsoft device, so add a quirk for checking CQ on this device.

V2:
- only check CQ for Microsoft device.

Ming Lei (2):
nvme-pci: move sq/cq_poll lock initialization into nvme_init_queue
nvme-pci: check CQ after batch submission for Microsoft device

 drivers/nvme/host/nvme.h |  6 +++
 drivers/nvme/host/pci.c  | 98 ++++++++++++++++++++++++++++++++++------
 2 files changed, 91 insertions(+), 13 deletions(-)
Cc Keith Busch <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Sagi Grimberg <[email protected]>
Cc Long Li <[email protected]>
Signature · 7 lines
2.20.1


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
author
#1 lore raw

PATCH v2 1/2 nvme-pci: move sq/cq_poll lock initialization into nvme_init_queue

Prepare for adding new cq lock for improving IO performance in case that device applies aggressive interrupt coalescing, and the new added cq_lock can share space with cq_poll_lock becasue both are mutually exclusive.

Move sq/cq_poll lock initialization into nvme_init_queue so that we may initialize the added cq_lock correctly and lockdep warning can be avoided.

This way is safe because no IO can be started until nvme_init_queue is returned.

Cc Keith Busch <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Sagi Grimberg <[email protected]>
Cc Long Li <[email protected]>
---
 drivers/nvme/host/pci.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +3 -2
index 869f462e6b6e..01728409a7ea 100644
@@ -1481,8 +1481,6 @@ static int nvme_alloc_queue(struct nvme_dev *dev, int qid, int depth)
 		goto free_cqdma;
 
 	nvmeq->dev = dev;
-	spin_lock_init(&nvmeq->sq_lock);
-	spin_lock_init(&nvmeq->cq_poll_lock);
 	nvmeq->cq_head = 0;
 	nvmeq->cq_phase = 1;
 	nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
@@ -1516,6 +1514,9 @@ static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid)
 {
 	struct nvme_dev *dev = nvmeq->dev;
 
+	spin_lock_init(&nvmeq->sq_lock);
+	spin_lock_init(&nvmeq->cq_poll_lock);
+
 	nvmeq->sq_tail = 0;
 	nvmeq->last_sq_tail = 0;
 	nvmeq->cq_head = 0;
Signature · 7 lines
2.20.1


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
author
#2 lore raw

PATCH v2 2/2 nvme-pci: check CQ after batch submission for Microsoft device

In reply to Ming Lei

f9dde187fa92("nvme-pci: remove cq check after submission") removes cq check after submission, this change actually causes performance regression on Microsoft Corporation device in which aggressive interrupt coalescing is used, for example, the max single interrupt per second can reach 40~50K at most.

Checking CQ after submission can improve IO completion for Microsoft Corporation device:

1) the check is very cheap, and lockless check on cq is enough, see nvme_cqe_pending(). Especially the check can be done after batch submission is done. Compared with the big latency added by aggressive interrupt coalescing, cost of the check can be ignored.

2) when IO completion is observed via checking CQ in submission, the requst may be completed without interrupt involved, or the interrupt handler overload can be decreased.

3) when single sw queue is submiting IOs to this hw queue, if IOs completion is observed via this check, the IO can be completed locally, which is cheaper than remote completion.

Follows test result done on Azure L80sv2 guest with NVMe drive( Microsoft Corporation Device b111). This guest has 80 CPUs and 10 numa nodes, and each NVMe drive supports 8 hw queues.

1) test script:

fio --bs=4k --ioengine=libaio --iodepth=64 --filename=/dev/nvme0n1 \
	--iodepth_batch_submit=16 --iodepth_batch_complete_min=16 \
	--direct=1 --runtime=30 --numjobs=1 --rw=randread \
	--name=test --group_reporting --gtod_reduce=1

2) test result:
| v5.3 | v5.3 with this patchset
-------------------------------------------
IOPS | 130K | 424K

Given IO is handled more efficiently in this way, the original report of CPU lockup[1] on Hyper-V can't be observed any more after this patch is applied, since this patch reduces IO completions much in interrupt handler.

[1] https://lore.kernel.org/lkml/[email protected]

Cc Keith Busch <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Sagi Grimberg <[email protected]>
Cc Long Li <[email protected]>
Fixes f9dde187fa92("nvme-pci: remove cq check after submission")
---
 drivers/nvme/host/nvme.h |  6 +++
 drivers/nvme/host/pci.c  | 95 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 89 insertions(+), 12 deletions(-)
drivers/nvme/host/nvme.h +6 -0
index 22e8401352c2..5575827016d1 100644
@@ -115,6 +115,12 @@ enum nvme_quirks {
 	 * Prevent tag overlap between queues
 	 */
 	NVME_QUIRK_SHARED_TAGS                  = (1 << 13),
+
+	/*
+	 * Check CQ in submission for improving performance since
+	 * the device applies aggressive interrupt coalescing
+	 */
+	NVME_QUIRK_CHECK_CQ			= (1 << 14),
 };
 
 /*
drivers/nvme/host/pci.c +83 -12

190 lines not on this page · raw message

Signature · 7 lines
2.20.1


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
maintainer
#3 lore raw

drivers/nvme/host/pci.c static irqreturn_t nvme_irq_check(int irq, void *data) · line 1096

Quoted 7 lines · Ming Lei
drivers/nvme/host/pci.c +7 -0
+static void nvme_check_cq(struct nvme_queue *nvmeq)
+{
+	if (test_bit(NVMEQ_CHECK_CQ, &nvmeq->flags) &&
+			nvme_cqe_pending(nvmeq)) {
+		unsigned long flags;
+
+		if (spin_trylock_irqsave(&nvmeq->cq_lock, flags)) {

What's with the irqsave? This isn't called from an irq disabled context.

Not saying I'm on board with this approach, though. Checking the cq during submission was cheap when submission and completion sides shared the same lock, but this quite different than what we previously had.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author
#4 lore raw
Quoted 10 lines · Keith Busch

drivers/nvme/host/pci.c static irqreturn_t nvme_irq_check(int irq, void *data) · line 1096

Quoted 7 lines · Ming Lei
drivers/nvme/host/pci.c +7 -0
+static void nvme_check_cq(struct nvme_queue *nvmeq)
+{
+	if (test_bit(NVMEQ_CHECK_CQ, &nvmeq->flags) &&
+			nvme_cqe_pending(nvmeq)) {
+		unsigned long flags;
+
+		if (spin_trylock_irqsave(&nvmeq->cq_lock, flags)) {

What's with the irqsave? This isn't called from an irq disabled context.

Because .cq_lock is required in nvme irq handler.

Quoted 2 lines

Not saying I'm on board with this approach, though. Checking the cq

I am open for other approach if the issue can be solved.

Quoted 2 lines

during submission was cheap when submission and completion sides shared the same lock, but this quite different than what we previously had.

Previously we have single .q_lock to cover both completion and submission.

Now we have splited the lock into two, that is why this patch added .cq_lock for this purpose.

Thanks,
Ming

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author
#5 lore raw
Quoted 12 lines · Ming Lei
Quoted 10 lines · Keith Busch

drivers/nvme/host/pci.c static irqreturn_t nvme_irq_check(int irq, void *data) · line 1096

Quoted 7 lines · Ming Lei
drivers/nvme/host/pci.c +7 -0
+static void nvme_check_cq(struct nvme_queue *nvmeq)
+{
+	if (test_bit(NVMEQ_CHECK_CQ, &nvmeq->flags) &&
+			nvme_cqe_pending(nvmeq)) {
+		unsigned long flags;
+
+		if (spin_trylock_irqsave(&nvmeq->cq_lock, flags)) {

What's with the irqsave? This isn't called from an irq disabled context.

Quoted 1 line

Because .cq_lock is required in nvme irq handler.

However, it can be changed to spin_trylock_irq().

thanks,
Ming

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#6 lore raw
In reply to Ming Lei

drivers/nvme/host/pci.c struct nvme_queue { · line 175

Quoted 11 lines · Ming Lei

spinlock_t sq_lock;
void *sq_cmds;
/* only used for poll queues: */

drivers/nvme/host/pci.c +4 -1
-	spinlock_t cq_poll_lock ____cacheline_aligned_in_smp;
+	union {
+		spinlock_t cq_poll_lock;
+		spinlock_t cq_lock;
+	}____cacheline_aligned_in_smp;
  	volatile struct nvme_completion *cqes;
  	struct blk_mq_tags **tags;
  	dma_addr_t sq_dma_addr;

Still not sure I follow the case for another lock (seems to me like just a semantic distinction, as they both basically bracket nvme_process_cq() calls).
What have I overlooked?

(Anyways the poll queues comment doesn't seem to apply to cq_lock.)

Thx,
Ed

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author
#7 lore raw
Quoted 16 lines · Edmund

drivers/nvme/host/pci.c struct nvme_queue { · line 175

Quoted 11 lines · Ming Lei

spinlock_t sq_lock;
void *sq_cmds;
/* only used for poll queues: */

drivers/nvme/host/pci.c +4 -1
-	spinlock_t cq_poll_lock ____cacheline_aligned_in_smp;
+	union {
+		spinlock_t cq_poll_lock;
+		spinlock_t cq_lock;
+	}____cacheline_aligned_in_smp;
  	volatile struct nvme_completion *cqes;
  	struct blk_mq_tags **tags;
  	dma_addr_t sq_dma_addr;

Still not sure I follow the case for another lock (seems to me like just a semantic distinction, as they both basically bracket nvme_process_cq() calls). What have I overlooked?

.cq_poll_lock is for sync poll queues between nvme_poll_irqdisable() and nvme_poll(), and this lock won't be acquired in irq context.

.cq_lock is for sync between submission and completion, which can be acquired in irq context.

Their usage isn't same, and lock context isn't same, and have to be initialized with different name(lock class) for making lockdep happy.

Thanks,
Ming

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme