Skip to content

Commit

Permalink
net: save some cycles when doing skb_attempt_defer_free()
Browse files Browse the repository at this point in the history
mainline inclusion
from mainline-v6.10-rc1
category: performance

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 <[email protected]>
Reviewed-by: Alexander Lobakin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Wentao Guan <[email protected]>
  • Loading branch information
JasonXing authored and opsiff committed Dec 24, 2024
1 parent dc2896c commit 8e7a5c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -6834,9 +6834,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(skb);
return;
}
Expand Down

0 comments on commit 8e7a5c3

Please sign in to comment.