Skip to contentSkip to conversation

net: iterate online nodes in skb_defer_free_flush()

PATCH Superseded Kris Pan 3 participants 6 messages Sep 11 – Sep 16

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kris Pan

author
#0 lore raw

PATCH 1/1 net: iterate online nodes in skb_defer_free_flush()

skb_attempt_defer_free() only queues skbs on the current CPU's node (numa_node_id() of a running CPU), which is always online, so the flush loop never needs to visit nodes that are merely possible.

for_each_node() walks node_possible_map. On machines where the possible map is much larger than the online map -- e.g. a POWER10 LPAR with 32 possible but 1 online node -- the flush loop touches 31 cold, always-empty per-node lists on every softirq pass, showing up as skb_defer_free_flush() and _find_next_bit() overhead.

Use for_each_online_node() to iterate only node_online_map.

Loopback UDP throughput in a QEMU guest with 32 possible / 1 online nodes (bench_udp, 8 senders, 6 interleaved runs) improves by ~5%.

Fixes 5628f3fe3b16 ("net: add NUMA awareness to skb_attempt_defer_free()")
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
index 290e0f099e6bf..b528b6a986fcf 100644
@@ -6907,7 +6907,7 @@ static void skb_defer_free_flush(void)
 	struct skb_defer_node *sdn;
 	int node;
 
-	for_each_node(node) {
+	for_each_online_node(node) {
 		sdn = this_cpu_ptr(net_hotdata.skb_defer_nodes) + node;
 
 		if (llist_empty(&sdn->defer_list))
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Kris Pan

skb_attempt_defer_free() only queues skbs on the current CPU's node (numa_node_id() of a running CPU), which is always online, so the flush loop never needs to visit nodes that are merely possible.

for_each_node() walks node_possible_map. On machines where the possible map is much larger than the online map -- e.g. a POWER10 LPAR with 32 possible but 1 online node -- the flush loop touches 31 cold, always-empty per-node lists on every softirq pass, showing up as skb_defer_free_flush() and _find_next_bit() overhead.

Use for_each_online_node() to iterate only node_online_map.

Loopback UDP throughput in a QEMU guest with 32 possible / 1 online nodes (bench_udp, 8 senders, 6 interleaved runs) improves by ~5%.

Fixes 5628f3fe3b16 ("net: add NUMA awareness to skb_attempt_defer_free()")
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +0 -0
index 290e0f099e6bf..b528b6a986fcf 100644

net/core/dev.c static void skb_defer_free_flush(void) · line 6910

Quoted 5 lines
net/core/dev.c +1 -1
@@ -6907,7 +6907,7 @@ static void skb_defer_free_flush(void)
        struct skb_defer_node *sdn;
        int node;
 
-       for_each_node(node) {
+       for_each_online_node(node) {

SGTM, but you probably could have added

(Assuming you read
https://lore.kernel.org/oe-lkp/[email protected]/)

Thanks.

author
#2 lore raw

PATCH v2 1/1 net: iterate online nodes in skb_defer_free_flush()

In reply to Kris Pan

skb_attempt_defer_free() only queues skbs on the current CPU's node (numa_node_id() of a running CPU), which is always online, so the flush loop never needs to visit nodes that are merely possible.

for_each_node() walks node_possible_map. On machines where the possible map is much larger than the online map -- e.g. a POWER10 LPAR with 32 possible but 1 online node -- the flush loop touches 31 cold, always-empty per-node lists on every softirq pass, showing up as skb_defer_free_flush() and _find_next_bit() overhead.

Use for_each_online_node() to iterate only node_online_map.

Loopback UDP throughput in a QEMU guest with 32 possible / 1 online nodes (bench_udp, 8 senders, 6 interleaved runs) improves by ~5%.

Fixes 5628f3fe3b16 ("net: add NUMA awareness to skb_attempt_defer_free()")
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
index 290e0f099e6bf..b528b6a986fcf 100644
@@ -6907,7 +6907,7 @@ static void skb_defer_free_flush(void)
 	struct skb_defer_node *sdn;
 	int node;
 
-	for_each_node(node) {
+	for_each_online_node(node) {
 		sdn = this_cpu_ptr(net_hotdata.skb_defer_nodes) + node;
 
 		if (llist_empty(&sdn->defer_list))
Signature · 1 line
2.43.0
maintainer
#3 lore raw
Quoted 10 lines · On Fri, 11 Sep 2026 10:38:04 +0800 Kris Pan wrote:

skb_attempt_defer_free() only queues skbs on the current CPU's node (numa_node_id() of a running CPU), which is always online, so the flush loop never needs to visit nodes that are merely possible.

for_each_node() walks node_possible_map. On machines where the possible map is much larger than the online map -- e.g. a POWER10 LPAR with 32 possible but 1 online node -- the flush loop touches 31 cold, always-empty per-node lists on every softirq pass, showing up as skb_defer_free_flush() and _find_next_bit() overhead.

Quoted 4 lines

Use for_each_online_node() to iterate only node_online_map.

Loopback UDP throughput in a QEMU guest with 32 possible / 1 online nodes (bench_udp, 8 senders, 6 interleaved runs) improves by ~5%.

Clashiko confirms this is racy:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]

Signature · 1 line
pw-bot: cr
author
#4 lore raw

Right, the node-offline race is real. I'll fix it in a v3 so the flush doesn't depend on node_online_map, e.g. a per-CPU mask of pending nodes set by the producer and drained by the flush.

Thanks.

#5 lore raw
Quoted 4 lines · Kris Pan

Right, the node-offline race is real. I'll fix it in a v3 so the flush doesn't depend on node_online_map, e.g. a per-CPU mask of pending nodes set by the producer and drained by the flush.

Certainly not.

We should not add a per-CPU active-node bitmask updated by skb_attempt_defer_free(),
as writing to a shared bitmask from remote CPUs would re-introduce the cross-NUMA
cache line bouncing that commit 5628f3fe3b16 eliminated.

Instead, keep for_each_online_node(node) in the skb_defer_free_flush() fast path,
and handle cleanup in the cold dev_cpu_dead(unsigned int oldcpu) hotplug path.