Skip to contentSkip to conversation

net: inline napi_skb_cache_get()

PATCH Applied Eric Dumazet 3 participants 4 messages Jan 12 – Jan 15

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

PATCH 1/1 net: inline napi_skb_cache_get()

clang is inlining it already, gcc (14.2) does not.

Small space cost (215 bytes on x86_64) but faster sk_buff allocations.

$ scripts/bloat-o-meter -t net/core/skbuff.gcc.before.o net/core/skbuff.gcc.after.o
add/remove: 0/1 grow/shrink: 4/1 up/down: 359/-144 (215)
Function                                     old     new   delta
__alloc_skb                                  471     611    +140
napi_build_skb                               245     363    +118
napi_alloc_skb                               331     416     +85
skb_copy_ubufs                              1869    1885     +16
skb_shift                                   1445    1413     -32
napi_skb_cache_get                           112       -    -112
Total: Before=59941, After=60156, chg +0.36%
---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/skbuff.c +1 -1
index a56133902c0d9c47b45a4a19b228b151456e5051..9e94590914b7f9b1cc748262c73eb5aa4f9d2df8 100644
@@ -280,7 +280,7 @@ EXPORT_SYMBOL(__netdev_alloc_frag_align);
  */
 static u32 skbuff_cache_size __read_mostly;
 
-static struct sk_buff *napi_skb_cache_get(bool alloc)
+static inline struct sk_buff *napi_skb_cache_get(bool alloc)
 {
 	struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
 	struct sk_buff *skb;
Signature · 1 line
2.52.0.457.g6b5491de43-goog
maintainer
#1 lore raw
Quoted 15 lines · Eric Dumazet

clang is inlining it already, gcc (14.2) does not.

Small space cost (215 bytes on x86_64) but faster sk_buff allocations.

$ scripts/bloat-o-meter -t net/core/skbuff.gcc.before.o net/core/skbuff.gcc.after.o
add/remove: 0/1 grow/shrink: 4/1 up/down: 359/-144 (215)
Function                                     old     new   delta
__alloc_skb                                  471     611    +140
napi_build_skb                               245     363    +118
napi_alloc_skb                               331     416     +85
skb_copy_ubufs                              1869    1885     +16
skb_shift                                   1445    1413     -32
napi_skb_cache_get                           112       -    -112
Total: Before=59941, After=60156, chg +0.36%
Quoted 1 line

Not blocking this patch, but I'm wondering if we should consider defining an 'inline_for_performance' macro for both documentation purpose and to allow no inline for size-sensitive build.

Paolo

#2 lore raw
Quoted 17 lines · Paolo Abeni
Quoted 15 lines · Eric Dumazet

clang is inlining it already, gcc (14.2) does not.

Small space cost (215 bytes on x86_64) but faster sk_buff allocations.

$ scripts/bloat-o-meter -t net/core/skbuff.gcc.before.o net/core/skbuff.gcc.after.o
add/remove: 0/1 grow/shrink: 4/1 up/down: 359/-144 (215)
Function                                     old     new   delta
__alloc_skb                                  471     611    +140
napi_build_skb                               245     363    +118
napi_alloc_skb                               331     416     +85
skb_copy_ubufs                              1869    1885     +16
skb_shift                                   1445    1413     -32
napi_skb_cache_get                           112       -    -112
Total: Before=59941, After=60156, chg +0.36%
Quoted 5 lines
Quoted 1 line

Not blocking this patch, but I'm wondering if we should consider defining an 'inline_for_performance' macro for both documentation purpose and to allow no inline for size-sensitive build.

Yes, I saw mm/slub.c was using __fastpath_inline, but conditional to CONFIG_SLUB_TINY,
and forcing __always_inline

#ifndef CONFIG_SLUB_TINY
#define __fastpath_inline __always_inline
#else
#define __fastpath_inline
#endif

(For some reason clang is not very smart at compiling mm/slub.c, I am preparing a series to help with that)

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

Hello:

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

Quoted 15 lines · On Mon, 12 Jan 2026 13:15:15 +0000 you wrote:

clang is inlining it already, gcc (14.2) does not.

Small space cost (215 bytes on x86_64) but faster sk_buff allocations.

$ scripts/bloat-o-meter -t net/core/skbuff.gcc.before.o net/core/skbuff.gcc.after.o
add/remove: 0/1 grow/shrink: 4/1 up/down: 359/-144 (215)
Function                                     old     new   delta
__alloc_skb                                  471     611    +140
napi_build_skb                               245     363    +118
napi_alloc_skb                               331     416     +85
skb_copy_ubufs                              1869    1885     +16
skb_shift                                   1445    1413     -32
napi_skb_cache_get                           112       -    -112
Total: Before=59941, After=60156, chg +0.36%
Quoted 1 line

[...]

Here is the summary with links:
- [net-next] net: inline napi_skb_cache_get()

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

You are awesome, thank you!

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