nvme-pci: add adaptive interrupt polling
v2 cover nvme-pci: add adaptive interrupt polling
At high IOPS, interrupt handling can limit throughput, especially when multiple drives contend for CPU time.
Add an opt-in adaptive policy for I/O queues that use a dedicated MSI-X vector and do not use threaded interrupts. Each queue independently switches between interrupt and poll mode based on its recent completion rate.
In interrupt mode, wait for at least 8192 completions. If they arrive no more than 10 us apart on average, try polling. While polling, an hrtimer runs irq_poll to drain the completion queue. Before a window is full, polling may fall 20 us behind the interrupt-mode pace. After 8192 completions, polling must be strictly faster than interrupt mode.
If a try fails, go back to interrupt mode and measure again. After three failures in a row, stay in interrupt mode for 64 windows of completions before measuring again. If polling works, keep it for at most 64 windows, then go back to interrupt mode and measure again.
The module parameter is off by default and only sets the initial mode for new controllers. A per-controller sysfs file can change the mode later. The change freezes the namespace queues and waits for in-flight I/O to finish. Queues that use threaded, MSI, or legacy interrupts keep the regular interrupt handler.
Measured with 4 KiB random reads on Solidigm SB5PH27X076T, adaptive polling on versus off:
QD32 QD64 QD128 one device, one job -0.08% +31.56% +30.95% fifteen devices, eight jobs/device +188.03% +236.46% +231.38%
The fifteen-device aggregate with eight jobs per device increases from 13.48M / 13.47M / 13.47M IOPS to 38.83M / 45.31M / 44.64M IOPS.
Changes since v1:
- Split the nvme_poll_cq() return-count change into a separate prep patch (patch 1/2) so the functional change stands on its own.
- Factor out nvme_irq_complete_batch() so the regular and adaptive interrupt handlers share one batch-completion path.
- Only call irq_poll_complete() when completions < budget, matching the irq_poll contract; the previous boundary case could return the poll object to the softirq list after it was already removed.
- Clarify comments: document the NVMEQ_ADAPTIVE_* flags and the dual-purpose retry_completions field, and reword the constant rationale.
- Minor style/indentation fixes per review.
Fengnan Chang (2):
nvme-pci: return completion count from nvme_poll_cq
nvme-pci: add adaptive interrupt polling
Documentation/ABI/testing/sysfs-nvme | 17 + drivers/nvme/host/Kconfig | 1 + drivers/nvme/host/pci.c | 542 +++++++++++++++++++++++++-- 3 files changed, 536 insertions(+), 24 deletions(-)
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 1/2 nvme-pci: return completion count from nvme_poll_cq
Return the number of completions consumed by nvme_poll_cq() instead of a boolean. Existing callers still treat zero vs non-zero as before; nvme_poll() keeps returning 0/1 via a bool local.
Extract nvme_irq_complete_batch() from nvme_irq() so the adaptive handler in the next patch can reuse the batch completion path.
--- drivers/nvme/host/pci.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/nvme/host/pci.c +15 -10
@@ -1606,13 +1606,12 @@ static inline void nvme_update_cq_head(struct nvme_queue *nvmeq) } } -static inline bool nvme_poll_cq (struct nvme_queue *nvmeq, -struct io_comp_batch *iob) +static inline unsigned int nvme_poll_cq (struct nvme_queue *nvmeq, +struct io_comp_batch *iob) { -bool found = false; +unsigned int found =0 ;while (nvme_cqe_pending (nvmeq)) { - found = true;/* * load-load control dependency between phase and the rest of * the cqe requires a full read memory barrier
@@ -1620,6 +1619,7 @@ static inline bool nvme_poll_cq(struct nvme_queue *nvmeq,dma_rmb ();nvme_handle_cqe (nvmeq, iob, nvmeq->cq_head);nvme_update_cq_head (nvmeq); + found++; }if (found)
@@ -1627,17 +1627,22 @@ static inline bool nvme_poll_cq(struct nvme_queue *nvmeq,return found; } +static irqreturn_t nvme_irq_complete_batch (struct io_comp_batch *iob, +unsigned int completions) +{ +if (!completions) +return IRQ_NONE ; +if (!rq_list_empty (&iob->req_list)) +nvme_pci_complete_batch (iob); +return IRQ_HANDLED ; +} +static irqreturn_t nvme_irq (int irq,void *data) {struct nvme_queue *nvmeq = data;DEFINE_IO_COMP_BATCH (iob); -if (nvme_poll_cq (nvmeq, &iob)) { -if (!rq_list_empty (&iob.req_list)) -nvme_pci_complete_batch (&iob); -return IRQ_HANDLED ; - } -return IRQ_NONE ; +return nvme_irq_complete_batch (&iob,nvme_poll_cq (nvmeq, &iob)); }static irqreturn_t nvme_irq_check (int irq,void *data)
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 2/2 nvme-pci: add adaptive interrupt polling
In reply to Fengnan ChangAt high IOPS, interrupt handling can limit throughput, especially when multiple drives contend for CPU time.
Add an opt-in adaptive policy for I/O queues that use a dedicated MSI-X vector and do not use threaded interrupts. Each queue independently switches between interrupt and poll mode based on its recent completion rate.
In interrupt mode, wait for at least 8192 completions. If they arrive no more than 10 us apart on average, try polling. While polling, an hrtimer runs irq_poll to drain the completion queue. Before a window is full, polling may fall 20 us behind the interrupt-mode pace. After 8192 completions, polling must be strictly faster than interrupt mode.
If a try fails, go back to interrupt mode and measure again. After three failures in a row, stay in interrupt mode for 64 windows of completions before measuring again. If polling works, keep it for at most 64 windows, then go back to interrupt mode and measure again.
The module parameter is off by default and only sets the initial mode for new controllers. A per-controller sysfs file can change the mode later. The change freezes the namespace queues and waits for in-flight I/O to finish. Queues that use threaded, MSI, or legacy interrupts keep the regular interrupt handler.
Measured with 4 KiB random reads on Solidigm SB5PH27X076T, adaptive polling on versus off:
QD32 QD64 QD128 one device, one job -0.08% +31.56% +30.95% fifteen devices, eight jobs/device +188.03% +236.46% +231.38%
The fifteen-device aggregate with eight jobs per device increases from 13.48M / 13.47M / 13.47M IOPS to 38.83M / 45.31M / 44.64M IOPS.
--- Documentation/ABI/testing/sysfs-nvme | 17 + drivers/nvme/host/Kconfig | 1 + drivers/nvme/host/pci.c | 517 ++++++++++++++++++++++++++- 3 files changed, 521 insertions(+), 14 deletions(-)
Documentation/ABI/testing/sysfs-nvme +17 -0
@@ -11,3 +11,20 @@ Description: (REPLACETLSPSK) with the target. After a reauthentication the value returned by tls_configured_key will be the new serial. + +What: /sys/class/nvme/nvmeX/adaptive_irq_polling +Date: August 2026 +KernelVersion: 7.3 +Contact: Linux NVMe mailing list <[email protected]> +Description: + Set the adaptive IRQ polling policy (0 or 1) for eligible + I/O queues of one PCI NVMe controller. Reading returns the + policy, not whether a queue is currently polling. Changing it + freezes the namespace request queues and waits for outstanding + namespace I/O. Writes fail with EBUSY unless the controller is + live. + + Eligible queues use non-threaded MSI-X with a dedicated vector. + The attribute is unavailable with threaded interrupts. The + module parameter supplies only the initial policy for new + controllers.
drivers/nvme/host/Kconfig +1 -0
@@ -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 +503 -14
676 lines not on this page · raw message
Signature · 1 line
2.39.5 (Apple Git-154)
More test data is available here.
https://docs.google.com/spreadsheets/d/1rer4Nl5HHxSO-D3NrrHuHSfpR9s1kLhpLjzh7h7Mbmw/edit?gid=875909538#gid=875909538
We’ve added tests for some NVMe drives with very poor performance, such as the HFS480GEJ8X176N (4k random write: 40k IOPS, 4k random
read: 700k IOPS) and the MZVL2480HBJD (4k random write: 20k IOPS, 4k random read: 130k IOPS).
We’ve also tested performance on QLC.
There were a total of 3,280 test cases covering 13 different drive models. Among these, 327 cases showed a steady improvement, with a maximum improvement of 240% and a median of 29%.
Meanwhile, 15 cases showed a regression, with a maximum regression of -11% and a median of -7.4%.
Almost none of the regressions can be reliably reproduced, but that doesn’t mean they didn’t occur—when we ran the tests again, similar regressions appeared in about 10 different cases.
Here is more data compare to GSIM:
https://docs.google.com/spreadsheets/d/14-_lLyPO_Uxm0ou7K-AcQ9qPCuWUZK0-n5JTgqvgZJc/edit?gid=875909538#gid=875909538
Quoted 64 lines
From: "Fengnan Chang"<[email protected]>
Date: Wed, Aug 26, 2026, 14:16
Subject: [PATCH v2 0/2] nvme-pci: add adaptive interrupt polling
To: "Keith Busch"<[email protected]>, "Jens Axboe"<[email protected]>, "Christoph Hellwig"<[email protected]>, "Sagi Grimberg"<[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>
Cc: <[email protected]>, "Fengnan Chang"<[email protected]>
At high IOPS, interrupt handling can limit throughput, especially when
multiple drives contend for CPU time.
Add an opt-in adaptive policy for I/O queues that use a dedicated MSI-X
vector and do not use threaded interrupts. Each queue independently
switches between interrupt and poll mode based on its recent completion
rate.
In interrupt mode, wait for at least 8192 completions. If they arrive
no more than 10 us apart on average, try polling. While polling, an
hrtimer runsirq_pollto drain the completion queue. Before a window
is full, polling may fall 20 us behind the interrupt-mode pace. After
8192 completions, polling must be strictly faster than interrupt mode.
If a try fails, go back to interrupt mode and measure again. After
three failures in a row, stay in interrupt mode for 64 windows of
completions before measuring again. If polling works, keep it for at
most 64 windows, then go back to interrupt mode and measure again.
The module parameter is off by default and only sets the initial
mode for new controllers. A per-controller sysfs file can change
the mode later. The change freezes the namespace queues and waits
for in-flight I/O to finish. Queues that use threaded, MSI, or
legacy interrupts keep the regular interrupt handler.
Measured with 4 KiB random reads on Solidigm SB5PH27X076T, adaptive
polling on versus off:
QD32 QD64 QD128
one device, one job -0.08% +31.56% +30.95%
fifteen devices, eight jobs/device +188.03% +236.46% +231.38%
The fifteen-device aggregate with eight jobs per device increases
from 13.48M / 13.47M / 13.47M IOPS to 38.83M / 45.31M / 44.64M IOPS.
Changes since v1:
- Split thenvme_poll_cq()return-count change into a separate prep patch
(patch 1/2) so the functional change stands on its own.
- Factor outnvme_irq_complete_batch()so the regular and adaptive
interrupt handlers share one batch-completion path.
- Only callirq_poll_complete()when completions < budget, matching the
irq_pollcontract; the previous boundary case could return the poll
object to the softirq list after it was already removed.
- Clarify comments: document the NVMEQ_ADAPTIVE_* flags and the
dual-purposeretry_completionsfield, and reword the constant rationale.
- Minor style/indentation fixes per review.
Fengnan Chang (2):
nvme-pci: return completion count fromnvme_poll_cq
nvme-pci: add adaptive interrupt polling
Documentation/ABI/testing/sysfs-nvme | 17 +
drivers/nvme/host/Kconfig | 1 +
drivers/nvme/host/pci.c | 542 +++++++++++++++++++++++++--3 files changed, 536 insertions(+), 24 deletions(-)
--
2.39.5 (Apple Git-154)