Skip to contentSkip to conversation

net: skbuff: don't copy alloc_cpu in skb header copies

PATCH Superseded Carolina Jubran 3 participants 3 messages Oct 12

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: skbuff: don't copy alloc_cpu in skb header copies

Commit 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") added alloc_cpu to struct sk_buff and placed it in the headers group copied by __copy_skb_header().

This is wrong for newly allocated skbs. For example, skb_segment() allocates a new skb and records the current CPU in alloc_cpu, but __copy_skb_header() overwrites it with the value from the original skb.

If the original skb was allocated on another CPU, the segment may later be treated as remotely allocated and unnecessarily deferred there when it is freed.

Move alloc_cpu out of the headers group so it is preserved across header copies. Initialize it explicitly in skb_clone(), which allocates the skb object directly instead of going through __alloc_skb().

This was discovered while investigating a throughput regression with software IPsec. The load used 512 IPsec tunnels carrying traffic over VXLAN, with 512 parallel iperf3 flows and an MTU of 4500.

Before the fix:

16.09% queued_spin_lock_slowpath

             |
             --15.90%--_raw_spin_lock_irqsave
                       |
                       --9.37%--__slab_free
                                 kfree
                                 skb_release_data
                                 napi_consume_skb
                                 mlx5e_poll_tx_cq

After the fix:

6.84% queued_spin_lock_slowpath

             |
             --6.57%--_raw_spin_lock_irqsave
                      |
                      --5.00%--__slab_free
                                kfree
                                skb_release_data
                                napi_consume_skb
                                mlx5e_poll_tx_cq
Fixes 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists")
---
 include/linux/skbuff.h | 2 +-
 net/core/skbuff.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/skbuff.h +1 -1
index a3ff380d43f01..2d5277765939f 100644
@@ -963,6 +963,7 @@ struct sk_buff {
 #ifdef CONFIG_SKB_EXTENSIONS
 	__u8			active_extensions;
 #endif
+	u16                     alloc_cpu;
 
 	/* Fields enclosed in headers group are copied
 	 * using a single memcpy() in __copy_skb_header()
@@ -1036,7 +1037,6 @@ struct sk_buff {
 	__u16			tc_index;	/* traffic control index */
 #endif
 
-	u16			alloc_cpu;
 
 	union {
 		__wsum		csum;
net/core/skbuff.c +1 -1
index 41beaf625421a..3d82eb87f4582 100644
@@ -1593,7 +1593,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
 #ifdef CONFIG_NET_RX_BUSY_POLL
 	CHECK_SKB_FIELD(napi_id);
 #endif
-	CHECK_SKB_FIELD(alloc_cpu);
 #ifdef CONFIG_XPS
 	CHECK_SKB_FIELD(sender_cpu);
 #endif
@@ -1618,6 +1617,7 @@ static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb)
 	C(len);
 	C(data_len);
 	C(mac_len);
+	C(alloc_cpu);
 	n->hdr_len = skb->nohdr ? skb_headroom(skb) : skb->hdr_len;
 	n->cloned = 1;
 	n->nohdr = 0;
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 44 lines · Carolina Jubran

Commit 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") added alloc_cpu to struct sk_buff and placed it in the headers group copied by __copy_skb_header().

This is wrong for newly allocated skbs. For example, skb_segment() allocates a new skb and records the current CPU in alloc_cpu, but __copy_skb_header() overwrites it with the value from the original skb.

If the original skb was allocated on another CPU, the segment may later be treated as remotely allocated and unnecessarily deferred there when it is freed.

Move alloc_cpu out of the headers group so it is preserved across header copies. Initialize it explicitly in skb_clone(), which allocates the skb object directly instead of going through __alloc_skb().

This was discovered while investigating a throughput regression with software IPsec. The load used 512 IPsec tunnels carrying traffic over VXLAN, with 512 parallel iperf3 flows and an MTU of 4500.

Before the fix:

16.09% queued_spin_lock_slowpath

             |
             --15.90%--_raw_spin_lock_irqsave
                       |
                       --9.37%--__slab_free
                                 kfree
                                 skb_release_data
                                 napi_consume_skb
                                 mlx5e_poll_tx_cq

After the fix:

   6.84%  queued_spin_lock_slowpath
             |
             --6.57%--_raw_spin_lock_irqsave
                      |
                      --5.00%--__slab_free
                                kfree
                                skb_release_data
                                napi_consume_skb
                                mlx5e_poll_tx_cq
Quoted 3 lines
Fixes 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists")
maintainer
#2 lore raw
In reply to Carolina Jubran
Quoted 58 lines · Carolina Jubran

Commit 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") added alloc_cpu to struct sk_buff and placed it in the headers group copied by __copy_skb_header().

This is wrong for newly allocated skbs. For example, skb_segment() allocates a new skb and records the current CPU in alloc_cpu, but __copy_skb_header() overwrites it with the value from the original skb.

If the original skb was allocated on another CPU, the segment may later be treated as remotely allocated and unnecessarily deferred there when it is freed.

Move alloc_cpu out of the headers group so it is preserved across header copies. Initialize it explicitly in skb_clone(), which allocates the skb object directly instead of going through __alloc_skb().

This was discovered while investigating a throughput regression with software IPsec. The load used 512 IPsec tunnels carrying traffic over VXLAN, with 512 parallel iperf3 flows and an MTU of 4500.

Before the fix:

16.09% queued_spin_lock_slowpath

             |
             --15.90%--_raw_spin_lock_irqsave
                       |
                       --9.37%--__slab_free
                                 kfree
                                 skb_release_data
                                 napi_consume_skb
                                 mlx5e_poll_tx_cq

After the fix:

   6.84%  queued_spin_lock_slowpath
             |
             --6.57%--_raw_spin_lock_irqsave
                      |
                      --5.00%--__slab_free
                                kfree
                                skb_release_data
                                napi_consume_skb
                                mlx5e_poll_tx_cq
Fixes 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists")
---
 include/linux/skbuff.h | 2 +-
 net/core/skbuff.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/skbuff.h +0 -0
index a3ff380d43f01..2d5277765939f 100644

include/linux/skbuff.h struct sk_buff { · line 966

Quoted 4 lines
include/linux/skbuff.h +1 -0
@@ -963,6 +963,7 @@ struct sk_buff {
 #ifdef CONFIG_SKB_EXTENSIONS
        __u8                    active_extensions;
 #endif
+       u16                     alloc_cpu;

spaces instead of tab here.

I had on my plate a better placement of alloc_cpu, end, tail... I would move alloc_cpu _after_ headers group.