net: skbuff: replace magic number with macro in skbuff_clear()
Subsystems (2)
PATCH 1/1 net: skbuff: replace magic number with macro in skbuff_clear()
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 <[email protected]>
--- net/core/skbuff.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
net/core/skbuff.c +11 -3
@@ -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 ); }/**
Signature · 1 line
2.43.0
Just a gentle ping on this patch sent on July 23rd, any feedback appreciated.
Thanks,
Ziran Zhang