All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next-2.6] net: introduce build_skb()
Date: Mon, 11 Jul 2011 07:46:46 +0200	[thread overview]
Message-ID: <1310363206.2512.26.camel@edumazet-laptop> (raw)
In-Reply-To: <ae7b531c89a01a21e4374907b69f4d997c9d5d1b.1310339688.git.mirq-linux@rere.qmqm.pl>

Le lundi 11 juillet 2011 à 02:52 +0200, Michał Mirosław a écrit :
> Introduce __netdev_alloc_skb_aligned() to return skb with skb->data
> aligned at specified 2^n multiple.
> 
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---

Hi Michal


Could we synchronize our work to not introduce things that might
disappear shortly ?

Here is the RFC patch about build_skb() :

[PATCH] net: introduce build_skb()

One of the thing we discussed during netdev 2011 conference was the idea
to change network drivers to allocate/populate their skb at RX
completion time, right before feeding the skb to network stack.

Right now, we allocate skbs when populating the RX ring, and thats a
waste of CPU cache, since allocating skb means a full memset() to clear
the skb and its skb_shared_info portion. By the time NIC fills a frame
in data buffer and host can get it, cpu probably threw away the cache
lines from its caches, because of huge RX ring sizes.

So the deal would be to allocate only the data buffer for the NIC to
populate its RX ring buffer. And use build_skb() at RX completion to
attach a data buffer (now filled with an ethernet frame) to a new skb,
initialize the skb_shared_info portion, and give the hot skb to network
stack.

build_skb() is the function to allocate an skb, caller providing the
data buffer that should be attached to it. Drivers are expected to call 
skb_reserve() right after build_skb() to let skb->data points to the
Ethernet frame (usually skipping NET_SKB_PAD and NET_IP_ALIGN)


Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 include/linux/skbuff.h |    1 
 net/core/skbuff.c      |   48 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 32ada53..5e903e7 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -507,6 +507,7 @@ static inline struct rtable *skb_rtable(const struct sk_buff *skb)
 extern void kfree_skb(struct sk_buff *skb);
 extern void consume_skb(struct sk_buff *skb);
 extern void	       __kfree_skb(struct sk_buff *skb);
+extern struct sk_buff *build_skb(void *data, unsigned int size);
 extern struct sk_buff *__alloc_skb(unsigned int size,
 				   gfp_t priority, int fclone, int node);
 static inline struct sk_buff *alloc_skb(unsigned int size,
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index d220119..9193d7e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -234,6 +234,54 @@ nodata:
 EXPORT_SYMBOL(__alloc_skb);
 
 /**
+ * build_skb - build a network buffer
+ * @data: data buffer provider by caller
+ * @size: size of data buffer, not including skb_shared_info
+ *
+ * Allocate a new &sk_buff. Caller provides space holding head and
+ * skb_shared_info. Mostly used in driver RX path.
+ * The return is the buffer. On a failure the return is %NULL.
+ * Notes :
+ *  Before IO, driver allocates only data buffer where NIC put incoming frame
+ *  Driver SHOULD add room at head (NET_SKB_PAD) and
+ *  MUST add room tail (to hold skb_shared_info)
+ *  After IO, driver calls build_skb(), to get a hot skb instead of a cold one
+ *  before giving packet to stack. RX rings only contains data buffers, not
+ *  full skbs.
+ */
+struct sk_buff *build_skb(void *data, unsigned int size)
+{
+	struct skb_shared_info *shinfo;
+	struct sk_buff *skb;
+
+	skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC);
+	if (!skb)
+		return NULL;
+
+	size = SKB_DATA_ALIGN(size);
+
+	memset(skb, 0, offsetof(struct sk_buff, tail));
+	skb->truesize = size + sizeof(struct sk_buff);
+	atomic_set(&skb->users, 1);
+	skb->head = data;
+	skb->data = data;
+	skb_reset_tail_pointer(skb);
+	skb->end = skb->tail + size;
+#ifdef NET_SKBUFF_DATA_USES_OFFSET
+	skb->mac_header = ~0U;
+#endif
+
+	/* make sure we initialize shinfo sequentially */
+	shinfo = skb_shinfo(skb);
+	memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
+	atomic_set(&shinfo->dataref, 1);
+	kmemcheck_annotate_variable(shinfo->destructor_arg);
+
+	return skb;
+}
+EXPORT_SYMBOL(build_skb);
+
+/**
  *	__netdev_alloc_skb - allocate an skbuff for rx on a specific device
  *	@dev: network device to receive on
  *	@length: length to allocate



  reply	other threads:[~2011-07-11  5:46 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-11  0:52 [PATCH v2 00/46] Clean up RX copybreak and DMA handling Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 02/46] net: wrap common patterns of rx handler code Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 05/46] net: bnx2x: fix DMA sync direction Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 06/46] net/tokenring: 3c359: fix DMA API usage Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 01/46] net: introduce __netdev_alloc_skb_aligned() Michał Mirosław
2011-07-11  5:46   ` Eric Dumazet [this message]
2011-07-11 10:53     ` [PATCH net-next-2.6] net: introduce build_skb() Michał Mirosław
2011-07-12 15:40     ` Eric Dumazet
2011-07-12 15:54       ` Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 03/46] net drivers: remove unnecessary dma_sync_to_device(DMA_FROM_DEVICE) Michał Mirosław
2011-07-11  8:30   ` Vlad Zolotarov
2011-07-11  9:29     ` Michał Mirosław
2011-07-11  9:46       ` Vlad Zolotarov
2011-07-11  0:52 ` [PATCH v2 04/46] net/wireless: p54: remove useless dma_sync_single_for_device(DMA_FROM_DEVICE) Michał Mirosław
2011-07-11 15:15   ` Pavel Roskin
2011-07-11 15:15     ` Pavel Roskin
2011-07-12  4:50   ` Felix Fietkau
2011-07-12  4:50     ` Felix Fietkau
2011-07-11  0:52 ` [PATCH v2 07/46] net/wireless: ath9k: fix DMA API usage Michał Mirosław
2011-07-11  0:52   ` [ath9k-devel] " Michał Mirosław
2011-07-11  0:52   ` Michał Mirosław
2011-07-12  4:36   ` [ath9k-devel] " Felix Fietkau
2011-07-12  4:36     ` Felix Fietkau
2011-07-12  4:36     ` Felix Fietkau
2011-07-12  5:30     ` [ath9k-devel] " Ben Greear
2011-07-12  5:30       ` Ben Greear
2011-07-12  5:30       ` Ben Greear
2011-07-12  9:55     ` Michał Mirosław
2011-07-12  9:55       ` Michał Mirosław
2011-07-12  9:55       ` Michał Mirosław
2011-07-12 12:54       ` Felix Fietkau
2011-07-12 12:54         ` Felix Fietkau
2011-07-12 12:54         ` Felix Fietkau
2011-07-12 13:03         ` [ath9k-devel] " Michał Mirosław
2011-07-12 13:03           ` Michał Mirosław
2011-07-12 13:03           ` Michał Mirosław
2011-07-12 14:21           ` Felix Fietkau
2011-07-12 14:21             ` Felix Fietkau
2011-07-12 14:21             ` Felix Fietkau
2011-07-12 15:58             ` Michał Mirosław
2011-07-12 15:58               ` Michał Mirosław
2011-07-12 16:04               ` Felix Fietkau
2011-07-12 16:04                 ` Felix Fietkau
2011-07-12 16:04                 ` Felix Fietkau
2011-07-12 19:13                 ` Michał Mirosław
2011-07-12 19:13                   ` Michał Mirosław
2011-07-12 19:32     ` Ralf Baechle
2011-07-12 19:32       ` Ralf Baechle
2011-07-12 20:53       ` Michał Mirosław
2011-07-12 20:53         ` Michał Mirosław
2011-07-12 20:53         ` Michał Mirosław
2011-07-12 20:59         ` Michał Mirosław
2011-07-12 20:59           ` Michał Mirosław
2011-07-12 20:59           ` Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 08/46] net/wireless: b43: fix DMA direction for RX buffers Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 09/46] net: octeon_mgmt: fix DMA unmap size Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 10/46] net: jme: convert to generic DMA API Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 12/46] net: sunhme: cleanup RX skb allocation Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 13/46] net: sunbmac: " Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 11/46] net: sungem: " Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 16/46] net: cxgb3: don't drop packets on memory pressure in driver Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 14/46] net: sunbmac: cleanup magic '34' Michał Mirosław
2011-07-11  0:52 ` [PATCH v2 46/46] net: mark drivers that drop packets from rx queue head under memory pressure Michał Mirosław
2011-07-11  5:40   ` Francois Romieu
2011-07-11  6:47   ` Eilon Greenstein
2011-07-11 10:04     ` Michał Mirosław
2011-07-11 10:16       ` Eilon Greenstein
2011-07-11 15:24   ` Stephen Hemminger
2011-07-11  0:52 ` [PATCH v2 15/46] net/wireless: b43: use kfree_skb() for untouched skbs Michał Mirosław
2011-07-11  6:54 ` [PATCH v2 00/46] Clean up RX copybreak and DMA handling David Miller
2011-07-11  9:16   ` Michał Mirosław
2011-07-11  9:24     ` David Miller
2011-07-11  9:47       ` Michał Mirosław
2011-07-11 10:11         ` David Miller
2011-07-11 11:17           ` Michał Mirosław
2011-07-11 12:36   ` Ben Hutchings

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=1310363206.2512.26.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.