Skip to content

Commit d86e5fb

Browse files
edumazetkuba-moo
authored andcommitted
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. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20231003181920.3280453-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 397f70e commit d86e5fb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

net/core/skbuff.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,10 +3722,19 @@ EXPORT_SYMBOL(skb_dequeue_tail);
37223722
void skb_queue_purge_reason(struct sk_buff_head *list,
37233723
enum skb_drop_reason reason)
37243724
{
3725-
struct sk_buff *skb;
3725+
struct sk_buff_head tmp;
3726+
unsigned long flags;
3727+
3728+
if (skb_queue_empty_lockless(list))
3729+
return;
3730+
3731+
__skb_queue_head_init(&tmp);
3732+
3733+
spin_lock_irqsave(&list->lock, flags);
3734+
skb_queue_splice_init(list, &tmp);
3735+
spin_unlock_irqrestore(&list->lock, flags);
37263736

3727-
while ((skb = skb_dequeue(list)) != NULL)
3728-
kfree_skb_reason(skb, reason);
3737+
__skb_queue_purge_reason(&tmp, reason);
37293738
}
37303739
EXPORT_SYMBOL(skb_queue_purge_reason);
37313740

0 commit comments

Comments
 (0)