net: use bulk free in kfree_skb_list
Subsystems (2)
PATCH 1/1 net: use bulk free in kfree_skb_list
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.
--- net/core/skbuff.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-)
net/core/skbuff.c +31 -4
@@ -666,12 +666,39 @@ 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 || + n_skbs >=ARRAY_SIZE (skbs)) { +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) +return ; + +kmem_cache_free_bulk (skbuff_head_cache, n_skbs, skbs); }EXPORT_SYMBOL (kfree_skb_list);
Signature · 1 line
2.17.0
Quoted 4 lines · On Sun, 24 Mar 2019 07:58:34 +0100 Felix Fietkau <[email protected]> wrote:
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 <[email protected]>
Thanks for working on this, it's been on my todo list for a very long time. I just discussed this with Florian at NetDevconf.
Quoted 18 lines
--- net/core/skbuff.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-)net/core/skbuff.c +3
-2@@ -666,12 +666,39 @@ 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 ;
net/core/skbuff.c EXPORT_SYMBOL(kfree_skb); · line 680
Quoted 10 lines
net/core/skbuff.c +8
-2-kfree_skb (segs); - segs = next; +while ((segs = next) !=NULL ) { + next = segs->next; + +if (!skb_unref (segs)) +continue ; + +if (segs->fclone !=SKB_FCLONE_UNAVAILABLE || + n_skbs >=ARRAY_SIZE (skbs)) {
You could call kmem_cache_free_bulk() here and reset n_skbs=0.
Quoted 24 lines
net/core/skbuff.c +20
-0+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) +return ; + +kmem_cache_free_bulk (skbuff_head_cache, n_skbs, skbs); }EXPORT_SYMBOL (kfree_skb_list);
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 10 lines · Jesper Dangaard Brouer
Quoted 4 lines · On Sun, 24 Mar 2019 07:58:34 +0100 Felix Fietkau <[email protected]> wrote:
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 <[email protected]>Thanks for working on this, it's been on my todo list for a very long time. I just discussed this with Florian at NetDevconf.
No problem. It was showing up on my perf traces while improving mac80211/mt76 performance, so I decided to deal with it now :)
Quoted 14 lines
Quoted 14 lines
net/core/skbuff.c +3
-2@@ -666,12 +666,39 @@ 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 ;
Quoted 12 lines
net/core/skbuff.c EXPORT_SYMBOL(kfree_skb); · line 680
Quoted 10 lines
net/core/skbuff.c +8
-2-kfree_skb (segs); - segs = next; +while ((segs = next) !=NULL ) { + next = segs->next; + +if (!skb_unref (segs)) +continue ; + +if (segs->fclone !=SKB_FCLONE_UNAVAILABLE || + n_skbs >=ARRAY_SIZE (skbs)) {You could call
kmem_cache_free_bulk()here and reset n_skbs=0.
Sure, good idea. I'll send v2 shortly.
- Felix