net: advance skb_defer_disable_key check in napi_consume_skb
Subsystems (2)
PATCH v4 1/1 net: advance skb_defer_disable_key check in napi_consume_skb
From: Jason Xing <[email protected]>
When net.core.skb_defer_max is adjusted to zero, napi_consume_skb() shouldn't go into that deeper in skb_attempt_defer_free() because it adds an additional pair of local_bh_enable/disable() which is evidently not needed. Advancing the check of the static key saves more cycles and benefits non defer case.
---
v4
1. add the missing header file.
Since a new sysctl might not be preferrable, I deicded to apply the current minimum patch to handle it. If in the future we receive some reports about this point, we will then consider it one more time.
v3
1. use a simpler approach to avoid adding a new sysctl. This is the minimum change to improvement defer_max 0 case.
V2
1. reuse proc_do_static_key() (Eric)
2. add doc (Stan)
--- net/core/skbuff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -1
@@ -94,6 +94,7 @@#include "dev.h" #include "devmem.h" +#include "net-sysfs.h" #include "netmem_priv.h" #include "sock_destructor.h"
@@ -1519,7 +1520,8 @@ void napi_consume_skb(struct sk_buff *skb, int budget)DEBUG_NET_WARN_ON_ONCE (!in_softirq ()); -if (skb->alloc_cpu !=smp_processor_id () && !skb_shared (skb)) { +if (!static_branch_unlikely (&skb_defer_disable_key) && + skb->alloc_cpu !=smp_processor_id () && !skb_shared (skb)) {skb_release_head_state (skb);return skb_attempt_defer_free (skb); }
Signature · 1 line
2.41.3
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 9 lines · On Thu, 2 Apr 2026 11:41:14 +0800 you wrote:
From: Jason Xing <[email protected]>
When net.core.skb_defer_max is adjusted to zero,
napi_consume_skb()shouldn't go into that deeper inskb_attempt_defer_free()because it adds an additional pair of local_bh_enable/disable() which is evidently not needed. Advancing the check of the static key saves more cycles and benefits non defer case.[...]
Here is the summary with links:
- [v4,net-next] net: advance skb_defer_disable_key check in napi_consume_skb
https://git.kernel.org/netdev/net-next/c/8a4e3ab61d49
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html