Skip to contentSkip to conversation

nvme-tcp: NIC topology aware I/O queue scaling and queue info export

PATCH In review Nilay Shroff 3 participants 6 messages Dec 1 – Dec 2 NVMe

lore
Share & tools
lore
#0 lore raw

v5 cover nvme-tcp: NIC topology aware I/O queue scaling and queue info export

This patch series has been revised based on feedback from the netdev community [1].

Following the feedback, the logic for determining the number of fabric I/O queues (nr-io-queues) has been now moved to userspace in nvme-cli [2]. As a result, the first two patches from the earlier series v2, which implemented this logic in the kernel driver, have been dropped in series v3.

Based on further feedback received on v3, this revision also moves the export of NVMe/TCP I/O queue information from debugfs to sysfs, making it easier for userspace tools to access the information and configure host-side network tuning.

The patch exports the socket endpoint addresses of each NVMe/TCP I/O queue through a new per-queue sysfs attribute named address. This provides the TCP flow information (source/destination IP addresses and ports) for each I/O queue. The associated CPU assignment can be retrieved through the existing io_cpu attribute.

Together, these attributes provide userspace tools with the information needed to configure:
- IRQ affinity
- RPS/XPS
- ntuple steering
- or any other scaling as deemed feasible

Together with tunning, these changes allow better alignment of:
flow -> NIC queue -> IRQ -> CPU -> NVMe/TCP I/O worker

Improving this alignment can enhance flow-to-CPU locality, potentially improving performance and reducing I/O latency. Performance evaluation results comparing the baseline with the tuned configuration are available in [3].

Thanks!

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://github.com/linux-nvme/nvme-cli/pull/4140
[3]: https://lore.kernel.org/all/[email protected]/

changes from v4
- Squashed the ABI documentation changes into first patch and so with that now this series only has one patch (Hannes Reinecke)
- Renamed traddr, trsvcid, host_traddr and host_trsvcid to dip, dport sip and sport respectively to match the generic terms used for tcp queue socket connection endpoint
- show IPv6 scope id along with IPv6 address if scope-id is non-zero.

Link to v4: https://lore.kernel.org/all/[email protected]/

Changes from v3
- Moved per-queue tcp flow information from debugfs to sysfs
(Daniel Wagner, Hannes Reinecke)
Link to v3: https://lore.kernel.org/all/[email protected]/

Changes from v2
- Dropped patch #1 and #2 from v2
- Added new debugfs attribute parameter "is_visible" which could be useful to hide the attribute for certain configuration or transport.
Link to v2: https://lore.kernel.org/all/[email protected]/

Nilay Shroff (1):
nvme-tcp: expose per-queue socket addresses via sysfs

 Documentation/ABI/stable/sysfs-nvme | 25 ++++++++++++
 drivers/nvme/host/tcp.c             | 59 +++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)

base-commit: 1c2ff060b8144fa816e7db751a8ed47c86032c92

Signature · 1 line
2.53.0
#1 lore raw

PATCH v5 1/1 nvme-tcp: expose per-queue socket addresses via sysfs

Add a read-only per-queue sysfs attribute named "address" to expose the socket addresses associated with each NVMe/TCP I/O queue.

The attribute reports the socket's peer and local endpoint information using the following fields:

- sip: Local transport address (IPv4/IPv6). For IPv6, appends
%<scope-id> if used for connection.
- sport: Local transport service identifier.
- dip: Peer transport address (IPV4/IPv6). For IPv6, appends
%<scope-id> if used for connection.
- dport: Peer transport service identifier

The attribute is available at:
/sys/class/nvme/nvmeX/queues/<qid>/address

Together with the existing per-queue "io_cpu" attribute, this information helps correlate NVMe/TCP I/O queues with network stack components and tune their interaction, including IRQ affinity, RPS/RFS, XPS and NIC flow steering (ntuple).

Also, document the per-IO-queue "address" sysfs attribute in Documentation/ABI/stable/sysfs-nvme.

No changes to I/O behavior are expected.

---
 Documentation/ABI/stable/sysfs-nvme | 25 ++++++++++++
 drivers/nvme/host/tcp.c             | 59 +++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
Documentation/ABI/stable/sysfs-nvme +25 -0
index fcfd0426866c..7dec65e306e7 100644
@@ -534,3 +534,28 @@ Description:
 		managed: (RO) Shows who owns the CPU placement. 1 while
 		io_cpu is driver managed, 0 once the user assigned it,
 		for the life of the controller.
+
+What:		/sys/class/nvme/nvmeX/queues/<qid>/address
+Date:		December 2026
+KernelVersion:	7.5
+Contact:	Nilay Shroff <[email protected]>
+Description:
+		(RO) Shows the socket endpoint addresses associated with
+		an NVMe/TCP I/O queue. The output contains the following
+		comma-separated fields:
+
+		sip:   Local transport address (IPv4/IPv6). For IPv6,
+		       appends %<scope-id> if scope-id is used for
+		       connection.
+
+		sport: Local transport service identifier (TCP port).
+
+		dip:   Peer transport address (IPv4/IPv6). For Ipv6,
+		       appends %<scope-id> if scope-id is used for
+		       connection.
+
+		dport: Peer transport service identifier (TCP port).
+
+		Returns an empty result if the I/O queue is not live.
+		Returns error if host or peer transport address can't be
+		determined or transport address family is unsupported.
drivers/nvme/host/tcp.c +59 -0

73 lines not on this page · raw message

Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v5 1/1] nvme-tcp: expose per-queue socket addresses via sysfs

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] nvme-tcp: address_show() emits %0 scope ID when one IPv6 endpoint is unscoped --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] nvme-tcp: address_show() emits %0 scope ID when one IPv6 endpoint is unscoped
--

commit cef888fe89d146daf5915c1274fff0343c037eb2
Author: Nilay Shroff <[email protected]>

nvme-tcp: expose per-queue socket addresses via sysfs

This commit adds a read-only per-queue sysfs attribute named "address" to expose the local and peer socket endpoint addresses for each NVMe/TCP I/O queue, and documents it in Documentation/ABI/stable/sysfs-nvme.

Quoted 40 lines
drivers/nvme/host/tcp.c +32 -0
index cf3c98b188bd1..05cf7000ef678 100644
@@ -2127,14 +2127,73 @@ static ssize_t managed_show(struct kobject *kobj, struct kobj_attribute *attr,
 			  !test_bit(NVME_TCP_Q_IO_CPU_USER, &queue->flags));
 }
 
+static ssize_t address_show(struct kobject *kobj, struct kobj_attribute *attr,
+			    char *buf)
+{
+	struct nvme_tcp_queue *queue = nvme_queue_info_data(kobj);
+	struct sockaddr_storage src, dst;
+	int ret = 0;
+
+	mutex_lock(&queue->queue_lock);
+
+	if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags))
+		goto out;
+
+	ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src);
+	if (ret <= 0)
+		goto out;
+
+	ret = kernel_getpeername(queue->sock, (struct sockaddr *)&dst);
+	if (ret <= 0)
+		goto out;
+
+	if (src.ss_family != dst.ss_family) {
+		ret = -EAFNOSUPPORT;
+		goto out;
+	}
+
+	if (src.ss_family == AF_INET) {
+		struct sockaddr_in *sip = (struct sockaddr_in *)&src;
+		struct sockaddr_in *dip = (struct sockaddr_in *)&dst;
+
+		ret = sysfs_emit(buf, "sip=%pI4,sport=%hu,dip=%pI4,dport=%hu\n",
+				 &sip->sin_addr.s_addr, ntohs(sip->sin_port),
+				 &dip->sin_addr.s_addr, ntohs(dip->sin_port));

drivers/nvme/host/tcp.c static ssize_t managed_show(struct kobject *kobj, struct kobj_attribute *attr, · line 2171

Quoted 10 lines
drivers/nvme/host/tcp.c +10 -0
+	} else if (src.ss_family == AF_INET6) {
+		struct sockaddr_in6 *sip6 = (struct sockaddr_in6 *)&src;
+		struct sockaddr_in6 *dip6 = (struct sockaddr_in6 *)&dst;
+
+		if (sip6->sin6_scope_id || dip6->sin6_scope_id)
+			ret = sysfs_emit(buf, "sip=%pI6c%%%u,sport=%hu,dip=%pI6c%%%u,dport=%hu\n",
+					 &sip6->sin6_addr, sip6->sin6_scope_id,
+					 ntohs(sip6->sin6_port),
+					 &dip6->sin6_addr, dip6->sin6_scope_id,
+					 ntohs(dip6->sin6_port));

[Severity: Medium]
Does this emit a "%0" suffix on the unscoped endpoint when only one of sip6->sin6_scope_id or dip6->sin6_scope_id is non-zero?

inet6_getname() sets sin6_scope_id via ipv6_iface_scope_id(), which only returns sk->sk_bound_dev_if for addresses that need a scope ID (such as link-local addresses) and returns 0 for global or unique-local addresses. If one side of the connection uses a link-local address and the other uses a global or unique-local address, formatting both with "%%%u" appends "%0" to the unscoped address.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v5 1/1] nvme-tcp: expose per-queue socket addresses via sysfs

Quoted 70 lines · On 12/1/26 3:34 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] nvme-tcp: address_show() emits %0 scope ID when one IPv6 endpoint is unscoped
--

commit cef888fe89d146daf5915c1274fff0343c037eb2
Author: Nilay Shroff <[email protected]>

nvme-tcp: expose per-queue socket addresses via sysfs

This commit adds a read-only per-queue sysfs attribute named "address" to expose the local and peer socket endpoint addresses for each NVMe/TCP I/O queue, and documents it in Documentation/ABI/stable/sysfs-nvme.

Quoted 40 lines
drivers/nvme/host/tcp.c +32 -0
index cf3c98b188bd1..05cf7000ef678 100644
@@ -2127,14 +2127,73 @@ static ssize_t managed_show(struct kobject *kobj, struct kobj_attribute *attr,
  			  !test_bit(NVME_TCP_Q_IO_CPU_USER, &queue->flags));
  }
 
+static ssize_t address_show(struct kobject *kobj, struct kobj_attribute *attr,
+			    char *buf)
+{
+	struct nvme_tcp_queue *queue = nvme_queue_info_data(kobj);
+	struct sockaddr_storage src, dst;
+	int ret = 0;
+
+	mutex_lock(&queue->queue_lock);
+
+	if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags))
+		goto out;
+
+	ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src);
+	if (ret <= 0)
+		goto out;
+
+	ret = kernel_getpeername(queue->sock, (struct sockaddr *)&dst);
+	if (ret <= 0)
+		goto out;
+
+	if (src.ss_family != dst.ss_family) {
+		ret = -EAFNOSUPPORT;
+		goto out;
+	}
+
+	if (src.ss_family == AF_INET) {
+		struct sockaddr_in *sip = (struct sockaddr_in *)&src;
+		struct sockaddr_in *dip = (struct sockaddr_in *)&dst;
+
+		ret = sysfs_emit(buf, "sip=%pI4,sport=%hu,dip=%pI4,dport=%hu\n",
+				 &sip->sin_addr.s_addr, ntohs(sip->sin_port),
+				 &dip->sin_addr.s_addr, ntohs(dip->sin_port));

drivers/nvme/host/tcp.c static ssize_t managed_show(struct kobject *kobj, struct kobj_attribute *attr, · line 2171

Quoted 10 lines
drivers/nvme/host/tcp.c +10 -0
+	} else if (src.ss_family == AF_INET6) {
+		struct sockaddr_in6 *sip6 = (struct sockaddr_in6 *)&src;
+		struct sockaddr_in6 *dip6 = (struct sockaddr_in6 *)&dst;
+
+		if (sip6->sin6_scope_id || dip6->sin6_scope_id)
+			ret = sysfs_emit(buf, "sip=%pI6c%%%u,sport=%hu,dip=%pI6c%%%u,dport=%hu\n",
+					 &sip6->sin6_addr, sip6->sin6_scope_id,
+					 ntohs(sip6->sin6_port),
+					 &dip6->sin6_addr, dip6->sin6_scope_id,
+					 ntohs(dip6->sin6_port));

[Severity: Medium]
Does this emit a "%0" suffix on the unscoped endpoint when only one of sip6->sin6_scope_id or dip6->sin6_scope_id is non-zero?

Quoted 7 lines

inet6_getname() sets sin6_scope_id via ipv6_iface_scope_id(), which only returns sk->sk_bound_dev_if for addresses that need a scope ID (such as link-local addresses) and returns 0 for global or unique-local addresses. If one side of the connection uses a link-local address and the other uses a global or unique-local address, formatting both with "%%%u" appends "%0" to the unscoped address.

Yes, that's correct. However, IMO, emitting %0 as the scope ID for the unscoped IPv6 address should be acceptable.

First, I doubt there are many use cases where a host connects to a link-local target address using a non-link-local source address. Even if such a configuration exists, a parser consuming this sysfs attribute can simply treat a scope-id of 0 as no scope-id.

On another note, the kernel also supports the %pISsc printk format specifier to print an IPv6 address along with its scope ID. This would similarly print %0 when the scope ID is zero.

That said, it is possible to avoid printing the scope-id for an endpoint when it is zero. However, doing so would require additional conditional formatting logic, making the code slightly more complicated.

If others feel that we should omit the scope-id when it is zero, I'm happy to make that change.

Thanks,
--Nilay

#4 lore raw

Re: [PATCH v5 1/1] nvme-tcp: expose per-queue socket addresses via sysfs

In reply to Nilay Shroff

I think the Sashiko nit on the output format has merit, but it's not really my area of expertise. Can you look into that?

drivers/nvme/host/tcp.c static ssize_t managed_show(struct kobject *kobj, struct kobj_attribute *attr, · line 2164

Quoted 10 lines
drivers/nvme/host/tcp.c +10 -0
+	if (src.ss_family == AF_INET) {
+		struct sockaddr_in *sip = (struct sockaddr_in *)&src;
+		struct sockaddr_in *dip = (struct sockaddr_in *)&dst;
+
+		ret = sysfs_emit(buf, "sip=%pI4,sport=%hu,dip=%pI4,dport=%hu\n",
+				 &sip->sin_addr.s_addr, ntohs(sip->sin_port),
+				 &dip->sin_addr.s_addr, ntohs(dip->sin_port));
+	} else if (src.ss_family == AF_INET6) {
+		struct sockaddr_in6 *sip6 = (struct sockaddr_in6 *)&src;
+		struct sockaddr_in6 *dip6 = (struct sockaddr_in6 *)&dst;

And another cosmetic nit, what about doing a switch on src.ss_family and then having a helper for each address family to give this a bit more structure?

#5 lore raw

Re: [PATCH v5 1/1] nvme-tcp: expose per-queue socket addresses via sysfs

Quoted 3 lines · Christoph Hellwig

I think the Sashiko nit on the output format has merit, but it's not really my area of expertise. Can you look into that?

Yes I just responded to that comment from sashiko add all the reviewers in Cc. I think we shall discuss or comment on the issue raised by Sashiko in that email thread.

Quoted 6 lines
Quoted 6 lines
drivers/nvme/host/tcp.c +6 -0
+	if (src.ss_family == AF_INET) {
+		struct sockaddr_in *sip = (struct sockaddr_in *)&src;
+		struct sockaddr_in *dip = (struct sockaddr_in *)&dst;
+
+		ret = sysfs_emit(buf, "sip=%pI4,sport=%hu,dip=%pI4,dport=%hu\n",
+				 &sip->sin_addr.s_addr, ntohs(sip->sin_port),
Quoted 9 lines

drivers/nvme/host/tcp.c static ssize_t managed_show(struct kobject *kobj, struct kobj_attribute *attr, · line 2164

Quoted 4 lines
drivers/nvme/host/tcp.c +4 -0
+				 &dip->sin_addr.s_addr, ntohs(dip->sin_port));
+	} else if (src.ss_family == AF_INET6) {
+		struct sockaddr_in6 *sip6 = (struct sockaddr_in6 *)&src;
+		struct sockaddr_in6 *dip6 = (struct sockaddr_in6 *)&dst;

And another cosmetic nit, what about doing a switch on src.ss_family and then having a helper for each address family to give this a bit more structure?

Sure, makes sense. I will reformat the code in the next revision.

Thanks,
--Nilay