netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: save some cycles when doing skb_attempt_defer_free()
@ 2024-04-11  3:24 Jason Xing
  2024-04-11  5:27 ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Xing @ 2024-04-11  3:24 UTC (permalink / raw)
  To: edumazet, pablo, kuba, pabeni, davem, horms, aleksander.lobakin
  Cc: netdev, kerneljasonxing, Jason Xing

From: Jason Xing <kernelxing@tencent.com>

Normally, we don't face these two exceptions very often meanwhile
we have some chance to meet the condition where the current cpu id
is the same as skb->alloc_cpu.

One simple test that can help us see the frequency of this statement
'cpu == raw_smp_processor_id()':
1. running iperf -s and iperf -c [ip] -P [MAX CPU]
2. using BPF to capture skb_attempt_defer_free()

I can see around 4% chance that happens to satisfy the statement.
So moving this statement at the beginning can save some cycles in
most cases.

Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
 net/core/skbuff.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ab970ded8a7b..b4f252dc91fb 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -7002,9 +7002,9 @@ void skb_attempt_defer_free(struct sk_buff *skb)
 	unsigned int defer_max;
 	bool kick;
 
-	if (WARN_ON_ONCE(cpu >= nr_cpu_ids) ||
+	if (cpu == raw_smp_processor_id() ||
 	    !cpu_online(cpu) ||
-	    cpu == raw_smp_processor_id()) {
+	    WARN_ON_ONCE(cpu >= nr_cpu_ids)) {
 nodefer:	kfree_skb_napi_cache(skb);
 		return;
 	}
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-11 10:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-11  3:24 [PATCH net-next] net: save some cycles when doing skb_attempt_defer_free() Jason Xing
2024-04-11  5:27 ` Eric Dumazet
2024-04-11  6:32   ` Jason Xing
2024-04-11  7:11     ` Eric Dumazet
2024-04-11  7:31       ` Jason Xing
2024-04-11  9:11         ` Alexander Lobakin
2024-04-11 10:00           ` Jason Xing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).