netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>
Cc: eugenia@mellanox.com, Alexander Duyck <alexander.duyck@gmail.com>,
	alexei.starovoitov@gmail.com, saeedm@mellanox.com,
	Jesper Dangaard Brouer <brouer@redhat.com>,
	gerlitz.or@gmail.com
Subject: [net-next PATCH 6/7] net: introduce napi_alloc_skb_hint() for more use-cases
Date: Fri, 04 Mar 2016 14:02:15 +0100	[thread overview]
Message-ID: <20160304130215.32651.87955.stgit@firesoul> (raw)
In-Reply-To: <20160304130054.32651.51776.stgit@firesoul>

The default bulk alloc size arbitrarily choosen (to be 8) might
not suit all use-cases, this introduce a function napi_alloc_skb_hint()
that allow the caller to specify a bulk size hint they are expecting.
It is a hint because __napi_alloc_skb() limits the bulk size to
the array size.

One user is the mlx5 driver, which bulk re-populate it's RX ring
with both SKBs and pages.  Thus, it would like to work with
bigger bulk alloc chunks.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
 include/linux/skbuff.h |   19 +++++++++++++++----
 net/core/skbuff.c      |    8 +++-----
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 797cefb888fb..f49077caedaf 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2393,14 +2393,25 @@ static inline void skb_free_frag(void *addr)
 	__free_page_frag(addr);
 }
 
+#define NAPI_SKB_CACHE_SIZE	64U /* Used in struct napi_alloc_cache */
+#define NAPI_SKB_BULK_ALLOC	 8U /* Default slab bulk alloc in NAPI */
+
 void *napi_alloc_frag(unsigned int fragsz);
-struct sk_buff *__napi_alloc_skb(struct napi_struct *napi,
-				 unsigned int length, gfp_t gfp_mask);
+struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
+				 unsigned int bulk_hint, gfp_t gfp_mask);
 static inline struct sk_buff *napi_alloc_skb(struct napi_struct *napi,
-					     unsigned int length)
+					     unsigned int len)
+{
+	return __napi_alloc_skb(napi, len, NAPI_SKB_BULK_ALLOC, GFP_ATOMIC);
+}
+static inline struct sk_buff *napi_alloc_skb_hint(struct napi_struct *napi,
+						  unsigned int len,
+						  unsigned int bulk_hint)
 {
-	return __napi_alloc_skb(napi, length, GFP_ATOMIC);
+	bulk_hint = bulk_hint ? : 1;
+	return __napi_alloc_skb(napi, len, bulk_hint, GFP_ATOMIC);
 }
+
 void napi_consume_skb(struct sk_buff *skb, int budget);
 
 void __kfree_skb_flush(void);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 96fb7933b614..c770bd4391ab 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -359,8 +359,6 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
 }
 EXPORT_SYMBOL(build_skb);
 
-#define NAPI_SKB_CACHE_SIZE	64
-
 struct napi_alloc_cache {
 	struct page_frag_cache page;
 	size_t skb_count;
@@ -492,9 +490,10 @@ EXPORT_SYMBOL(__netdev_alloc_skb);
  *	%NULL is returned if there is no free memory.
  */
 struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
-				 gfp_t gfp_mask)
+				 unsigned int bulk_hint, gfp_t gfp_mask)
 {
 	struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
+	unsigned int bulk_sz = min(bulk_hint, NAPI_SKB_CACHE_SIZE);
 	struct sk_buff *skb;
 	void *data;
 
@@ -518,10 +517,9 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
 	if (unlikely(!data))
 		return NULL;
 
-#define BULK_ALLOC_SIZE 8
 	if (!nc->skb_count) {
 		nc->skb_count = kmem_cache_alloc_bulk(skbuff_head_cache,
-						      gfp_mask, BULK_ALLOC_SIZE,
+						      gfp_mask, bulk_sz,
 						      nc->skb_cache);
 	}
 	if (likely(nc->skb_count)) {

  parent reply	other threads:[~2016-03-04 13:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04 13:01 [net-next PATCH 0/7] net: bulk alloc side and more bulk free drivers Jesper Dangaard Brouer
2016-03-04 13:01 ` [net-next PATCH 1/7] mlx5: use napi_consume_skb API to get bulk free operations Jesper Dangaard Brouer
2016-03-04 13:01 ` [net-next PATCH 2/7] mlx4: " Jesper Dangaard Brouer
2016-03-08 19:24   ` David Miller
2016-03-09 11:00     ` Jesper Dangaard Brouer
2016-03-09 16:47       ` Alexander Duyck
2016-03-09 21:03         ` David Miller
2016-03-09 21:36           ` Jesper Dangaard Brouer
2016-03-09 21:43             ` Alexander Duyck
2016-03-09 21:47               ` Jesper Dangaard Brouer
2016-03-09 22:07                 ` Alexander Duyck
2016-03-10 12:15                   ` [net-next PATCH V2 0/3] net: bulk free adjustment and two driver use-cases Jesper Dangaard Brouer
2016-03-10 12:15                     ` [net-next PATCH V2 1/3] net: adjust napi_consume_skb to handle none-NAPI callers Jesper Dangaard Brouer
2016-03-10 12:15                     ` [net-next PATCH V2 2/3] mlx4: use napi_consume_skb API to get bulk free operations Jesper Dangaard Brouer
2016-03-10 13:59                       ` Sergei Shtylyov
2016-03-10 14:59                         ` [net-next PATCH V3 0/3] net: bulk free adjustment and two driver use-cases Jesper Dangaard Brouer
2016-03-10 14:59                           ` [net-next PATCH V3 1/3] net: adjust napi_consume_skb to handle none-NAPI callers Jesper Dangaard Brouer
2016-03-10 17:21                             ` Sergei Shtylyov
2016-03-11  7:45                               ` Jesper Dangaard Brouer
2016-03-11  8:43                                 ` [net-next PATCH V4 0/3] net: bulk free adjustment and two driver use-cases Jesper Dangaard Brouer
2016-03-11  8:43                                   ` [net-next PATCH V4 1/3] net: adjust napi_consume_skb to handle non-NAPI callers Jesper Dangaard Brouer
2016-03-11  8:44                                   ` [net-next PATCH V4 2/3] mlx4: use napi_consume_skb API to get bulk free operations Jesper Dangaard Brouer
2016-03-11  8:44                                   ` [net-next PATCH V4 3/3] mlx5: " Jesper Dangaard Brouer
2016-03-14  2:35                                   ` [net-next PATCH V4 0/3] net: bulk free adjustment and two driver use-cases David Miller
2016-03-10 14:59                           ` [net-next PATCH V3 2/3] mlx4: use napi_consume_skb API to get bulk free operations Jesper Dangaard Brouer
2016-03-10 14:59                           ` [net-next PATCH V3 3/3] mlx5: " Jesper Dangaard Brouer
2016-03-10 12:15                     ` [net-next PATCH V2 " Jesper Dangaard Brouer
2016-03-04 13:01 ` [net-next PATCH 3/7] net: bulk alloc and reuse of SKBs in NAPI context Jesper Dangaard Brouer
2016-03-13 14:06   ` Rana Shahout
2016-03-14  6:55     ` Jesper Dangaard Brouer
2016-03-04 13:01 ` [net-next PATCH 4/7] mlx5: use napi_alloc_skb API to get SKB bulk allocations Jesper Dangaard Brouer
2016-03-04 13:02 ` [net-next PATCH 5/7] mlx4: " Jesper Dangaard Brouer
2016-03-04 13:02 ` Jesper Dangaard Brouer [this message]
2016-03-04 13:02 ` [net-next PATCH 7/7] mlx5: hint the NAPI alloc skb API about the expected bulk size Jesper Dangaard Brouer
2016-03-04 16:36 ` [net-next PATCH 0/7] net: bulk alloc side and more bulk free drivers Alexei Starovoitov
2016-03-04 19:15   ` Jesper Dangaard Brouer

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=20160304130215.32651.87955.stgit@firesoul \
    --to=brouer@redhat.com \
    --cc=alexander.duyck@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=davem@davemloft.net \
    --cc=eugenia@mellanox.com \
    --cc=gerlitz.or@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.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;
as well as URLs for NNTP newsgroup(s).