* [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* Re: [PATCH v2] net: use bulk free in kfree_skb_list
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 8:54 ` Paolo Abeni
2 siblings, 0 replies; 8+ messages in thread
From: Jesper Dangaard Brouer @ 2019-03-24 18:23 UTC (permalink / raw)
To: Felix Fietkau; +Cc: brouer, netdev, davem, fw
On Sun, 24 Mar 2019 17:56:44 +0100
Felix Fietkau <nbd@nbd.name> 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 <nbd@nbd.name>
> ---
> v2: call kmem_cache_free_bulk once the skb array is full instead of
> falling back to kfree_skb
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] net: use bulk free in kfree_skb_list
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 8:54 ` Paolo Abeni
2 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2019-03-25 8:51 UTC (permalink / raw)
To: Felix Fietkau, netdev; +Cc: davem, brouer, fw
On 03/24/2019 09:56 AM, Felix Fietkau 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.
>
I do not believe kfree_skb_list() is used in the fast path, so do we really
need to make it so complex ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] net: use bulk free in kfree_skb_list
2019-03-25 8:51 ` Eric Dumazet
@ 2019-03-25 9:09 ` Felix Fietkau
2019-03-25 9:31 ` Eric Dumazet
0 siblings, 1 reply; 8+ messages in thread
From: Felix Fietkau @ 2019-03-25 9:09 UTC (permalink / raw)
To: Eric Dumazet, netdev; +Cc: davem, brouer, fw
On 2019-03-25 09:51, Eric Dumazet wrote:
>
>
> On 03/24/2019 09:56 AM, Felix Fietkau 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.
>>
>
> I do not believe kfree_skb_list() is used in the fast path, so do we really
> need to make it so complex ?
mac80211 uses it to free the fraglist from A-MSDU aggregated packets in
the tx status path. That's one fast path where it gets used right now
and the reason it was showing up in my perf traces.
- Felix
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] net: use bulk free in kfree_skb_list
2019-03-25 9:09 ` Felix Fietkau
@ 2019-03-25 9:31 ` Eric Dumazet
2019-03-25 9:35 ` Felix Fietkau
0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2019-03-25 9:31 UTC (permalink / raw)
To: Felix Fietkau, netdev; +Cc: davem, brouer, fw
On 03/25/2019 02:09 AM, Felix Fietkau wrote:
> On 2019-03-25 09:51, Eric Dumazet wrote:
>>
>>
>> On 03/24/2019 09:56 AM, Felix Fietkau 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.
>>>
>>
>> I do not believe kfree_skb_list() is used in the fast path, so do we really
>> need to make it so complex ?
> mac80211 uses it to free the fraglist from A-MSDU aggregated packets in
> the tx status path. That's one fast path where it gets used right now
> and the reason it was showing up in my perf traces.
This is not drop monitor friendly then....
TX completion should use consume_skb() or dev_kfree_skb()
BTW, I wonder what drop-monitor signal bulk free is sending ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] net: use bulk free in kfree_skb_list
2019-03-25 9:31 ` Eric Dumazet
@ 2019-03-25 9:35 ` Felix Fietkau
2019-03-25 16:03 ` Jesper Dangaard Brouer
0 siblings, 1 reply; 8+ messages in thread
From: Felix Fietkau @ 2019-03-25 9:35 UTC (permalink / raw)
To: Eric Dumazet, netdev; +Cc: davem, brouer, fw
On 2019-03-25 10:31, Eric Dumazet wrote:
>
>
> On 03/25/2019 02:09 AM, Felix Fietkau wrote:
>> On 2019-03-25 09:51, Eric Dumazet wrote:
>>>
>>>
>>> On 03/24/2019 09:56 AM, Felix Fietkau 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.
>>>>
>>>
>>> I do not believe kfree_skb_list() is used in the fast path, so do we really
>>> need to make it so complex ?
>> mac80211 uses it to free the fraglist from A-MSDU aggregated packets in
>> the tx status path. That's one fast path where it gets used right now
>> and the reason it was showing up in my perf traces.
>
> This is not drop monitor friendly then....
>
> TX completion should use consume_skb() or dev_kfree_skb()
>
> BTW, I wonder what drop-monitor signal bulk free is sending ?
Good point about the drop monitor. Would you prefer that I replace this
patch with one that adds a consume_skb_list function and another one
that makes mac80211 use it?
- Felix
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] net: use bulk free in kfree_skb_list
2019-03-25 9:35 ` Felix Fietkau
@ 2019-03-25 16:03 ` Jesper Dangaard Brouer
0 siblings, 0 replies; 8+ messages in thread
From: Jesper Dangaard Brouer @ 2019-03-25 16:03 UTC (permalink / raw)
To: Felix Fietkau; +Cc: Eric Dumazet, netdev, davem, fw, brouer
On Mon, 25 Mar 2019 10:35:35 +0100 Felix Fietkau <nbd@nbd.name> wrote:
> On 2019-03-25 10:31, Eric Dumazet wrote:
> > On 03/25/2019 02:09 AM, Felix Fietkau wrote:
> >> On 2019-03-25 09:51, Eric Dumazet wrote:
> >>> On 03/24/2019 09:56 AM, Felix Fietkau 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.
> >>>
> >>> I do not believe kfree_skb_list() is used in the fast path, so do
> >>> we really need to make it so complex ?
> >>
> >> mac80211 uses it to free the fraglist from A-MSDU aggregated
> >> packets in the tx status path. That's one fast path where it gets
> >> used right now and the reason it was showing up in my perf
> >> traces.
Notice that kfree_skb_list(to_free) is used in (what I consider)
"fast-path" when the qdisc system drops packets, happens via to_free in
bottom of __dev_xmit_skb(). And fq_codel (which is default in most
distro's today) have an optimization (in fq_codel_drop()) for bulk
freeing SKBs, which will also benefit from this.
Thus, I still think it will be valuable to optimize kfree_skb_list().
> > This is not drop monitor friendly then....
> >
> > TX completion should use consume_skb() or dev_kfree_skb()
> >
> > BTW, I wonder what drop-monitor signal bulk free is sending ?
>
> Good point about the drop monitor. Would you prefer that I replace
> this patch with one that adds a consume_skb_list function and another
> one that makes mac80211 use it?
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] net: use bulk free in kfree_skb_list
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 8:54 ` Paolo Abeni
2 siblings, 0 replies; 8+ messages in thread
From: Paolo Abeni @ 2019-03-25 8:54 UTC (permalink / raw)
To: Felix Fietkau, netdev; +Cc: davem, brouer, fw
Hi,
On Sun, 2019-03-24 at 17:56 +0100, Felix Fietkau 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 <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 (fclone != SKB_FCLONE_UNAVAILABLE) {
> + kfree_skb(segs);
> + continue;
> + }
I think you should swap the order of skb_unref() and the above check,
or skbs with 'fclone != SKB_FCLONE_UNAVAILABLE' will go twice in
skb_unref() (kfree_skb() calls skb_unref(), too).
Other than that LGTM,
Thanks,
Paolo
^ permalink raw reply [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).