netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: save some cycles when doing skb_attempt_defer_free()
@ 2024-04-12  3:07 Jason Xing
  2024-04-15  9:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Xing @ 2024-04-12  3:07 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>
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
---
v2
Link: https://lore.kernel.org/all/20240411032450.51649-1-kerneljasonxing@gmail.com/
1. Fix the wrong order of testing cpu (Eric)
---
 net/core/skbuff.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ab970ded8a7b..6dc577a3ea6a 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) ||
-	    !cpu_online(cpu) ||
-	    cpu == raw_smp_processor_id()) {
+	if (cpu == raw_smp_processor_id() ||
+	    WARN_ON_ONCE(cpu >= nr_cpu_ids) ||
+	    !cpu_online(cpu)) {
 nodefer:	kfree_skb_napi_cache(skb);
 		return;
 	}
-- 
2.37.3


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

* Re: [PATCH net-next v2] net: save some cycles when doing skb_attempt_defer_free()
  2024-04-12  3:07 [PATCH net-next v2] net: save some cycles when doing skb_attempt_defer_free() Jason Xing
@ 2024-04-15  9:40 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-15  9:40 UTC (permalink / raw)
  To: Jason Xing
  Cc: edumazet, pablo, kuba, pabeni, davem, horms, aleksander.lobakin,
	netdev, kernelxing

Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Fri, 12 Apr 2024 11:07:18 +0800 you wrote:
> 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()
> 
> [...]

Here is the summary with links:
  - [net-next,v2] net: save some cycles when doing skb_attempt_defer_free()
    https://git.kernel.org/netdev/net-next/c/4d0470b9ad73

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-04-15  9:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-12  3:07 [PATCH net-next v2] net: save some cycles when doing skb_attempt_defer_free() Jason Xing
2024-04-15  9:40 ` patchwork-bot+netdevbpf

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).