From: Eric Dumazet <eric.dumazet@gmail.com>
To: Thomas Graf <tgraf@suug.ch>
Cc: netdev@vger.kernel.org, jesse@nicira.com, dev@openvswitch.org
Subject: Re: [PATCH net-next 1/2] net: Export skb_zerocopy() to zerocopy from one skb to another
Date: Fri, 24 May 2013 08:31:56 -0700 [thread overview]
Message-ID: <1369409516.3301.407.camel@edumazet-glaptop> (raw)
In-Reply-To: <d209be514b6eff718e0b6562da289faadd014806.1369406826.git.tgraf@suug.ch>
On Fri, 2013-05-24 at 16:52 +0200, Thomas Graf wrote:
> Make the skb zerocopy logic written for nfnetlink queue available for
> use by other modules.
>
> Signed-off-by: Thomas Graf <tgraf@suug.ch>
> ---
> include/linux/skbuff.h | 2 ++
> net/core/skbuff.c | 46 +++++++++++++++++++++++++++++++++++
> net/netfilter/nfnetlink_queue_core.c | 47 +-----------------------------------
> 3 files changed, 49 insertions(+), 46 deletions(-)
>
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 2e0ced1..ff2cbe8 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -2478,6 +2478,8 @@ extern int skb_splice_bits(struct sk_buff *skb,
> unsigned int len,
> unsigned int flags);
> extern void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
> +extern void skb_zerocopy(struct sk_buff *to, const struct sk_buff *from,
> + int len, int hlen);
> extern void skb_split(struct sk_buff *skb,
> struct sk_buff *skb1, const u32 len);
> extern int skb_shift(struct sk_buff *tgt, struct sk_buff *skb,
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index d629891..cb60bf6 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -2118,6 +2118,52 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)
> }
> EXPORT_SYMBOL(skb_copy_and_csum_dev);
>
> +void
> +skb_zerocopy(struct sk_buff *to, const struct sk_buff *from, int len, int hlen)
> +{
> + int i, j = 0;
> + int plen = 0; /* length of skb->head fragment */
> + struct page *page;
> + unsigned int offset;
> +
> + /* dont bother with small payloads */
> + if (len <= skb_tailroom(to)) {
> + skb_copy_bits(from, 0, skb_put(to, len), len);
> + return;
> + }
> +
> + if (hlen) {
> + skb_copy_bits(from, 0, skb_put(to, hlen), hlen);
> + len -= hlen;
> + } else {
> + plen = min_t(int, skb_headlen(from), len);
> + if (plen) {
> + page = virt_to_head_page(from->head);
Hmm. Big warning here : In the nfnetlink case, we specifically made sure
that this path was taken only if skb->head_frag was set (all incoming
packets have this property, but not outgoing ones yet)
This should be documented if we move it to net/core/skbuff.c, or we
should add a BUG_ON()
I see your openvswitch code seems OK.
Maybe also put in net/core/skbuff.c the code dealing with this stuff ?
+ if (!skb->head_frag ||
+ skb_headlen(skb) < L1_CACHE_BYTES ||
+ skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)
+ hlen = skb_headlen(skb);
+
+ if (skb_has_frag_list(skb))
+ hlen = skb->len;
> + offset = from->data - (unsigned char *)page_address(page);
> + __skb_fill_page_desc(to, 0, page, offset, plen);
> + get_page(page);
> + j = 1;
> + len -= plen;
> + }
> + }
next prev parent reply other threads:[~2013-05-24 15:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-24 14:52 [PATCH net-next 0/2] Open vSwitch zerocopy upcall Thomas Graf
2013-05-24 14:52 ` [PATCH net-next 1/2] net: Export skb_zerocopy() to zerocopy from one skb to another Thomas Graf
2013-05-24 15:31 ` Eric Dumazet [this message]
2013-05-24 16:01 ` Thomas Graf
2013-05-24 14:52 ` [PATCH net-next 2/2] openvswitch: Use zerocopy if applicable when performing the upcall Thomas Graf
2013-05-24 17:24 ` Jesse Gross
2013-05-24 18:58 ` Eric Dumazet
2013-05-24 21:23 ` Jesse Gross
2013-05-24 21:57 ` Eric Dumazet
2013-05-24 22:18 ` Jesse Gross
2013-05-24 22:34 ` Eric Dumazet
2013-05-25 0:08 ` Jesse Gross
2013-05-25 0:32 ` Eric Dumazet
2013-05-25 7:02 ` Thomas Graf
2013-05-25 14:39 ` Eric Dumazet
2013-05-27 1:28 ` Jesse Gross
2013-06-07 12:21 ` Thomas Graf
2013-06-10 20:34 ` Jesse Gross
2013-06-10 20:43 ` David Miller
2013-06-10 20:55 ` Jesse Gross
2013-07-25 12:43 [PATCH net-next 0/2 v2] Open vSwitch zerocopy upcall Thomas Graf
2013-07-25 12:43 ` [PATCH net-next 1/2] net: Export skb_zerocopy() to zerocopy from one skb to another Thomas Graf
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=1369409516.3301.407.camel@edumazet-glaptop \
--to=eric.dumazet@gmail.com \
--cc=dev@openvswitch.org \
--cc=jesse@nicira.com \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
/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).