The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ziran Zhang <zhangcoder@yeah.net>
To: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ziran Zhang <zhangcoder@yeah.net>
Subject: [PATCH] net: skbuff: replace magic number with macro in skbuff_clear()
Date: Thu, 23 Jul 2026 22:47:24 +0800	[thread overview]
Message-ID: <20260723144724.6492-1-zhangcoder@yeah.net> (raw)

The number 128 in skbuff_clear() is to split a large
memset into two smaller ones, so the compiler can inline
both calls instead of a single memset function call.

Replace the number with a named macro, so its purpose is
documented and the value can be easily adjusted if needed.

Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
 net/core/skbuff.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 18dabb4e9..e3f8a93bd 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -228,6 +228,12 @@ static void skb_under_panic(struct sk_buff *skb, unsigned int sz, void *addr)
 #define NAPI_SKB_CACHE_BULK	32
 #define NAPI_SKB_CACHE_FREE	32
 
+/*
+ * For offsetof(struct sk_buff, tail) == 184, the 64-byte loop in
+ * memset_orig() runs twice (2 * 64 = 128). Splitting here for inlining.
+ */
+#define SKB_CLEAR_INLINE_CHUNK_SIZE	128
+
 struct napi_alloc_cache {
 	local_lock_t bh_lock;
 	struct page_frag_cache page;
@@ -319,10 +325,12 @@ static inline void skbuff_clear(struct sk_buff *skb)
 	 * with two smaller memset(), with a barrier() between them.
 	 * This forces the compiler to inline both calls.
 	 */
-	BUILD_BUG_ON(offsetof(struct sk_buff, tail) <= 128);
-	memset(skb, 0, 128);
+	BUILD_BUG_ON(offsetof(struct sk_buff, tail) <=
+		     SKB_CLEAR_INLINE_CHUNK_SIZE);
+	memset(skb, 0, SKB_CLEAR_INLINE_CHUNK_SIZE);
 	barrier();
-	memset((void *)skb + 128, 0, offsetof(struct sk_buff, tail) - 128);
+	memset((void *)skb + SKB_CLEAR_INLINE_CHUNK_SIZE, 0,
+	       offsetof(struct sk_buff, tail) - SKB_CLEAR_INLINE_CHUNK_SIZE);
 }
 
 /**
-- 
2.43.0


                 reply	other threads:[~2026-07-23 15:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260723144724.6492-1-zhangcoder@yeah.net \
    --to=zhangcoder@yeah.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.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