summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2026-01-16 19:44:02 +0300
committerJakub Kicinski <kuba@kernel.org>2026-01-21 05:25:33 +0300
commit79bfa5fb85870d44a5368790dbf5ccce007e6e9f (patch)
treed8e9579982dc8548bde3a94f34ec93c75a38da54
parentee7be82f8c7e753e38dcf3add7ba65b543d49bd6 (diff)
downloadlinux-79bfa5fb85870d44a5368790dbf5ccce007e6e9f.tar.xz
net: fclone allocation small optimization
After skb allocation, initial skb->fclone value is 0 (SKB_FCLONE_UNAVAILABLE) We can replace one RMW sequence with a single OR instruction. movzbl 0x7e(%r13),%eax // skb->fclone = SKB_FCLONE_ORIG; and $0xf3,%al or $0x4,%al mov %al,0x7e(%r13) -> or $0x4,0x7e(%r13) // skb->fclone |= SKB_FCLONE_ORIG; Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20260116164402.1872649-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--net/core/skbuff.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f2367818c130..1c2b9ae7bce6 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -723,7 +723,14 @@ fallback:
fclones = container_of(skb, struct sk_buff_fclones, skb1);
- skb->fclone = SKB_FCLONE_ORIG;
+ /* skb->fclone is a 2bits field.
+ * Replace expensive RMW (skb->fclone = SKB_FCLONE_ORIG)
+ * with a single OR.
+ */
+ BUILD_BUG_ON(SKB_FCLONE_UNAVAILABLE != 0);
+ DEBUG_NET_WARN_ON_ONCE(skb->fclone != SKB_FCLONE_UNAVAILABLE);
+ skb->fclone |= SKB_FCLONE_ORIG;
+
refcount_set(&fclones->fclone_ref, 1);
}