nvme-tcp: allow setting per-queue io_cpu through sysfs
PATCH v3 1/1 nvme-tcp: allow setting per-queue io_cpu through sysfs
nvme_tcp_set_queue_io_cpu() picks each queue's io_cpu at connect time as the least loaded CPU in the queue's blk-mq map group, and all socket work runs there for the connection's lifetime. This decision falls short when the host partitions its CPUs after connect time. On a 384 cpu multi tenant host with 128 queue controllers, blk-mq folds three CPUs into every map group, some groups straddle two tenants' cpusets, and 9% of nvme_tcp_io_work executions ran outside the submitting VM's cpuset, seen by the neighbor as steal time.
Expose each I/O queue's io_cpu as a writable sysfs attribute
/sys/class/nvme/nvmeX/tcp_queues/<qid>/io_cpu
so a control plane that owns CPU placement can set it directly instead of relying on the driver's heuristic. A written value persists across reconnects, marked by NVME_TCP_Q_IO_CPU_USER. Writing -1 clears the mark and re-runs the connect time selection. Reading returns the CPU, or -1 when the queue is unbound.
The store, the connect time selection and queue stop serialize their accounting of nvme_tcp_cpu_queues under the queue lock.
---
Changes since v2 [1]:
- Replaced the io_cpu_adopt connect option and the submitter adoption heuristic with a per queue writable sysfs attribute, following Sagi's suggestion [2]. The control plane now sets each queue's io_cpu directly, the assignment is kept across reconnects and writing -1 reverts to the connect time selection.
- Retitled from "nvme-tcp: pin io_cpu to submitter cpu".
The per queue directories follow the blk-mq mq/<hctx> sysfs pattern.
Tested on a 2 socket 384 cpu host with 128 queue controllers. Writing a cpu number changed the queue's io_cpu to it. Writing an invalid value was rejected. Writing -1 re-ran the connect time selection. Pinned queues kept their io_cpu across a controller reset while unpinned queues received a fresh pick.
The multiple queues per hctx RFC [3] found the same need to steer the socket work cpu, so this attribute may gain a second user.
[1] https://lore.kernel.org/linux-nvme/[email protected]/
[2] https://lore.kernel.org/linux-nvme/[email protected]/
[3] https://lore.kernel.org/linux-nvme/[email protected]/
Documentation/ABI/stable/sysfs-nvme | 12 +++ drivers/nvme/host/tcp.c | 153 +++++++++++++++++++++++++++- 2 files changed, 162 insertions(+), 3 deletions(-)
Documentation/ABI/stable/sysfs-nvme +12 -0
@@ -451,3 +451,15 @@ Contact: Hannes Reinecke <[email protected]> Description: Shows the subsystem type. Possible values: "discovery", "nvm", "reserved". + +What: /sys/class/nvme/nvmeX/tcp_queues/<qid>/io_cpu +Date: September 2026 +KernelVersion: 7.4 +Contact: Saravanan D <[email protected]> +Description: + (RW) The CPU that runs the socket work for I/O queue <qid> + of an NVMe over TCP controller, selected by the driver at + connect time. Writing a CPU number overrides the selection + and persists across reconnects. Writing -1 reverts to the + driver's selection. Reads show the current CPU, or -1 when + the queue is unbound.
drivers/nvme/host/tcp.c +150 -3
233 lines not on this page · raw message
base-commit: fd9beb8870736e1c6a0b2351d88a161aaeb2b326
Signature · 1 line
2.55.0
Quoted 9 lines · Saravanan D
nvme_tcp_set_queue_io_cpu()picks each queue'sio_cpuat connect time as the least loaded CPU in the queue's blk-mq map group, and all socket work runs there for the connection's lifetime. This decision falls short when the host partitions its CPUs after connect time. On a 384 cpu multi tenant host with 128 queue controllers, blk-mq folds three CPUs into every map group, some groups straddle two tenants' cpusets, and 9% ofnvme_tcp_io_workexecutions ran outside the submitting VM's cpuset, seen by the neighbor as steal time.
Quoted 4 lines
Expose each I/O queue's
io_cpuas a writable sysfs attribute/sys/class/nvme/nvmeX/tcp_queues/<qid>/io_cpu
I wonder if we should avoid introducing a transport-specific tcp_queues hierarchy here. io_cpu describes CPU placement of an NVMe I/O queue rather than something inherently specific to TCP, and other transports may have similar queue-level attributes in the future. Could we instead introduce a generic "queues/<qid>/" hierarchy under each NVMe controller, e.g.
/sys/class/nvme/nvmeX/queues/<qid>/
and have transports expose queue-specific attributes there? The "queues/<qid>" object could be created for every controller, while transports that need queue- specific sysfs attributes can populate the corresponding <qid> objects. This would give us a transport-independent ABI and avoid introducing separate tcp_queues, rdma_queues, etc. hierarchies.
Quoted 9 lines
so a control plane that owns CPU placement can set it directly instead of relying on the driver's heuristic. A written value persists across reconnects, marked by
NVME_TCP_Q_IO_CPU_USER. Writing -1 clears the mark and re-runs the connect time selection. Reading returns the CPU, or -1 when the queue is unbound.The store, the connect time selection and queue stop serialize their accounting of
nvme_tcp_cpu_queuesunder the queue lock.
Also, based on the current design, it seems possible to have some queues whose io_cpu is driver-managed while other queues are explicitly managed by the control plane. This gives useful flexibility for the tenant use case. However, looking at the io_cpu sysfs attribute alone, it is not possible to determine whether the current CPU was selected by the driver or explicitly assigned by the control plane. So could we expose this state through an additional read-only attribute alongside io_cpu, for example:
/sys/class/nvme/nvmeX/queues/<qid>/io_cpu
/sys/class/nvme/nvmeX/queues/<qid>/managed
where "managed" indicates who currently owns the CPU placement. For example, "1" could indicate that io_cpu is driver-managed and "0" indicates it is managed by the control plane or user. This would make the current ownership state observable without making any wild guess.
Thanks,
--Nilay
Quoted 10 lines · On Thu, 10 Sep 2026 13:55:59 +0530 Nilay Shroff <[email protected]> wrote:
I wonder if we should avoid introducing a transport-specific
tcp_queueshierarchy here.io_cpudescribes CPU placement of an NVMe I/O queue rather than something inherently specific to TCP, and other transports may have similar queue-level attributes in the future. Could we instead introduce a generic "queues/<qid>/" hierarchy under each NVMe controller, e.g./sys/class/nvme/nvmeX/queues/<qid>/and have transports expose queue-specific attributes there?
Thanks for your review.
A controller is backed by exactly one transport, so we can adopt the transport-neutral /sys/class/nvme/nvmeX/queues/<qid>/ path with the creation staying outside of core in nvme-tcp, which owns the queue lifecycle. The core only knows ctrl->queue_count and never sees individual queue lifecycle.
No other transport has queue attributes today, so a controller backed by rdma will have no queues directory at all. The path appears only where a transport populates it, and if another transport grows queue attributes later, the creation can move into the core without any ABI change.
Quoted 9 lines
So could we expose this state through an additional read-only attribute alongside
io_cpu, for example:/sys/class/nvme/nvmeX/queues/<qid>/io_cpu
/sys/class/nvme/nvmeX/queues/<qid>/managedwhere "managed" indicates who currently owns the CPU placement. For example, "1" could indicate that
io_cpuis driver-managed and "0" indicates it is managed by the control plane or user.
Agreed, I can add the read-only managed attribute, 1 when the io_cpu is driver managed and 0 when the user assigned it in the next version.
Both suggestions look good to me. I will wait for Sagi or Keith to weigh in before spinning v4.
Saravanan D.
Sagi Grimberg
maintainerQuoted 31 lines · Saravanan D
Quoted 10 lines · On Thu, 10 Sep 2026 13:55:59 +0530 Nilay Shroff <[email protected]> wrote:
I wonder if we should avoid introducing a transport-specific
tcp_queueshierarchy here.io_cpudescribes CPU placement of an NVMe I/O queue rather than something inherently specific to TCP, and other transports may have similar queue-level attributes in the future. Could we instead introduce a generic "queues/<qid>/" hierarchy under each NVMe controller, e.g./sys/class/nvme/nvmeX/queues/<qid>/and have transports expose queue-specific attributes there?
Thanks for your review.
A controller is backed by exactly one transport, so we can adopt the transport-neutral /sys/class/nvme/nvmeX/queues/<qid>/ path with the creation staying outside of core in nvme-tcp, which owns the queue lifecycle. The core only knows
ctrl->queue_countand never sees individual queue lifecycle.No other transport has queue attributes today, so a controller backed by rdma will have no queues directory at all. The path appears only where a transport populates it, and if another transport grows queue attributes later, the creation can move into the core without any ABI change.
Quoted 6 lines
So could we expose this state through an additional read-only attribute alongside
io_cpu, for example:/sys/class/nvme/nvmeX/queues/<qid>/io_cpu
/sys/class/nvme/nvmeX/queues/<qid>/managed
Quoted 8 lines
Quoted 3 lines
where "managed" indicates who currently owns the CPU placement. For example, "1" could indicate that
io_cpuis driver-managed and "0" indicates it is managed by the control plane or user.Agreed, I can add the read-only managed attribute, 1 when the
io_cpuis driver managed and 0 when the user assigned it in the next version.Both suggestions look good to me. I will wait for Sagi or Keith to weigh in before spinning v4.
I agree with this approach.
I think that making nvme-core more "aware" of individual controller queues is a good thing.
Sagi Grimberg
maintainerQuoted 11 lines · Saravanan D
nvme_tcp_set_queue_io_cpu()picks each queue'sio_cpuat connect time as the least loaded CPU in the queue's blk-mq map group, and all socket work runs there for the connection's lifetime. This decision falls short when the host partitions its CPUs after connect time. On a 384 cpu multi tenant host with 128 queue controllers, blk-mq folds three CPUs into every map group, some groups straddle two tenants' cpusets, and 9% ofnvme_tcp_io_workexecutions ran outside the submitting VM's cpuset, seen by the neighbor as steal time.Expose each I/O queue's
io_cpuas a writable sysfs attribute
Quoted 7 lines
/sys/class/nvme/nvmeX/tcp_queues/<qid>/io_cpu
so a control plane that owns CPU placement can set it directly instead of relying on the driver's heuristic. A written value persists across reconnects, marked by
NVME_TCP_Q_IO_CPU_USER. Writing -1 clears the mark and re-runs the connect time selection. Reading returns the CPU, or -1 when the queue is unbound.
No need for NVME_TCP_Q_IO_CPU_USER flag and restoring to the original connect time selection. -1 would mean WORK_CPU_UNBOUND. In fact lets allow this file to access "unbound" string (same as -1). I don't think we need to restore the connect time selection, the user who touches these settings is obviously interested to be in control.
Quoted 3 lines
The store, the connect time selection and queue stop serialize their accounting of
nvme_tcp_cpu_queuesunder the queue lock.
I think that the queue accounting is something we'd do anyways, regardless of how the queue is set. It just represents the io_cpu spread across cpu cores.
Quoted 69 lines
Suggested-by Sagi Grimberg <[email protected]>Assisted-by Claude:claude-opus-4-8 [Claude Code]Signed-off-by Saravanan D <[email protected]>---
Changes since v2 [1]:
- Replaced theio_cpu_adoptconnect option and the submitter adoption heuristic with a per queue writable sysfs attribute, following Sagi's suggestion [2]. The control plane now sets each queue'sio_cpudirectly, the assignment is kept across reconnects and writing -1 reverts to the connect time selection.
- Retitled from "nvme-tcp: pinio_cputo submitter cpu".The per queue directories follow the blk-mq mq/<hctx> sysfs pattern.
Tested on a 2 socket 384 cpu host with 128 queue controllers. Writing a cpu number changed the queue's
io_cputo it. Writing an invalid value was rejected. Writing -1 re-ran the connect time selection. Pinned queues kept theirio_cpuacross a controller reset while unpinned queues received a fresh pick.The multiple queues per hctx RFC [3] found the same need to steer the socket work cpu, so this attribute may gain a second user.
[1] https://lore.kernel.org/linux-nvme/[email protected]/
[2] https://lore.kernel.org/linux-nvme/[email protected]/
[3] https://lore.kernel.org/linux-nvme/[email protected]/Documentation/ABI/stable/sysfs-nvme | 12 +++ drivers/nvme/host/tcp.c | 153 +++++++++++++++++++++++++++- 2 files changed, 162 insertions(+), 3 deletions(-)Documentation/ABI/stable/sysfs-nvme +12
-0@@ -451,3 +451,15 @@ Contact: Hannes Reinecke <[email protected]> Description: Shows the subsystem type. Possible values: "discovery", "nvm", "reserved". + +What: /sys/class/nvme/nvmeX/tcp_queues/<qid>/io_cpu +Date: September 2026 +KernelVersion: 7.4 +Contact: Saravanan D <[email protected]> +Description: + (RW) The CPU that runs the socket work for I/O queue <qid> + of an NVMe over TCP controller, selected by the driver at + connect time. Writing a CPU number overrides the selection + and persists across reconnects. Writing -1 reverts to the + driver's selection. Reads show the current CPU, or -1 when + the queue is unbound.drivers/nvme/host/tcp.c +1
-0@@ -93,6 +93,7 @@ enum nvme_tcp_queue_flags {NVME_TCP_Q_LIVE =1 ,NVME_TCP_Q_POLLING =2 ,NVME_TCP_Q_IO_CPU_SET =3 , + NVME_TCP_Q_IO_CPU_USER = 4, }; enum nvme_tcp_recv_state {@@ -102,6 +103,17 @@ enum nvme_tcp_recv_state { };struct nvme_tcp_ctrl ;
drivers/nvme/host/tcp.c enum nvme_tcp_recv_state { · line 115
Quoted 10 lines
drivers/nvme/host/tcp.c +10
-0+struct nvme_tcp_queue ; + +/* +* Allocated per registration and freed by its kobject release, so a +* reconnect never reuses a kobject whose release is still pending. +*/ +struct nvme_tcp_queue_kobj { +struct kobject kobj; +struct nvme_tcp_queue *queue; +};
I am wandering if it is time to introduce the core nvme queue:
struct nvme_queue {
struct kobject kobj;
unsigned int qid;
u64 flags;
};
And have the transport queue embed it:
struct nvme_tcp_queue {
struct nvme_queue nvmeq;
....
};
I suspect it will allow for better abstractions.
Thoughts? Keith, Christoph?
Quoted 121 lines · Sagi Grimberg
Quoted 11 lines · Saravanan D
nvme_tcp_set_queue_io_cpu()picks each queue'sio_cpuat connect time as the least loaded CPU in the queue's blk-mq map group, and all socket work runs there for the connection's lifetime. This decision falls short when the host partitions its CPUs after connect time. On a 384 cpu multi tenant host with 128 queue controllers, blk-mq folds three CPUs into every map group, some groups straddle two tenants' cpusets, and 9% ofnvme_tcp_io_workexecutions ran outside the submitting VM's cpuset, seen by the neighbor as steal time.Expose each I/O queue's
io_cpuas a writable sysfs attributeQuoted 7 lines
/sys/class/nvme/nvmeX/tcp_queues/<qid>/io_cpu
so a control plane that owns CPU placement can set it directly instead of relying on the driver's heuristic. A written value persists across reconnects, marked by
NVME_TCP_Q_IO_CPU_USER. Writing -1 clears the mark and re-runs the connect time selection. Reading returns the CPU, or -1 when the queue is unbound.No need for
NVME_TCP_Q_IO_CPU_USERflag and restoring to the original connect time selection. -1 would meanWORK_CPU_UNBOUND. In fact lets allow this file to access "unbound" string (same as -1). I don't think we need to restore the connect time selection, the user who touches these settings is obviously interested to be in control.Quoted 3 lines
The store, the connect time selection and queue stop serialize their accounting of
nvme_tcp_cpu_queuesunder the queue lock.I think that the queue accounting is something we'd do anyways, regardless of how the queue is set. It just represents the
io_cpuspread across cpu cores.Quoted 67 lines
Suggested-by Sagi Grimberg <[email protected]>Assisted-by Claude:claude-opus-4-8 [Claude Code]Signed-off-by Saravanan D <[email protected]>---
Changes since v2 [1]:
- Replaced theio_cpu_adoptconnect option and the submitter adoption heuristic with a per queue writable sysfs attribute, following Sagi's suggestion [2]. The control plane now sets each queue'sio_cpudirectly, the assignment is kept across reconnects and writing -1 reverts to the connect time selection.
- Retitled from "nvme-tcp: pinio_cputo submitter cpu".The per queue directories follow the blk-mq mq/<hctx> sysfs pattern.
Tested on a 2 socket 384 cpu host with 128 queue controllers. Writing a cpu number changed the queue's
io_cputo it. Writing an invalid value was rejected. Writing -1 re-ran the connect time selection. Pinned queues kept theirio_cpuacross a controller reset while unpinned queues received a fresh pick.The multiple queues per hctx RFC [3] found the same need to steer the socket work cpu, so this attribute may gain a second user.
[1] https://lore.kernel.org/linux-nvme/[email protected]/
[2] https://lore.kernel.org/linux-nvme/[email protected]/
[3] https://lore.kernel.org/linux-nvme/[email protected]/
Documentation/ABI/stable/sysfs-nvme| 12 +++ drivers/nvme/host/tcp.c | 153 +++++++++++++++++++++++++++-2 files changed, 162 insertions(+), 3 deletions(-)Documentation/ABI/stable/sysfs-nvme +0
-0@@ -451,3 +451,15 @@ Contact: Hannes Reinecke <[email protected]>Description:
Shows the subsystem type. Possible values: "discovery", "nvm", "reserved".Documentation/ABI/stable/sysfs-nvme +12
-0+ +What: /sys/class/nvme/nvmeX/tcp_queues/<qid>/io_cpu +Date: September 2026 +KernelVersion: 7.4 +Contact: Saravanan D <[email protected]> +Description: + (RW) The CPU that runs the socket work for I/O queue <qid> + of an NVMe over TCP controller, selected by the driver at + connect time. Writing a CPU number overrides the selection + and persists across reconnects. Writing -1 reverts to the + driver's selection. Reads show the current CPU, or -1 when + the queue is unbound.drivers/nvme/host/tcp.c +1
-0@@ -93,6 +93,7 @@ enum nvme_tcp_queue_flags { NVME_TCP_Q_LIVE = 1, NVME_TCP_Q_POLLING = 2, NVME_TCP_Q_IO_CPU_SET = 3, + NVME_TCP_Q_IO_CPU_USER = 4, }; enum nvme_tcp_recv_state {@@ -102,6 +103,17 @@ enum nvme_tcp_recv_state { }; struct nvme_tcp_ctrl;drivers/nvme/host/tcp.c enum nvme_tcp_recv_state { · line 114
Quoted 10 lines
drivers/nvme/host/tcp.c +10
-0+struct nvme_tcp_queue ; + +/* +* Allocated per registration and freed by its kobject release, so a +* reconnect never reuses a kobject whose release is still pending. +*/ +struct nvme_tcp_queue_kobj { + struct kobject kobj; + struct nvme_tcp_queue *queue; +};I am wandering if it is time to introduce the core nvme queue:
structnvme_queue{
struct kobject kobj;
unsigned int qid;
u64 flags;
};And have the transport queue embed it:
structnvme_tcp_queue{
struct nvme_queue nvmeq;
....
};
Quoted 3 lines
I suspect it will allow for better abstractions.
Thoughts? Keith, Christoph?
Yes, agreed. I think having a common queue structure would provide a better abstraction here. However, struct nvme_queue is already used by the PCI driver for its transport-specific queue representation. Perhaps we could name common structure as struct nvme_queue_info.
Thanks,
--Nilay
Quoted 5 lines · On Sat, 12 Sep 2026 00:11:18 +0300 Sagi Grimberg <[email protected]> wrote:
No need for
NVME_TCP_Q_IO_CPU_USERflag and restoring to the original connect time selection. -1 would meanWORK_CPU_UNBOUND. In fact lets allow this file to access "unbound" string (same as -1). I don't think we need to restore the connect time selection, the user who touches these settings is obviously interested to be in control.
Noted. The next version will accept a cpu number, -1 or the string "unbound", with -1 and "unbound" setting io_cpu to WORK_CPU_UNBOUND.
Quoted 3 lines
I think that the queue accounting is something we'd do anyways, regardless of how the queue is set. It just represents the
io_cpuspread across cpu cores.
Agreed, the accounting applies regardless of whether the io_cpu came from the driver's selection or from the control plane.
Quoted 7 lines
I am wandering if it is time to introduce the core nvme queue:
struct nvme_queue { struct kobject kobj; unsigned int qid; u64 flags; };
Quoted 7 lines
And have the transport queue embed it:
struct nvme_tcp_queue { struct nvme_queue nvmeq; .... };I suspect it will allow for better abstractions.
This works for me, and it settles where the queues/<qid>/ kobject lives. As Nilay pointed out the nvme_queue name is taken by the PCI driver, so the common struct needs another name.
One clarification for the reconnect path. You suggested earlier that a user assigned io_cpu should not change across reconnects. Without a flag the driver cannot tell a user assigned io_cpu from its own pick when it reconnects, since both are just a cpu number. If the assignment should still persist, would you consider tracking it as a bit in the flags of core nvme queue struct ?
I will wait for Keith and Christoph before spinning the next version.
Thanks,
Saravanan D.