From: Tom Herbert <tom@herbertland.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
akpm@linux-foundation.org, linux-mm@kvack.org,
aravinda@linux.vnet.ibm.com, Christoph Lameter <cl@linux.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
iamjoonsoo.kim@lge.com
Subject: Re: [RFC PATCH 1/3] net: introduce kfree_skb_bulk() user of kmem_cache_free_bulk()
Date: Fri, 4 Sep 2015 11:47:17 -0700 [thread overview]
Message-ID: <CALx6S36R2zGwj5XF0GZWPOC1Ng5HviPWxBM-cn=DDMXU9Auoxg@mail.gmail.com> (raw)
In-Reply-To: <20150904170046.4312.38018.stgit@devil>
On Fri, Sep 4, 2015 at 10:00 AM, Jesper Dangaard Brouer
<brouer@redhat.com> wrote:
> Introduce the first user of SLAB bulk free API kmem_cache_free_bulk(),
> in the network stack in form of function kfree_skb_bulk() which bulk
> free SKBs (not skb clones or skb->head, yet).
>
> As this is the third user of SKB reference decrementing, split out
> refcnt decrement into helper function and use this in all call points.
>
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> ---
> include/linux/skbuff.h | 1 +
> net/core/skbuff.c | 87 +++++++++++++++++++++++++++++++++++++++---------
> 2 files changed, 71 insertions(+), 17 deletions(-)
>
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index b97597970ce7..e5f1e007723b 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -762,6 +762,7 @@ static inline struct rtable *skb_rtable(const struct sk_buff *skb)
> }
>
> void kfree_skb(struct sk_buff *skb);
> +void kfree_skb_bulk(struct sk_buff **skbs, unsigned int size);
> void kfree_skb_list(struct sk_buff *segs);
> void skb_tx_error(struct sk_buff *skb);
> void consume_skb(struct sk_buff *skb);
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 429b407b4fe6..034545934158 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -661,26 +661,83 @@ void __kfree_skb(struct sk_buff *skb)
> }
> EXPORT_SYMBOL(__kfree_skb);
>
> +/*
> + * skb_dec_and_test - Helper to drop ref to SKB and see is ready to free
> + * @skb: buffer to decrement reference
> + *
> + * Drop a reference to the buffer, and return true if it is ready
> + * to free. Which is if the usage count has hit zero or is equal to 1.
> + *
> + * This is performance critical code that should be inlined.
> + */
> +static inline bool skb_dec_and_test(struct sk_buff *skb)
> +{
> + if (unlikely(!skb))
> + return false;
> + if (likely(atomic_read(&skb->users) == 1))
> + smp_rmb();
> + else if (likely(!atomic_dec_and_test(&skb->users)))
> + return false;
> + /* If reaching here SKB is ready to free */
> + return true;
> +}
> +
> /**
> * kfree_skb - free an sk_buff
> * @skb: buffer to free
> *
> * Drop a reference to the buffer and free it if the usage count has
> - * hit zero.
> + * hit zero or is equal to 1.
> */
> void kfree_skb(struct sk_buff *skb)
> {
> - if (unlikely(!skb))
> - return;
> - if (likely(atomic_read(&skb->users) == 1))
> - smp_rmb();
> - else if (likely(!atomic_dec_and_test(&skb->users)))
> - return;
> - trace_kfree_skb(skb, __builtin_return_address(0));
> - __kfree_skb(skb);
> + if (skb_dec_and_test(skb)) {
> + trace_kfree_skb(skb, __builtin_return_address(0));
> + __kfree_skb(skb);
> + }
> }
> EXPORT_SYMBOL(kfree_skb);
>
> +/**
> + * kfree_skb_bulk - bulk free SKBs when refcnt allows to
> + * @skbs: array of SKBs to free
> + * @size: number of SKBs in array
> + *
> + * If SKB refcnt allows for free, then release any auxiliary data
> + * and then bulk free SKBs to the SLAB allocator.
> + *
> + * Note that interrupts must be enabled when calling this function.
> + */
> +void kfree_skb_bulk(struct sk_buff **skbs, unsigned int size)
> +{
What not pass a list of skbs (e.g. using skb->next)?
> + int i;
> + size_t cnt = 0;
> +
> + for (i = 0; i < size; i++) {
> + struct sk_buff *skb = skbs[i];
> +
> + if (!skb_dec_and_test(skb))
> + continue; /* skip skb, not ready to free */
> +
> + /* Construct an array of SKBs, ready to be free'ed and
> + * cleanup all auxiliary, before bulk free to SLAB.
> + * For now, only handle non-cloned SKBs, related to
> + * SLAB skbuff_head_cache
> + */
> + if (skb->fclone == SKB_FCLONE_UNAVAILABLE) {
> + skb_release_all(skb);
> + skbs[cnt++] = skb;
> + } else {
> + /* SKB was a clone, don't handle this case */
> + __kfree_skb(skb);
> + }
> + }
> + if (likely(cnt)) {
> + kmem_cache_free_bulk(skbuff_head_cache, cnt, (void **) skbs);
> + }
> +}
> +EXPORT_SYMBOL(kfree_skb_bulk);
> +
> void kfree_skb_list(struct sk_buff *segs)
> {
> while (segs) {
> @@ -722,14 +779,10 @@ EXPORT_SYMBOL(skb_tx_error);
> */
> void consume_skb(struct sk_buff *skb)
> {
> - if (unlikely(!skb))
> - return;
> - if (likely(atomic_read(&skb->users) == 1))
> - smp_rmb();
> - else if (likely(!atomic_dec_and_test(&skb->users)))
> - return;
> - trace_consume_skb(skb);
> - __kfree_skb(skb);
> + if (skb_dec_and_test(skb)) {
> + trace_consume_skb(skb);
> + __kfree_skb(skb);
> + }
> }
> EXPORT_SYMBOL(consume_skb);
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-09-04 18:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-24 0:58 [PATCH V2 0/3] slub: introducing detached freelist Jesper Dangaard Brouer
2015-08-24 0:58 ` [PATCH V2 1/3] slub: extend slowpath __slab_free() to handle bulk free Jesper Dangaard Brouer
2015-08-24 0:59 ` [PATCH V2 2/3] slub: optimize bulk slowpath free by detached freelist Jesper Dangaard Brouer
2015-08-24 0:59 ` [PATCH V2 3/3] slub: build detached freelist with look-ahead Jesper Dangaard Brouer
2015-09-04 17:00 ` [RFC PATCH 0/3] Network stack, first user of SLAB/kmem_cache bulk free API Jesper Dangaard Brouer
2015-09-04 17:00 ` [RFC PATCH 1/3] net: introduce kfree_skb_bulk() user of kmem_cache_free_bulk() Jesper Dangaard Brouer
2015-09-04 18:47 ` Tom Herbert [this message]
2015-09-07 8:41 ` Jesper Dangaard Brouer
2015-09-07 16:25 ` Tom Herbert
2015-09-07 20:14 ` Jesper Dangaard Brouer
2015-09-08 21:01 ` David Miller
2015-09-04 17:01 ` [RFC PATCH 2/3] net: NIC helper API for building array of skbs to free Jesper Dangaard Brouer
2015-09-04 17:01 ` [RFC PATCH 3/3] ixgbe: bulk free SKBs during TX completion cleanup cycle Jesper Dangaard Brouer
2015-09-04 18:09 ` [RFC PATCH 0/3] Network stack, first user of SLAB/kmem_cache bulk free API Alexander Duyck
2015-09-04 18:55 ` Christoph Lameter
2015-09-04 20:39 ` Alexander Duyck
2015-09-04 23:45 ` Christoph Lameter
2015-09-05 11:18 ` Jesper Dangaard Brouer
2015-09-08 17:32 ` Christoph Lameter
2015-09-09 12:59 ` Jesper Dangaard Brouer
2015-09-09 14:08 ` Christoph Lameter
2015-09-07 8:16 ` Jesper Dangaard Brouer
2015-09-07 21:23 ` Alexander Duyck
2015-09-16 10:02 ` Experiences with slub bulk use-case for network stack Jesper Dangaard Brouer
2015-09-16 15:13 ` Christoph Lameter
2015-09-17 20:17 ` Jesper Dangaard Brouer
2015-09-17 23:57 ` Christoph Lameter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALx6S36R2zGwj5XF0GZWPOC1Ng5HviPWxBM-cn=DDMXU9Auoxg@mail.gmail.com' \
--to=tom@herbertland.com \
--cc=akpm@linux-foundation.org \
--cc=aravinda@linux.vnet.ibm.com \
--cc=brouer@redhat.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox