Skip to contentSkip to conversation

xps: Transmit Packet Steering

PATCH Applied Tom Herbert 6 participants 21 messages Nov 21, 2010 – Dec 1, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v7 2/2 xps: Transmit Packet Steering

This patch implements transmit packet steering (XPS) for multiqueue devices. XPS selects a transmit queue during packet transmission based on configuration. This is done by mapping the CPU transmitting the packet to a queue. This is the transmit side analogue to RPS-- where RPS is selecting a CPU based on receive queue, XPS selects a queue based on the CPU (previously there was an XPS patch from Eric Dumazet, but that might more appropriately be called transmit completion steering).

Each transmit queue can be associated with a number of CPUs which will use the queue to send packets. This is configured as a CPU mask on a per queue basis in:

/sys/class/net/eth<n>/queues/tx-<n>/xps_cpus

The mappings are stored per device in an inverted data structure that maps CPUs to queues. In the netdevice structure this is an array of num_possible_cpu structures where each structure holds and array of queue_indexes for queues which that CPU can use.

The benefits of XPS are improved locality in the per queue data structures. Also, transmit completions are more likely to be done nearer to the sending thread, so this should promote locality back to the socket on free (e.g. UDP). The benefits of XPS are dependent on cache hierarchy, application load, and other factors. XPS would nominally be configured so that a queue would only be shared by CPUs which are sharing a cache, the degenerative configuration woud be that each CPU has it's own queue.

Below are some benchmark results which show the potential benfit of this patch. The netperf test has 500 instances of netperf TCP_RR test with 1 byte req. and resp.

bnx2x on 16 core AMD
XPS (16 queues, 1 TX queue per CPU) 1234K at 100% CPU
No XPS (16 queues) 996K at 100% CPU

---
 include/linux/netdevice.h |   30 ++++
 net/core/dev.c            |   53 ++++++-
 net/core/net-sysfs.c      |  369 ++++++++++++++++++++++++++++++++++++++++++++-
 net/core/net-sysfs.h      |    3 +
 4 files changed, 447 insertions(+), 8 deletions(-)
include/linux/netdevice.h +30 -0
index b45c1b8..badf928 100644
@@ -503,6 +503,10 @@ struct netdev_queue {
 	struct Qdisc		*qdisc;
 	unsigned long		state;
 	struct Qdisc		*qdisc_sleeping;
+#ifdef CONFIG_RPS
+	struct kobject		kobj;
+#endif
+
 /*
  * write mostly part
  */
@@ -530,6 +534,30 @@ struct rps_map {
 #define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + (_num * sizeof(u16)))
 
 /*
+ * This structure holds an XPS map which can be of variable length.  The
+ * map is an array of queues.
+ */
+struct xps_map {
+	unsigned int len;
+	unsigned int alloc_len;
+	struct rcu_head rcu;
+	u16 queues[0];
+};
+#define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + (_num * sizeof(u16)))
+#define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map))	\
+    / sizeof(u16))
+
+/*
+ * This structure holds all XPS maps for device.  Maps are indexed by CPU.
+ */
+struct xps_dev_maps {
+	struct rcu_head rcu;
+	struct xps_map *cpu_map[0];
+};
+#define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) +		\
+    (nr_cpu_ids * sizeof(struct xps_map *)))
+
+/*
  * The rps_dev_flow structure contains the mapping of a flow to a CPU and the
  * tail pointer for that CPU's input queue at the time of last enqueue.
  */
@@ -1016,6 +1044,8 @@ struct net_device {
 	unsigned long		tx_queue_len;	/* Max frames per queue allowed */
 	spinlock_t		tx_global_lock;
 
+	struct xps_dev_maps	*xps_maps;
+
 	/* These may be needed for future network-power-down code. */
 
 	/*
net/core/dev.c +50 -3

95 lines not on this page · raw message

net/core/net-sysfs.c +364 -5

396 lines not on this page · raw message

net/core/net-sysfs.h +3 -0
index 778e157..25ec2ee 100644
@@ -6,6 +6,9 @@ int netdev_register_kobject(struct net_device *);
 void netdev_unregister_kobject(struct net_device *);
 #ifdef CONFIG_RPS
 int net_rx_queue_update_kobjects(struct net_device *, int old_num, int new_num);
+int netdev_queue_update_kobjects(struct net_device *net,
+				 int old_num, int new_num);
+
 #endif
 
 #endif
Signature · 1 line
1.7.3.1
#1 lore raw
Quoted 50 lines · Tom Herbert

This patch implements transmit packet steering (XPS) for multiqueue devices.  XPS selects a transmit queue during packet transmission based on configuration.  This is done by mapping the CPU transmitting the packet to a queue.  This is the transmit side analogue to RPS-- where RPS is selecting a CPU based on receive queue, XPS selects a queue based on the CPU (previously there was an XPS patch from Eric Dumazet, but that might more appropriately be called transmit completion steering).

Each transmit queue can be associated with a number of CPUs which will use the queue to send packets.  This is configured as a CPU mask on a per queue basis in:

/sys/class/net/eth<n>/queues/tx-<n>/xps_cpus

The mappings are stored per device in an inverted data structure that maps CPUs to queues.  In the netdevice structure this is an array of num_possible_cpu structures where each structure holds and array of queue_indexes for queues which that CPU can use.

The benefits of XPS are improved locality in the per queue data structures.  Also, transmit completions are more likely to be done nearer to the sending thread, so this should promote locality back to the socket on free (e.g. UDP).  The benefits of XPS are dependent on cache hierarchy, application load, and other factors.  XPS would nominally be configured so that a queue would only be shared by CPUs which are sharing a cache, the degenerative configuration woud be that each CPU has it's own queue.

Below are some benchmark results which show the potential benfit of this patch.  The netperf test has 500 instances of netperf TCP_RR test with 1 byte req. and resp.

bnx2x on 16 core AMD
  XPS (16 queues, 1 TX queue per CPU)  1234K at 100% CPU No XPS (16 queues)                   996K at 100% CPU

---
 include/linux/netdevice.h |   30 ++++
 net/core/dev.c            |   53 ++++++-
 net/core/net-sysfs.c      |  369 ++++++++++++++++++++++++++++++++++++++++++++- net/core/net-sysfs.h      |    3 +

 4 files changed, 447 insertions(+), 8 deletions(-)
include/linux/netdevice.h +0 -0
index b45c1b8..badf928 100644

include/linux/netdevice.h struct netdev_queue { · line 509

Quoted 7 lines
include/linux/netdevice.h +4 -0
@@ -503,6 +503,10 @@ struct netdev_queue {
        struct Qdisc            *qdisc;
        unsigned long           state;
        struct Qdisc            *qdisc_sleeping;
+#ifdef CONFIG_RPS
+       struct kobject          kobj;
+#endif
+

Why do you reuse CONFIG_RPS? I think it is confusing, as the code enclosed is for XPS not RPS.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#2 lore raw
In reply to Tom Herbert

Le dimanche 21 novembre 2010 à 15:17 -0800, Tom Herbert a écrit :

...

Quoted 51 lines
net/core/net-sysfs.c +51 -0
+
+static DEFINE_MUTEX(xps_map_mutex);
+
+static ssize_t store_xps_map(struct netdev_queue *queue,
+		      struct netdev_queue_attribute *attribute,
+		      const char *buf, size_t len)
+{
+	struct net_device *dev = queue->dev;
+	cpumask_var_t mask;
+	int err, i, cpu, pos, map_len, alloc_len, need_set;
+	unsigned long index;
+	struct xps_map *map, *new_map;
+	struct xps_dev_maps *dev_maps, *new_dev_maps;
+	int nonempty = 0;
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
+		return -ENOMEM;
+
+	index = get_netdev_queue_index(queue);
+
+	err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits);
+	if (err) {
+		free_cpumask_var(mask);
+		return err;
+	}
+
+	new_dev_maps = kzalloc(max_t(unsigned,
+	    XPS_DEV_MAPS_SIZE, L1_CACHE_BYTES), GFP_KERNEL);
+	if (!new_dev_maps) {
+		free_cpumask_var(mask);
+		return -ENOMEM;
+	}
+
+	mutex_lock(&xps_map_mutex);
+
+	dev_maps = dev->xps_maps;
+
+	for_each_possible_cpu(cpu) {
+		new_map = map = dev_maps ? dev_maps->cpu_map[cpu] : NULL;
+
+		if (map) {
+			for (pos = 0; pos < map->len; pos++)
+				if (map->queues[pos] == index)
+					break;
+			map_len = map->len;
+			alloc_len = map->alloc_len;
+		} else
+			pos = map_len = alloc_len = 0;

net/core/net-sysfs.c net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num) · line 954

Quoted 10 lines
net/core/net-sysfs.c +10 -0
+
+		need_set = cpu_isset(cpu, *mask) && cpu_online(cpu);
+
+		if (need_set && pos >= map_len) {
+			/* Need to add queue to this CPU's map */
+			if (map_len >= alloc_len) {
+				alloc_len = alloc_len ?
+				    2 * alloc_len : XPS_MIN_MAP_ALLOC;
+				new_map = kzalloc(XPS_MAP_SIZE(alloc_len),
+				    GFP_KERNEL);

kzalloc_node(size, GFP_KERNEL, cpu_to_node(cpu))

to get memory close to the cpu ?

Quoted 28 lines
net/core/net-sysfs.c +28 -0
+				if (!new_map)
+					goto error;
+				new_map->alloc_len = alloc_len;
+				for (i = 0; i < map_len; i++)
+					new_map->queues[i] = map->queues[i];
+				new_map->len = map_len;
+			}
+			new_map->queues[new_map->len++] = index;
+		} else if (!need_set && pos < map_len) {
+			/* Need to remove queue from this CPU's map */
+			if (map_len > 1)
+				new_map->queues[pos] =
+				    new_map->queues[--new_map->len];
+			else
+				new_map = NULL;
+		}
+		new_dev_maps->cpu_map[cpu] = new_map;
+	}
+
+	/* Cleanup old maps */
+	for_each_possible_cpu(cpu) {
+		map = dev_maps ? dev_maps->cpu_map[cpu] : NULL;
+		if (map && new_dev_maps->cpu_map[cpu] != map)
+			call_rcu(&map->rcu, xps_map_release);
+		if (new_dev_maps->cpu_map[cpu])
+			nonempty = 1;
+	}
+
maintainer Applied
#3 lore raw
In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Sun, 21 Nov 2010 15:17:27 -0800 (PST)

Quoted 33 lines

This patch implements transmit packet steering (XPS) for multiqueue devices. XPS selects a transmit queue during packet transmission based on configuration. This is done by mapping the CPU transmitting the packet to a queue. This is the transmit side analogue to RPS-- where RPS is selecting a CPU based on receive queue, XPS selects a queue based on the CPU (previously there was an XPS patch from Eric Dumazet, but that might more appropriately be called transmit completion steering).

Each transmit queue can be associated with a number of CPUs which will use the queue to send packets. This is configured as a CPU mask on a per queue basis in:

/sys/class/net/eth<n>/queues/tx-<n>/xps_cpus

The mappings are stored per device in an inverted data structure that maps CPUs to queues. In the netdevice structure this is an array of num_possible_cpu structures where each structure holds and array of queue_indexes for queues which that CPU can use.

The benefits of XPS are improved locality in the per queue data structures. Also, transmit completions are more likely to be done nearer to the sending thread, so this should promote locality back to the socket on free (e.g. UDP). The benefits of XPS are dependent on cache hierarchy, application load, and other factors. XPS would nominally be configured so that a queue would only be shared by CPUs which are sharing a cache, the degenerative configuration woud be that each CPU has it's own queue.

Below are some benchmark results which show the potential benfit of this patch. The netperf test has 500 instances of netperf TCP_RR test with 1 byte req. and resp.

Quoted 5 lines

bnx2x on 16 core AMD
XPS (16 queues, 1 TX queue per CPU) 1234K at 100% CPU
No XPS (16 queues) 996K at 100% CPU

Applied, please consider Eric's feedback about map NUMA node placement.

#4 lore raw
Quoted 1 line

Applied, please consider Eric's feedback about map NUMA node placement.

Yes, I intended to do that. Also, I was planning to add Changli's idea of adding CONFIG_XPS. Also, I believe the case where CONFIG_RPS is not enabled breaks the build, I'll send a fix as soon as possible.

Tom

#5 lore raw
Quoted 7 lines · Tom Herbert
Quoted 1 line

Applied, please consider Eric's feedback about map NUMA node placement.

Yes, I intended to do that. Also, I was planning to add Changli's idea of adding CONFIG_XPS. Also, I believe the case where CONFIG_RPS is not enabled breaks the build, I'll send a fix as soon as possible.

Tom

I'll provide a patch as soon as David pushes net-next-2.6, dont worry ;)

Thanks !

#6 lore raw

PATCH 1/1 xps: NUMA allocations for per cpu data

store_xps_map() allocates maps that are used by single cpu, it makes sense to use NUMA allocations.

---
 net/core/net-sysfs.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/core/net-sysfs.c +3 -2
index 68dbbfd..35f28b1 100644
@@ -950,8 +950,9 @@ static ssize_t store_xps_map(struct netdev_queue *queue,
 			if (map_len >= alloc_len) {
 				alloc_len = alloc_len ?
 				    2 * alloc_len : XPS_MIN_MAP_ALLOC;
-				new_map = kzalloc(XPS_MAP_SIZE(alloc_len),
-				    GFP_KERNEL);
+				new_map = kzalloc_node(XPS_MAP_SIZE(alloc_len),
+						       GFP_KERNEL,
+						       cpu_to_node(cpu));
 				if (!new_map)
 					goto error;
 				new_map->alloc_len = alloc_len;
#8 lore raw
In reply to Tom Herbert

On Sun, 2010-11-21 at 15:17 -0800, Tom Herbert wrote:
[...]

Quoted 10 lines

Each transmit queue can be associated with a number of CPUs which will use the queue to send packets. This is configured as a CPU mask on a per queue basis in:

/sys/class/net/eth<n>/queues/tx-<n>/xps_cpus

The mappings are stored per device in an inverted data structure that maps CPUs to queues. In the netdevice structure this is an array of num_possible_cpu structures where each structure holds and array of queue_indexes for queues which that CPU can use.

[...]

I was thinking we could also use CPU reverse-mapping from IRQ affinity to set this up automatically - maybe leaving an option for manual override?

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#9 lore raw

PATCH 1/1 sched: use xps information for qdisc NUMA affinity

I was thinking of using XPS tx_queue->cpu mapping to eventually allocate memory with correct NUMA affinities, for qdisc/class stuff for example.

Here is a first patch to allocate qdisc with proper NUMA affinities.

Tested on my 16-cpus machine

echo 0001 >/sys/class/net/eth1/queues/tx-0/xps_cpus echo 0002 >/sys/class/net/eth1/queues/tx-1/xps_cpus echo 0004 >/sys/class/net/eth1/queues/tx-2/xps_cpus echo 0008 >/sys/class/net/eth1/queues/tx-3/xps_cpus echo 0010 >/sys/class/net/eth1/queues/tx-4/xps_cpus echo 0020 >/sys/class/net/eth1/queues/tx-5/xps_cpus echo 0040 >/sys/class/net/eth1/queues/tx-6/xps_cpus echo 0080 >/sys/class/net/eth1/queues/tx-7/xps_cpus echo 0100 >/sys/class/net/eth1/queues/tx-8/xps_cpus echo 0200 >/sys/class/net/eth1/queues/tx-9/xps_cpus echo 0400 >/sys/class/net/eth1/queues/tx-10/xps_cpus echo 0800 >/sys/class/net/eth1/queues/tx-11/xps_cpus echo 1000 >/sys/class/net/eth1/queues/tx-12/xps_cpus echo 2000 >/sys/class/net/eth1/queues/tx-13/xps_cpus echo 4000 >/sys/class/net/eth1/queues/tx-14/xps_cpus echo 8000 >/sys/class/net/eth1/queues/tx-15/xps_cpus

tc qdisc del dev eth1 root
tc qdisc add dev eth1 root mq

Thanks

[PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Allocate qdisc memory according to NUMA properties of cpus included in xps map.

To be effective, qdisc should be (re)setup after changes of /sys/class/net/eth<n>/queues/tx-<n>/xps_cpus

I added a numa_node field in struct netdev_queue, containing NUMA node if all cpus included in xps_cpus share same node, else -1.

Cc Ben Hutchings <[email protected]>
Cc Tom Herbert <[email protected]>
---
 include/linux/netdevice.h |   20 +++++++++++++++++++-
 net/core/dev.c            |    5 +++--
 net/core/net-sysfs.c      |   12 +++++++++++-
 net/sched/sch_generic.c   |    4 +++-
 4 files changed, 36 insertions(+), 5 deletions(-)
include/linux/netdevice.h +19 -1
index 9ae4544..f912de7 100644
@@ -508,7 +508,9 @@ struct netdev_queue {
 #ifdef CONFIG_RPS
 	struct kobject		kobj;
 #endif
-
+#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
+	int			numa_node;
+#endif
 /*
  * write mostly part
  */
@@ -523,6 +525,22 @@ struct netdev_queue {
 	u64			tx_dropped;
 } ____cacheline_aligned_in_smp;
 
+static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
+{
+#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
+	return q->numa_node;
+#else
+	return -1;
+#endif
+}
+
+static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
+{
+#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
+	q->numa_node = node;
+#endif
+}
+
 #ifdef CONFIG_RPS
 /*
  * This structure holds an RPS map which can be of variable length.  The
net/core/dev.c +3 -2
index 3259d2c..cd24374 100644
@@ -5125,9 +5125,10 @@ static int netif_alloc_netdev_queues(struct net_device *dev)
 	}
 	dev->_tx = tx;
 
-	for (i = 0; i < count; i++)
+	for (i = 0; i < count; i++) {
+		netdev_queue_numa_node_write(&tx[i], -1);
 		tx[i].dev = dev;
-
+	}
 	return 0;
 }
 
net/core/net-sysfs.c +11 -1
index 99c1129..149dde0 100644
@@ -911,6 +911,7 @@ static ssize_t store_xps_map(struct netdev_queue *queue,
 	struct xps_map *map, *new_map;
 	struct xps_dev_maps *dev_maps, *new_dev_maps;
 	int nonempty = 0;
+	int numa_node = -2;
 
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
@@ -950,7 +951,14 @@ static ssize_t store_xps_map(struct netdev_queue *queue,
 			pos = map_len = alloc_len = 0;
 
 		need_set = cpu_isset(cpu, *mask) && cpu_online(cpu);
-
+#ifdef CONFIG_NUMA
+		if (need_set) {
+			if (numa_node == -2)
+				numa_node = cpu_to_node(cpu);
+			else if (numa_node != cpu_to_node(cpu))
+				numa_node = -1;
+		}
+#endif
 		if (need_set && pos >= map_len) {
 			/* Need to add queue to this CPU's map */
 			if (map_len >= alloc_len) {
@@ -996,6 +1004,8 @@ static ssize_t store_xps_map(struct netdev_queue *queue,
 	if (dev_maps)
 		call_rcu(&dev_maps->rcu, xps_dev_maps_release);
 
+	netdev_queue_numa_node_write(queue, (numa_node >= 0) ? numa_node : -1);
+
 	mutex_unlock(&xps_map_mutex);
 
 	free_cpumask_var(mask);
net/sched/sch_generic.c +3 -1
index 7f0bd89..0918834 100644
@@ -553,7 +553,9 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
 	size = QDISC_ALIGN(sizeof(*sch));
 	size += ops->priv_size + (QDISC_ALIGNTO - 1);
 
-	p = kzalloc(size, GFP_KERNEL);
+	p = kzalloc_node(size, GFP_KERNEL,
+			 netdev_queue_numa_node_read(dev_queue));
+
 	if (!p)
 		goto errout;
 	sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
#10 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Quoted 3 lines · Eric Dumazet

I was thinking of using XPS tx_queue->cpu mapping to eventually allocate memory with correct NUMA affinities, for qdisc/class stuff for example.

An interesting idea, but the real question is can this be used for all queue related allocations. This includes those that drivers allocate which are probably done in initialization.

Tom

#11 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Quoted 9 lines · Tom Herbert
Quoted 3 lines · Eric Dumazet

I was thinking of using XPS tx_queue->cpu mapping to eventually allocate memory with correct NUMA affinities, for qdisc/class stuff for example.

An interesting idea, but the real question is can this be used for all queue related allocations. This includes those that drivers allocate which are probably done in initialization.

This would need a callback to device, to eventually re-allocate its ring buffer (or whatever data structures it allocated). Probably worth it, considering size of txbd on some NICS (up to one cache line per entry)

Right now, they tend to allocate their memory on a single NUMA node, so it is a problem.

#12 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Quoted 11 lines · Eric Dumazet
Quoted 9 lines · Tom Herbert
Quoted 3 lines · Eric Dumazet

I was thinking of using XPS tx_queue->cpu mapping to eventually allocate memory with correct NUMA affinities, for qdisc/class stuff for example.

An interesting idea, but the real question is can this be used for all queue related allocations. This includes those that drivers allocate which are probably done in initialization.

Quoted 6 lines

This would need a callback to device, to eventually re-allocate its ring buffer (or whatever data structures it allocated). Probably worth it, considering size of txbd on some NICS (up to one cache line per entry)

Right now, they tend to allocate their memory on a single NUMA node, so it is a problem.

Yes, that's why I proposed an ethtool interface for reconfiguring this. Although to be honest I haven't yet constructed a case where it made a difference. I think the most important objects to be allocated on the right node are RX buffers, and as long as refill is scheduled on the same CPU as the IRQ this already happens.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#13 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Quoted 6 lines · Ben Hutchings

Yes, that's why I proposed an ethtool interface for reconfiguring this. Although to be honest I haven't yet constructed a case where it made a difference. I think the most important objects to be allocated on the right node are RX buffers, and as long as refill is scheduled on the same CPU as the IRQ this already happens.

Hmm, right now RX skbs are allocated on the right node, since they are allocated on the node of the cpu handling the {soft}irq.

commit 564824b0c52c346

net: allocate skbs on local node

commit b30973f877 (node-aware skb allocation) spread a wrong habit of allocating net drivers skbs on a given memory node : The one closest to the NIC hardware. This is wrong because as soon as we try to scale network stack, we need to use many cpus to handle traffic and hit slub/slab management on cross-node allocations/frees when these cpus have to alloc/free skbs bound to a central node.

skb allocated in RX path are ephemeral, they have a very short lifetime : Extra cost to maintain NUMA affinity is too expensive. What appeared as a nice idea four years ago is in fact a bad one.

In 2010, NIC hardwares are multiqueue, or we use RPS to spread the load, and two 10Gb NIC might deliver more than 28 million packets per second, needing all the available cpus.

Cost of cross-node handling in network and vm stacks outperforms the small benefit hardware had when doing its DMA transfert in its 'local' memory node at RX time. Even trying to differentiate the two allocations done for one skb (the sk_buff on local node, the data part on NIC hardware node) is not enough to bring good performance.

maintainer
#14 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Tue, 30 Nov 2010 10:31:48 -0800

Quoted 8 lines · Eric Dumazet
Quoted 3 lines

I was thinking of using XPS tx_queue->cpu mapping to eventually allocate memory with correct NUMA affinities, for qdisc/class stuff for example.

An interesting idea, but the real question is can this be used for all queue related allocations. This includes those that drivers allocate which are probably done in initialization.

Most drivers do, and all drivers ought to, allocate DMA queues and whatnot when the interface is brought up.

That solves this particular issue.

For example, drivers/net/niu.c does this by calling niu_alloc_channels() via niu_open().

The only thing we really can't handle currently is the netdev itself (and the associated driver private). Jesse Brandeburg has been reminding me about this over and over :-)

There might be some things we can even do about that part. For example, we can put all of the things the driver touches in the RX and TX fast paths via indirect pointers and therefore be able to allocate and reallocate those portions as we want long after device registry.

Doing the core netdev struct itself is too hard because it sits in so many tables.

#15 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Quoted 12 lines · David Miller

Most drivers do, and all drivers ought to, allocate DMA queues and whatnot when the interface is brought up.

That solves this particular issue.

For example, drivers/net/niu.c does this by calling niu_alloc_channels() via niu_open().

The only thing we really can't handle currently is the netdev itself (and the associated driver private). Jesse Brandeburg has been reminding me about this over and over :-)

Quoted 8 lines

There might be some things we can even do about that part. For example, we can put all of the things the driver touches in the RX and TX fast paths via indirect pointers and therefore be able to allocate and reallocate those portions as we want long after device registry.

Doing the core netdev struct itself is too hard because it sits in so many tables.

netdev struct itself is shared by all cpus, so there is no real choice, unless you know one netdev will be used by a restricted set of cpus/nodes... Probably very unlikely in practice.

This can probably be done right now with
numactl .... modprobe ...

We could change (only on NUMA setups maybe)

struct netdev_queue *_tx;

to a

struct netdev_queue **_tx;

and allocate each "struct netdev_queue" on appropriate node, but adding one indirection level might be overkill...

For very hot small structures, (one or two cache lines), I am not sure its worth the pain.

Ben, could you remind us what was your ethtool interface ?

Something to setup a NUMA map for RX queues, TX queues ?

I can probably play with bnx2x and custom module param to test how it can help raw performance...

#16 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

On Tue, 2010-11-30 at 20:07 +0100, Eric Dumazet wrote:
[...]

Quoted 6 lines

Ben, could you remind us what was your ethtool interface ?

Something to setup a NUMA map for RX queues, TX queues ?

I can probably play with bnx2x and custom module param to test how it can help raw performance...

See these patches:

<http://patchwork.ozlabs.org/patch/65201/>
<http://patchwork.ozlabs.org/patch/65202/>

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
maintainer
#17 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Tue, 30 Nov 2010 20:07:27 +0100

[ Jesse CC:'d ]

Quoted 3 lines

netdev struct itself is shared by all cpus, so there is no real choice, unless you know one netdev will be used by a restricted set of cpus/nodes... Probably very unlikely in practice.

Unfortunately Jesse has found non-trivial gains by NUMA localizing the netdev struct during routing tests in soome configurations.

Quoted 6 lines

We could change (only on NUMA setups maybe)

struct netdev_queue *_tx;

to a

Quoted 7 lines

struct netdev_queue **_tx;

and allocate each "struct netdev_queue" on appropriate node, but adding one indirection level might be overkill...

For very hot small structures, (one or two cache lines), I am not sure its worth the pain.

Jesse, do you think this would help the case you were testing?

#18 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Quoted 11 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Tue, 30 Nov 2010 20:07:27 +0100

[ Jesse CC:'d ]

Quoted 3 lines

netdev struct itself is shared by all cpus, so there is no real choice, unless you know one netdev will be used by a restricted set of cpus/nodes... Probably very unlikely in practice.

Unfortunately Jesse has found non-trivial gains by NUMA localizing the netdev struct during routing tests in soome configurations.

Thanks Dave, given the results I can see with current upstream (at least igb) I don't think that netdev access is hurting performance unless the driver is unwisely accessing netdev structs for write on multiple cpus simultaneously.

I think the trick is to have drivers that are concerned with this kind of thing have a "hot path struct" that is used at runtime. Since the cache on the numa systems will still cache remote node memory for read, if it is not written to, then the read data will be housed on each cpus' L3.

Quoted 10 lines
Quoted 10 lines

We could change (only on NUMA setups maybe)

struct netdev_queue *_tx;

to a

struct netdev_queue **_tx;

and allocate each "struct netdev_queue" on appropriate node, but adding one indirection level might be overkill...

I agree probably overkill.

Quoted 4 lines
Quoted 2 lines

For very hot small structures, (one or two cache lines), I am not sure its worth the pain.

Jesse, do you think this would help the case you were testing?

I would be glad to test, but I am currently seeing pretty good results with upstream igb. I'll retest with latest kernel and with

# taskset 1 insmod igb.ko
echo 2 > /proc/irq/<igb irqs>/smp_affinity

(1 and 2 are different sockets on my machine)

maintainer
#19 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Mon, 29 Nov 2010 19:14:37 +0100

Quoted 5 lines

[PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Allocate qdisc memory according to NUMA properties of cpus included in xps map.

Quoted 7 lines

To be effective, qdisc should be (re)setup after changes of /sys/class/net/eth<n>/queues/tx-<n>/xps_cpus

I added a numa_node field in struct netdev_queue, containing NUMA node if all cpus included in xps_cpus share same node, else -1.

I think this is good enough to cook in net-next-2.6

Please use "net sched: " instead of just plain "sched: " in your commit header lines so that people don't confuse such changes with process scheduler ones :-)

#20 lore raw

Re: [PATCH net-next-2.6] sched: use xps information for qdisc NUMA affinity

Quoted 5 lines · David Miller

I think this is good enough to cook in net-next-2.6

Please use "net sched: " instead of just plain "sched: " in your commit header lines so that people don't confuse such changes with process scheduler ones :-)

Yes, I'll try to remember next time, thanks !