* [PATCH net-next 1/4] net: increase default NAPI_SKB_CACHE_SIZE to 128
2025-11-18 7:06 [PATCH net-next 0/4] net: adjust conservative values around napi Jason Xing
@ 2025-11-18 7:06 ` Jason Xing
2025-11-18 7:06 ` [PATCH net-next 2/4] net: increase default NAPI_SKB_CACHE_BULK to 32 Jason Xing
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jason Xing @ 2025-11-18 7:06 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms; +Cc: netdev, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
After commit b61785852ed0 ("net: increase skb_defer_max default to 128")
changed the value sysctl_skb_defer_max to avoid many calls to
kick_defer_list_purge(), the same situation can be applied to
NAPI_SKB_CACHE_SIZE that was proposed in 2016. It's a trade-off between
using pre-allocated memory in skb_cache and saving more a bit heavy
function calls in the softirq context.
With this patch applied, we can have more skbs per-cpu to accelerate the
sending path that needs to acquire new skbs.
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
net/core/skbuff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 9feea830a4db..e4abf0e56776 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -223,7 +223,7 @@ static void skb_under_panic(struct sk_buff *skb, unsigned int sz, void *addr)
skb_panic(skb, sz, addr, __func__);
}
-#define NAPI_SKB_CACHE_SIZE 64
+#define NAPI_SKB_CACHE_SIZE 128
#define NAPI_SKB_CACHE_BULK 16
#define NAPI_SKB_CACHE_HALF (NAPI_SKB_CACHE_SIZE / 2)
--
2.41.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net-next 2/4] net: increase default NAPI_SKB_CACHE_BULK to 32
2025-11-18 7:06 [PATCH net-next 0/4] net: adjust conservative values around napi Jason Xing
2025-11-18 7:06 ` [PATCH net-next 1/4] net: increase default NAPI_SKB_CACHE_SIZE to 128 Jason Xing
@ 2025-11-18 7:06 ` Jason Xing
2025-11-18 7:06 ` [PATCH net-next 3/4] net: use NAPI_SKB_CACHE_FREE to keep 32 as default to do bulk free Jason Xing
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jason Xing @ 2025-11-18 7:06 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms; +Cc: netdev, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
The previous value 16 is a bit conservative, so adjust it along with
NAPI_SKB_CACHE_SIZE, which can minimize triggering memory allocation
in napi_skb_cache_get*().
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
net/core/skbuff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index e4abf0e56776..b6fe7ab85c4a 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -224,7 +224,7 @@ static void skb_under_panic(struct sk_buff *skb, unsigned int sz, void *addr)
}
#define NAPI_SKB_CACHE_SIZE 128
-#define NAPI_SKB_CACHE_BULK 16
+#define NAPI_SKB_CACHE_BULK 32
#define NAPI_SKB_CACHE_HALF (NAPI_SKB_CACHE_SIZE / 2)
struct napi_alloc_cache {
--
2.41.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net-next 3/4] net: use NAPI_SKB_CACHE_FREE to keep 32 as default to do bulk free
2025-11-18 7:06 [PATCH net-next 0/4] net: adjust conservative values around napi Jason Xing
2025-11-18 7:06 ` [PATCH net-next 1/4] net: increase default NAPI_SKB_CACHE_SIZE to 128 Jason Xing
2025-11-18 7:06 ` [PATCH net-next 2/4] net: increase default NAPI_SKB_CACHE_BULK to 32 Jason Xing
@ 2025-11-18 7:06 ` Jason Xing
2025-11-18 7:06 ` [PATCH net-next 4/4] net: prefetch the next skb in napi_skb_cache_get() Jason Xing
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jason Xing @ 2025-11-18 7:06 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms; +Cc: netdev, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
- Replace NAPI_SKB_CACHE_HALF with NAPI_SKB_CACHE_FREE
- Only free 32 skbs in napi_skb_cache_put()
Since the first patch adjusting NAPI_SKB_CACHE_SIZE to 128, the number
of packets to be freed in the softirq was increased from 32 to 64.
Considering a subsequent net_rx_action() calling napi_poll() a few
times can easily consume the 64 available slots and we can afford
keeping a higher value of sk_buffs in per-cpu storage, decrease
NAPI_SKB_CACHE_FREE to 32 like before. So now the logic is 1) keeping
96 skbs, 2) freeing 32 skbs at one time.
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
net/core/skbuff.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index b6fe7ab85c4a..d81ac78c32ff 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -225,7 +225,7 @@ static void skb_under_panic(struct sk_buff *skb, unsigned int sz, void *addr)
#define NAPI_SKB_CACHE_SIZE 128
#define NAPI_SKB_CACHE_BULK 32
-#define NAPI_SKB_CACHE_HALF (NAPI_SKB_CACHE_SIZE / 2)
+#define NAPI_SKB_CACHE_FREE 32
struct napi_alloc_cache {
local_lock_t bh_lock;
@@ -1445,7 +1445,6 @@ void __consume_stateless_skb(struct sk_buff *skb)
static void napi_skb_cache_put(struct sk_buff *skb)
{
struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
- u32 i;
if (!kasan_mempool_poison_object(skb))
return;
@@ -1454,13 +1453,16 @@ static void napi_skb_cache_put(struct sk_buff *skb)
nc->skb_cache[nc->skb_count++] = skb;
if (unlikely(nc->skb_count == NAPI_SKB_CACHE_SIZE)) {
- for (i = NAPI_SKB_CACHE_HALF; i < NAPI_SKB_CACHE_SIZE; i++)
+ u32 i, remaining = NAPI_SKB_CACHE_SIZE - NAPI_SKB_CACHE_FREE;
+
+ for (i = remaining; i < NAPI_SKB_CACHE_SIZE; i++)
kasan_mempool_unpoison_object(nc->skb_cache[i],
skbuff_cache_size);
- kmem_cache_free_bulk(net_hotdata.skbuff_cache, NAPI_SKB_CACHE_HALF,
- nc->skb_cache + NAPI_SKB_CACHE_HALF);
- nc->skb_count = NAPI_SKB_CACHE_HALF;
+ kmem_cache_free_bulk(net_hotdata.skbuff_cache,
+ NAPI_SKB_CACHE_FREE,
+ nc->skb_cache + remaining);
+ nc->skb_count = remaining;
}
local_unlock_nested_bh(&napi_alloc_cache.bh_lock);
}
--
2.41.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net-next 4/4] net: prefetch the next skb in napi_skb_cache_get()
2025-11-18 7:06 [PATCH net-next 0/4] net: adjust conservative values around napi Jason Xing
` (2 preceding siblings ...)
2025-11-18 7:06 ` [PATCH net-next 3/4] net: use NAPI_SKB_CACHE_FREE to keep 32 as default to do bulk free Jason Xing
@ 2025-11-18 7:06 ` Jason Xing
2025-11-19 7:56 ` [PATCH net-next 0/4] net: adjust conservative values around napi Eric Dumazet
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Jason Xing @ 2025-11-18 7:06 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms; +Cc: netdev, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
After getting the current skb in napi_skb_cache_get(), the next skb in
cache is highly likely to be used soon, so prefetch would be helpful.
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
net/core/skbuff.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index d81ac78c32ff..5a1d123e7ef7 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -299,6 +299,8 @@ static struct sk_buff *napi_skb_cache_get(bool alloc)
}
skb = nc->skb_cache[--nc->skb_count];
+ if (nc->skb_count)
+ prefetch(nc->skb_cache[nc->skb_count - 1]);
local_unlock_nested_bh(&napi_alloc_cache.bh_lock);
kasan_mempool_unpoison_object(skb, skbuff_cache_size);
--
2.41.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net-next 0/4] net: adjust conservative values around napi
2025-11-18 7:06 [PATCH net-next 0/4] net: adjust conservative values around napi Jason Xing
` (3 preceding siblings ...)
2025-11-18 7:06 ` [PATCH net-next 4/4] net: prefetch the next skb in napi_skb_cache_get() Jason Xing
@ 2025-11-19 7:56 ` Eric Dumazet
2025-11-19 17:51 ` Alexander Lobakin
2025-11-20 4:40 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2025-11-19 7:56 UTC (permalink / raw)
To: Jason Xing; +Cc: davem, kuba, pabeni, horms, netdev, Jason Xing
On Mon, Nov 17, 2025 at 11:07 PM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> From: Jason Xing <kernelxing@tencent.com>
>
> This series keeps at least 96 skbs per cpu and frees 32 skbs at one
> time in conclusion. More initial discussions with Eric can be seen at
> the link [1].
>
> [1]: https://lore.kernel.org/all/CAL+tcoBEEjO=-yvE7ZJ4sB2smVBzUht1gJN85CenJhOKV2nD7Q@mail.gmail.com/
>
> ---
> Please note that the series is made on top of the recent series:
> https://lore.kernel.org/all/20251116202717.1542829-1-edumazet@google.com/
>
> Jason Xing (4):
> net: increase default NAPI_SKB_CACHE_SIZE to 128
> net: increase default NAPI_SKB_CACHE_BULK to 32
> net: use NAPI_SKB_CACHE_FREE to keep 32 as default to do bulk free
> net: prefetch the next skb in napi_skb_cache_get()
For the series :
Reviewed-by: Eric Dumazet <edumazet@google.com>
Thanks !
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH net-next 0/4] net: adjust conservative values around napi
2025-11-18 7:06 [PATCH net-next 0/4] net: adjust conservative values around napi Jason Xing
` (4 preceding siblings ...)
2025-11-19 7:56 ` [PATCH net-next 0/4] net: adjust conservative values around napi Eric Dumazet
@ 2025-11-19 17:51 ` Alexander Lobakin
2025-11-19 23:56 ` Jason Xing
2025-11-20 4:40 ` patchwork-bot+netdevbpf
6 siblings, 1 reply; 9+ messages in thread
From: Alexander Lobakin @ 2025-11-19 17:51 UTC (permalink / raw)
To: Jason Xing; +Cc: davem, edumazet, kuba, pabeni, horms, netdev, Jason Xing
From: Jason Xing <kerneljasonxing@gmail.com>
Date: Tue, 18 Nov 2025 15:06:42 +0800
> From: Jason Xing <kernelxing@tencent.com>
>
> This series keeps at least 96 skbs per cpu and frees 32 skbs at one
> time in conclusion. More initial discussions with Eric can be seen at
> the link [1].
>
> [1]: https://lore.kernel.org/all/CAL+tcoBEEjO=-yvE7ZJ4sB2smVBzUht1gJN85CenJhOKV2nD7Q@mail.gmail.com/
>
> ---
> Please note that the series is made on top of the recent series:
> https://lore.kernel.org/all/20251116202717.1542829-1-edumazet@google.com/
>
> Jason Xing (4):
> net: increase default NAPI_SKB_CACHE_SIZE to 128
> net: increase default NAPI_SKB_CACHE_BULK to 32
> net: use NAPI_SKB_CACHE_FREE to keep 32 as default to do bulk free
> net: prefetch the next skb in napi_skb_cache_get()
>
> net/core/skbuff.c | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
For the series:
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
BTW I picked these numbers of 64 (size), 16 (bulk), 32 (free) when I was
working on 1G NICs/switches on a 32-bit MIPS board back in 2020. Lots of
things have changed since then and even back then, these numbers could
be suboptimal for faster NICs/architectures (and yes, the cache never
was NUMA aware as the MIPS arch code doesn't support even building the
kernel in the "NUMA simulation" mode).
I remember clearly that the cache size of 64 was taken to match
NAPI_POLL_WEIGHT.
The size of bulk to allocate was conservative, but back then it gave the
best perf numbers. I believe the bulk allocator has improved a lot for
the past years (note that let's say cpumap still allocates only 8 skbs
per bulk, not sure about veth).
Anyway, lots of things around NAPI caches have changed since then,
especially when it comes to how the kernel now tries to free the skb on
the same CPU it was allocated on. So I'm glad to see these parameters
tweaked.
Thanks,
Olek
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH net-next 0/4] net: adjust conservative values around napi
2025-11-19 17:51 ` Alexander Lobakin
@ 2025-11-19 23:56 ` Jason Xing
0 siblings, 0 replies; 9+ messages in thread
From: Jason Xing @ 2025-11-19 23:56 UTC (permalink / raw)
To: Alexander Lobakin
Cc: davem, edumazet, kuba, pabeni, horms, netdev, Jason Xing
On Thu, Nov 20, 2025 at 1:52 AM Alexander Lobakin
<aleksander.lobakin@intel.com> wrote:
>
> From: Jason Xing <kerneljasonxing@gmail.com>
> Date: Tue, 18 Nov 2025 15:06:42 +0800
>
> > From: Jason Xing <kernelxing@tencent.com>
> >
> > This series keeps at least 96 skbs per cpu and frees 32 skbs at one
> > time in conclusion. More initial discussions with Eric can be seen at
> > the link [1].
> >
> > [1]: https://lore.kernel.org/all/CAL+tcoBEEjO=-yvE7ZJ4sB2smVBzUht1gJN85CenJhOKV2nD7Q@mail.gmail.com/
> >
> > ---
> > Please note that the series is made on top of the recent series:
> > https://lore.kernel.org/all/20251116202717.1542829-1-edumazet@google.com/
> >
> > Jason Xing (4):
> > net: increase default NAPI_SKB_CACHE_SIZE to 128
> > net: increase default NAPI_SKB_CACHE_BULK to 32
> > net: use NAPI_SKB_CACHE_FREE to keep 32 as default to do bulk free
> > net: prefetch the next skb in napi_skb_cache_get()
> >
> > net/core/skbuff.c | 20 ++++++++++++--------
> > 1 file changed, 12 insertions(+), 8 deletions(-)
>
> For the series:
>
> Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
>
> BTW I picked these numbers of 64 (size), 16 (bulk), 32 (free) when I was
> working on 1G NICs/switches on a 32-bit MIPS board back in 2020. Lots of
> things have changed since then and even back then, these numbers could
> be suboptimal for faster NICs/architectures (and yes, the cache never
> was NUMA aware as the MIPS arch code doesn't support even building the
> kernel in the "NUMA simulation" mode).
>
> I remember clearly that the cache size of 64 was taken to match
> NAPI_POLL_WEIGHT.
> The size of bulk to allocate was conservative, but back then it gave the
> best perf numbers. I believe the bulk allocator has improved a lot for
> the past years (note that let's say cpumap still allocates only 8 skbs
> per bulk, not sure about veth).
>
> Anyway, lots of things around NAPI caches have changed since then,
> especially when it comes to how the kernel now tries to free the skb on
> the same CPU it was allocated on. So I'm glad to see these parameters
> tweaked.
Thanks for sharing the important background :) I believe along with
the fast development of NICs we still have many things to work on in
the kernel.
Thanks,
Jason
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 0/4] net: adjust conservative values around napi
2025-11-18 7:06 [PATCH net-next 0/4] net: adjust conservative values around napi Jason Xing
` (5 preceding siblings ...)
2025-11-19 17:51 ` Alexander Lobakin
@ 2025-11-20 4:40 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-20 4:40 UTC (permalink / raw)
To: Jason Xing; +Cc: davem, edumazet, kuba, pabeni, horms, netdev, kernelxing
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 18 Nov 2025 15:06:42 +0800 you wrote:
> From: Jason Xing <kernelxing@tencent.com>
>
> This series keeps at least 96 skbs per cpu and frees 32 skbs at one
> time in conclusion. More initial discussions with Eric can be seen at
> the link [1].
>
> [1]: https://lore.kernel.org/all/CAL+tcoBEEjO=-yvE7ZJ4sB2smVBzUht1gJN85CenJhOKV2nD7Q@mail.gmail.com/
>
> [...]
Here is the summary with links:
- [net-next,1/4] net: increase default NAPI_SKB_CACHE_SIZE to 128
https://git.kernel.org/netdev/net-next/c/3505730d9042
- [net-next,2/4] net: increase default NAPI_SKB_CACHE_BULK to 32
https://git.kernel.org/netdev/net-next/c/01d738561899
- [net-next,3/4] net: use NAPI_SKB_CACHE_FREE to keep 32 as default to do bulk free
https://git.kernel.org/netdev/net-next/c/2d67b5c5c67f
- [net-next,4/4] net: prefetch the next skb in napi_skb_cache_get()
https://git.kernel.org/netdev/net-next/c/5d7fc63ab841
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 9+ messages in thread