Skip to contentSkip to conversation

net: skb_queue_purge_reason() optimizations

PATCH Applied Eric Dumazet 3 participants 3 messages Oct 3, 2023 – Oct 5, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: skb_queue_purge_reason() optimizations

1) Exit early if the list is empty.

2) splice the list into a local list,
so that we block hard irqs only once.

---
 net/core/skbuff.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
net/core/skbuff.c +12 -3
index 87f5372b197fff4ffef5df34ef126eb1e297ae4c..0401f40973a584ba4a89509b02510c8352bd6fb5 100644
@@ -3722,10 +3722,19 @@ EXPORT_SYMBOL(skb_dequeue_tail);
 void skb_queue_purge_reason(struct sk_buff_head *list,
 			    enum skb_drop_reason reason)
 {
-	struct sk_buff *skb;
+	struct sk_buff_head tmp;
+	unsigned long flags;
+
+	if (skb_queue_empty_lockless(list))
+		return;
+
+	__skb_queue_head_init(&tmp);
+
+	spin_lock_irqsave(&list->lock, flags);
+	skb_queue_splice_init(list, &tmp);
+	spin_unlock_irqrestore(&list->lock, flags);
 
-	while ((skb = skb_dequeue(list)) != NULL)
-		kfree_skb_reason(skb, reason);
+	__skb_queue_purge_reason(&tmp, reason);
 }
 EXPORT_SYMBOL(skb_queue_purge_reason);
 
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 3 Oct 2023 18:19:20 +0000 you wrote:

1) Exit early if the list is empty.

2) splice the list into a local list,
so that we block hard irqs only once.

[...]

Here is the summary with links:
- [net-next] net: skb_queue_purge_reason() optimizations

    https://git.kernel.org/netdev/net-next/c/d86e5fbd4c96

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html