All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: skbuff: replace magic number with macro in skbuff_clear()
@ 2026-07-23 14:47 Ziran Zhang
  0 siblings, 0 replies; only message in thread
From: Ziran Zhang @ 2026-07-23 14:47 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, linux-kernel, Ziran Zhang

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-23 15:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 14:47 [PATCH] net: skbuff: replace magic number with macro in skbuff_clear() Ziran Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.