From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next] net: add skb_defer_disable_key static key
Date: Wed, 11 Mar 2026 19:13:40 +0000 [thread overview]
Message-ID: <20260311191340.1996888-1-edumazet@google.com> (raw)
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 <edumazet@google.com>
---
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(-)
diff --git a/net/core/net-sysfs.h b/net/core/net-sysfs.h
index e938f25e8e86f9dfd8f710a08922c4cabf662c2e..38e2e3ffd0bdc4ccea2f6c7636c1bbc7d0f46af5 100644
--- a/net/core/net-sysfs.h
+++ b/net/core/net-sysfs.h
@@ -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
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 513cbfed19bc34bbb6767cdd7a50dad68be430fb..3d6978dd0aa83f63984b994359d0c914c6427a00 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -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;
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 502705e0464981ecfc32233d22c747e14b3febf7..b508618bfc12393ba926ebf5a2dd4ea73ef03ee8 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -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,
},
};
--
2.53.0.473.g4a7958ca14-goog
next reply other threads:[~2026-03-11 19:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 19:13 Eric Dumazet [this message]
2026-03-13 2:50 ` [PATCH net-next] net: add skb_defer_disable_key static key patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260311191340.1996888-1-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox