Skip to contentSkip to conversation

net: minor __alloc_skb() optimization

PATCH Applied Eric Dumazet 3 participants 6 messages Jan 13 – Jan 16

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

PATCH 1/1 net: minor __alloc_skb() optimization

We can directly call __finalize_skb_around() instead of __build_skb_around() because @size is not zero.

---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/skbuff.c +1 -1
index 4887099e8678352a62d805e1b0be2736dc985376..77508cf7c41e829a11a988d8de3d2673ff1ff121 100644
@@ -714,7 +714,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
 	prefetchw(data + SKB_WITH_OVERHEAD(size));
 
 	skbuff_clear(skb);
-	__build_skb_around(skb, data, size);
+	__finalize_skb_around(skb, data, size);
 	skb->pfmemalloc = pfmemalloc;
 
 	if (flags & SKB_ALLOC_FCLONE) {
Signature · 1 line
2.52.0.457.g6b5491de43-goog
maintainer
#1 lore raw
Quoted 2 lines · On Tue, 13 Jan 2026 13:10:17 +0000 Eric Dumazet wrote:

We can directly call __finalize_skb_around() instead of __build_skb_around() because @size is not zero.

FWIW I've been tempted to delete the zero check from __build_skb_around() completely recently.. It's been a few years since we added slab_build_skb() surely any buggy driver that's actually used would have already hit that WARN_ONCE() and gotten reported?

#2 lore raw
Quoted 10 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 13 Jan 2026 13:10:17 +0000 Eric Dumazet wrote:

We can directly call __finalize_skb_around() instead of __build_skb_around() because @size is not zero.

FWIW I've been tempted to delete the zero check from __build_skb_around() completely recently.. It's been a few years since we added slab_build_skb() surely any buggy driver that's actually used would have already hit that WARN_ONCE() and gotten reported?

We could keep it for a while, WDYT of

net/core/skbuff.c +0 -0
index 77508cf7c41e829a11a988d8de3d2673ff1ff121..ccd287ff46e91c2548483c51fa32fc6167867940

100644

net/core/skbuff.c +0 -0
@@ -458,7 +458,8 @@ static void __build_skb_around(struct sk_buff

*skb, void *data,

        /* frag_size == 0 is considered deprecated now. Callers
         * using slab buffer should use slab_build_skb() instead.
         */
-       if (WARN_ONCE(size == 0, "Use slab_build_skb() instead"))
+       if (IS_ENABLED(CONFIG_DEBUG_NET) &&
+           WARN_ONCE(size == 0, "Use slab_build_skb() instead"))
                data = __slab_build_skb(data, &size);

        __finalize_skb_around(skb, data, size);
#3 lore raw
Quoted 30 lines · Eric Dumazet
Quoted 10 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 13 Jan 2026 13:10:17 +0000 Eric Dumazet wrote:

We can directly call __finalize_skb_around() instead of __build_skb_around() because @size is not zero.

FWIW I've been tempted to delete the zero check from __build_skb_around() completely recently.. It's been a few years since we added slab_build_skb() surely any buggy driver that's actually used would have already hit that WARN_ONCE() and gotten reported?

We could keep it for a while, WDYT of

net/core/skbuff.c +0 -0
index 77508cf7c41e829a11a988d8de3d2673ff1ff121..ccd287ff46e91c2548483c51fa32fc6167867940

100644

net/core/skbuff.c +2 -1
@@ -458,7 +458,8 @@ static void __build_skb_around(struct sk_buff
 *skb, void *data,
        /* frag_size == 0 is considered deprecated now. Callers
         * using slab buffer should use slab_build_skb() instead.
         */
-       if (WARN_ONCE(size == 0, "Use slab_build_skb() instead"))
+       if (IS_ENABLED(CONFIG_DEBUG_NET) &&
+           WARN_ONCE(size == 0, "Use slab_build_skb() instead"))
                data = __slab_build_skb(data, &size);
 
Quoted 1 line
        __finalize_skb_around(skb, data, size);

BTW, for folks using clang and not up to date kernels, backporting this commit makes sure __build_skb_around() is at least inlined.

commit 242b872239f6a7deacbc20ab9406ea40cb738ec6

Author: Xie Yuanbin <[email protected]>
Date:   Sun Nov 9 16:37:15 2025 +0800

include/linux/once_lite.h: fix judgment in WARN_ONCE with clang

maintainer
#4 lore raw
In reply to Eric Dumazet
Quoted 8 lines · On Wed, 14 Jan 2026 02:54:10 +0100 Eric Dumazet wrote:

We could keep it for a while, WDYT of

net/core/skbuff.c +0 -0
index 77508cf7c41e829a11a988d8de3d2673ff1ff121..ccd287ff46e91c2548483c51fa32fc6167867940

100644

net/core/skbuff.c static void __build_skb_around(struct sk_buff · line 464

Quoted 8 lines
net/core/skbuff.c +2 -1
@@ -458,7 +458,8 @@ static void __build_skb_around(struct sk_buff
 *skb, void *data,
        /* frag_size == 0 is considered deprecated now. Callers
         * using slab buffer should use slab_build_skb() instead.
         */
-       if (WARN_ONCE(size == 0, "Use slab_build_skb() instead"))
+       if (IS_ENABLED(CONFIG_DEBUG_NET) &&
+           WARN_ONCE(size == 0, "Use slab_build_skb() instead"))
                data = __slab_build_skb(data, &size);

Probably not worth it. People who use relevant HW + 3 year old kernels (I just checked, we added the warning in Dec 2022) likely don't set DEBUG_NET either. That said looks like the warning landed in 6.2, narrowly missing the v6.1 LTS. I suppose v6.1 may still be used by some "enterprise-ish" distroes. I guess we should wait another year :( Sorry for the noise :(

#5 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 7 lines · On Tue, 13 Jan 2026 13:10:17 +0000 you wrote:

We can directly call __finalize_skb_around() instead of __build_skb_around() because @size is not zero.

---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
- [net-next] net: minor __alloc_skb() optimization

    https://git.kernel.org/netdev/net-next/c/2db009e4c8d6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html