netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: use bulk free in kfree_skb_list
@ 2019-03-24 16:56 Felix Fietkau
  2019-03-24 18:23 ` Jesper Dangaard Brouer
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Felix Fietkau @ 2019-03-24 16:56 UTC (permalink / raw)
  To: netdev; +Cc: davem, brouer, fw

Since we're freeing multiple skbs, we might as well use bulk free to save a
few cycles. Use the same conditions for bulk free as in napi_consume_skb.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
v2: call kmem_cache_free_bulk once the skb array is full instead of
    falling back to kfree_skb
 net/core/skbuff.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 2415d9cb9b89..1eeaa264d2a4 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -666,12 +666,44 @@ EXPORT_SYMBOL(kfree_skb);
 
 void kfree_skb_list(struct sk_buff *segs)
 {
-	while (segs) {
-		struct sk_buff *next = segs->next;
+	struct sk_buff *next = segs;
+	void *skbs[16];
+	int n_skbs = 0;
 
-		kfree_skb(segs);
-		segs = next;
+	while ((segs = next) != NULL) {
+		next = segs->next;
+
+		if (!skb_unref(segs))
+			continue;
+
+		if (segs->fclone != SKB_FCLONE_UNAVAILABLE) {
+			kfree_skb(segs);
+			continue;
+		}
+
+		trace_kfree_skb(segs, __builtin_return_address(0));
+
+		/* drop skb->head and call any destructors for packet */
+		skb_release_all(segs);
+
+#ifdef CONFIG_SLUB
+		/* SLUB writes into objects when freeing */
+		prefetchw(segs);
+#endif
+
+		skbs[n_skbs++] = segs;
+
+		if (n_skbs < ARRAY_SIZE(skbs))
+			continue;
+
+		kmem_cache_free_bulk(skbuff_head_cache, n_skbs, skbs);
+		n_skbs = 0;
 	}
+
+	if (!n_skbs)
+		return;
+
+	kmem_cache_free_bulk(skbuff_head_cache, n_skbs, skbs);
 }
 EXPORT_SYMBOL(kfree_skb_list);
 
-- 
2.17.0


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

end of thread, other threads:[~2019-03-25 16:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-24 16:56 [PATCH v2] net: use bulk free in kfree_skb_list Felix Fietkau
2019-03-24 18:23 ` Jesper Dangaard Brouer
2019-03-25  8:51 ` Eric Dumazet
2019-03-25  9:09   ` Felix Fietkau
2019-03-25  9:31     ` Eric Dumazet
2019-03-25  9:35       ` Felix Fietkau
2019-03-25 16:03         ` Jesper Dangaard Brouer
2019-03-25  8:54 ` Paolo Abeni

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