net: minor __alloc_skb() optimization
Subsystems (2)
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
@@ -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
Jakub Kicinski
maintainerQuoted 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?
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 addedslab_build_skb()surely any buggy driver that's actually used would have already hit thatWARN_ONCE()and gotten reported?
We could keep it for a while, WDYT of
net/core/skbuff.c +0 -0
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);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 addedslab_build_skb()surely any buggy driver that's actually used would have already hit thatWARN_ONCE()and gotten reported?We could keep it for a while, WDYT of
net/core/skbuff.c +0
-0100644
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
Jakub Kicinski
maintainerQuoted 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
-0100644
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 :(
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.Signed-off-by Eric Dumazet <[email protected]>--- 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