Skip to contentSkip to conversation

nvme-pci: add adaptive interrupt polling

RFC PATCH Superseded Fengnan Chang 1 participant 1 message Aug 6 NVMe

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 nvme-pci: add adaptive interrupt polling

The idea behind this approach is: Let each I/O queue switch itself between interrupt and poll mode based on its own recent completion rate.

This version is still in the testing phase, and there are still some issues with the code implementation. I releasing it now to see if the approach is generally acceptable. If the approach looks good, I’ll continue to refine it and conduct more extensive testing. The main implementation logic is in nvme_adaptive_sample and nvme_adaptive_irq_poll; you should focus on reviewing the implementation of these two functions.

Compared to the previous version, this represents a much smaller performance regression while offering greater benefits.

In high-IOPS scenarios, relying on interrupts to handle I/O operations can limit performance. This issue becomes particularly pronounced in multi-disk environments, where performance is constrained by the CPU's interrupt-handling capacity.

Each Solidigm SB5PH27X038T device used for testing can deliver about 3.2M 4 KiB random-read IOPS. Four of them should be good for about 12.8M IOPS, but interrupt-driven completion tops out at 5.59M, only about 44% of that.

Polling gets rid of that cost, but polling every queue all the time burns CPU and hurts the sparse or bursty queues that interrupts handle just fine. So instead of a global switch, let each queue make the call on its own, from how fast it has been completing lately, and re-check often enough that the decision tracks the workload rather than a fixed tunable.

Each queue runs a small loop with three stages. First it samples its completion rate while still on interrupts. Only if that rate is high enough to fill a small batch inside a bounded latency window does it mask its own IRQ and start draining the CQ from a high-resolution timer, with each wait sized to collect roughly one batch. It keeps polling as long as it keeps up with that rate; the moment it stalls or slows down it turns the IRQ back on and backs off, waiting longer the further behind it fell. A queue that doesn't benefit drops back quickly and only gets retried once in a while, so polling stays on the queues that are actually interrupt-bound and everything else keeps running on the untouched IRQ path.

Measured with 4 KiB random reads on Solidigm SB5PH27X038T, adaptive on versus off:

                                   QD32      QD64      QD128
  one device, one job             +18.44%   +24.35%   +26.38%
  four devices, eight jobs        +83.76%   +99.02%   +96.26%

The four-device eight-job aggregate goes from 5.59M IOPS (44% of the 12.8M ceiling) to 10.89M IOPS (85%). Tail latency improves too: QD64 p99 drops from 1073 us to 498 us (-54%) and p99.9 from 1909 us to 741 us (-61%). Interrupts per I/O drop from about 0.91 to 0.08 (~12x fewer) in the four-device case, and from 0.96 to 0.03 (~33x fewer) on a single high-QD queue.

---
 drivers/nvme/host/Kconfig |   1 +
 drivers/nvme/host/pci.c   | 468 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 452 insertions(+), 17 deletions(-)
drivers/nvme/host/Kconfig +1 -0
index 31974c7dd20c9..22164b901da85 100644
@@ -5,6 +5,7 @@ config NVME_CORE
 config BLK_DEV_NVME
 	tristate "NVM Express block device"
 	depends on PCI && BLOCK
+	select IRQ_POLL
 	select NVME_CORE
 	help
 	  The NVM Express driver is for solid state drives directly
drivers/nvme/host/pci.c +451 -17

593 lines not on this page · raw message

Signature · 1 line
2.39.5 (Apple Git-154)