net: add skb_defer_disable_key static key
Subsystems (2)
PATCH 1/1 net: add skb_defer_disable_key static key
Add a static key to bypass skb_attempt_defer_free() steps if net.core.skb_defer_max is set to zero.
Main benefit is the atomic_long_inc_return() avoidance.
Signed-off-by Eric Dumazet <[email protected]>
--- net/core/net-sysfs.h | 1 + net/core/skbuff.c | 5 +++++ net/core/sysctl_net_core.c | 25 ++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-)
net/core/net-sysfs.h +1 -0
@@ -13,4 +13,5 @@ int netdev_change_owner(struct net_device *, const struct net *net_old,extern struct mutex rps_default_mask_mutex; +DECLARE_STATIC_KEY_FALSE (skb_defer_disable_key);#endif
net/core/skbuff.c +5 -0
@@ -7256,6 +7256,8 @@ static void kfree_skb_napi_cache(struct sk_buff *skb)local_bh_enable (); } +DEFINE_STATIC_KEY_FALSE (skb_defer_disable_key); +/** * skb_attempt_defer_free - queue skb for remote freeing * @skb: buffer
@@ -7272,6 +7274,9 @@ void skb_attempt_defer_free(struct sk_buff *skb)bool kick;int cpu; +if (static_branch_unlikely (&skb_defer_disable_key)) + goto nodefer; +/* zero copy notifications should not be delayed. */ if (skb_zcopy (skb)) goto nodefer;
net/core/sysctl_net_core.c +24 -1
@@ -349,6 +349,29 @@ static int proc_do_rss_key(const struct ctl_table *table, int write,return proc_dostring (&fake_table, write, buffer, lenp, ppos); } +static int proc_do_skb_defer_max (const struct ctl_table *table,int write, +void *buffer,size_t *lenp,loff_t *ppos) +{ +static DEFINE_MUTEX (skb_defer_max_mutex); +int ret, oval, nval; + +mutex_lock (&skb_defer_max_mutex); + + oval = !net_hotdata.sysctl_skb_defer_max; + ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos); + nval = !net_hotdata.sysctl_skb_defer_max; + +if (nval != oval) { +if (nval) +static_branch_enable (&skb_defer_disable_key); +else +static_branch_disable (&skb_defer_disable_key); + } + +mutex_unlock (&skb_defer_max_mutex); +return ret; +} +#ifdef CONFIG_BPF_JIT static int proc_dointvec_minmax_bpf_enable(const struct ctl_table *table, int write, void *buffer, size_t *lenp,
@@ -650,7 +673,7 @@ static struct ctl_table net_core_table[] = { .data = &net_hotdata.sysctl_skb_defer_max, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_do_skb_defer_max, .extra1 = SYSCTL_ZERO, }, };
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
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 8 lines · On Wed, 11 Mar 2026 19:13:40 +0000 you wrote:
Add a static key to bypass
skb_attempt_defer_free()steps if net.core.skb_defer_max is set to zero.Main benefit is the
atomic_long_inc_return()avoidance.Signed-off-by Eric Dumazet <[email protected]>[...]
Here is the summary with links:
- [net-next] net: add skb_defer_disable_key static key
https://git.kernel.org/netdev/net-next/c/08dc30de1a40
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html