diff mbox series

[net-next,v2] net: save some cycles when doing skb_attempt_defer_free()

Message ID 20240412030718.68016-1-kerneljasonxing@gmail.com (mailing list archive)
State Accepted
Commit 4d0470b9ad73e965f5a1e52f1deb0edbb6d03c89
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2] net: save some cycles when doing skb_attempt_defer_free() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 928 this patch: 928
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 938 this patch: 938
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 939 this patch: 939
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 53 this patch: 53
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-12--06-00 (tests: 962)

Commit Message

Jason Xing April 12, 2024, 3:07 a.m. UTC
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(-)

Comments

patchwork-bot+netdevbpf@kernel.org April 15, 2024, 9:40 a.m. UTC | #1
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!
diff mbox series

Patch

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;
 	}