From: David Miller <davem@davemloft.net>
To: eric.dumazet@gmail.com
Cc: prashant@broadcom.com, bpoirier@suse.de, mchan@broadcom.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v6 4/4] tg3: Fix tx_pending checks for tg3_tso_bug
Date: Fri, 05 Sep 2014 21:39:02 -0700 (PDT) [thread overview]
Message-ID: <20140905.213902.1124686922505260665.davem@davemloft.net> (raw)
In-Reply-To: <20140905.171306.1460013939580748402.davem@davemloft.net>
From: David Miller <davem@davemloft.net>
Date: Fri, 05 Sep 2014 17:13:06 -0700 (PDT)
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Fri, 05 Sep 2014 17:03:30 -0700
>
>> Instead of this private helper (and pretty limited one btw), we could
>> add a core function, that would build skbs with order-0 fragments.
>>
>> Instead of skb_linearize(), I guess many call sites could instead use
>> this new helper.
>>
>> Because as you said, skb_linearize() of one 64KB GSO packet can ask
>> order-5 allocations, and this generally does not work reliably.
>
> xen-netback could make use of this helper too.
I was curious what it might look like so I cobbled the following
completely untested patch together :-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index da1378a..eba0ad6 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -955,6 +955,67 @@ struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
EXPORT_SYMBOL(skb_copy);
/**
+ * skb_copy_pskb - copy sk_buff into a paged skb
+ * @oskb: buffer to copy
+ * @gfp_mask: allocation priority
+ *
+ * Normalize a paged skb into one that maximally uses order
+ * zero pages in it's fragment array. This is used to canonicalize
+ * spaghetti SKBs that use the page array inefficiently (f.e. only
+ * one byte per page frag).
+ */
+
+struct sk_buff *skb_copy_pskb(const struct sk_buff *oskb, gfp_t gfp_mask)
+{
+ unsigned int data_len = oskb->data_len;
+ int offset, npages, i;
+ struct sk_buff *skb;
+
+ npages = (data_len + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
+ if (npages > MAX_SKB_FRAGS)
+ return NULL;
+
+ skb = __alloc_skb(skb_end_offset(oskb), gfp_mask,
+ skb_alloc_rx_flag(oskb), NUMA_NO_NODE);
+ if (!skb)
+ return NULL;
+
+ skb_reserve(skb, skb_headroom(oskb));
+ skb_put(skb, skb_headlen(oskb));
+ skb_copy_from_linear_data(oskb, skb->data, skb->len);
+
+ copy_skb_header(skb, oskb);
+
+ skb->truesize += data_len;
+ offset = skb_headlen(oskb);
+ for (i = 0; i < npages; i++) {
+ struct page *page = alloc_page(gfp_mask);
+ unsigned int chunk;
+ u8 *vaddr;
+
+ if (!page) {
+ kfree(skb);
+ skb = NULL;
+ break;
+ }
+
+ chunk = min_t(unsigned int, data_len, PAGE_SIZE);
+ skb_fill_page_desc(skb, i, page, 0, chunk);
+
+ vaddr = kmap_atomic(page);
+ skb_copy_bits(oskb, offset, vaddr, chunk);
+ kunmap_atomic(vaddr);
+
+ offset += chunk;
+ data_len -= chunk;
+ skb->data_len += chunk;
+ }
+
+ return skb;
+}
+EXPORT_SYMBOL(skb_copy_pskb);
+
+/**
* __pskb_copy_fclone - create copy of an sk_buff with private head.
* @skb: buffer to copy
* @headroom: headroom of new skb
next prev parent reply other threads:[~2014-09-06 4:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-05 1:30 [PATCH net v6 0/4] tg3: tx_pending fixes Benjamin Poirier
2014-09-05 1:30 ` [PATCH net v6 1/4] tg3: Limit minimum tx queue wakeup threshold Benjamin Poirier
2014-09-05 1:30 ` [PATCH net v6 2/4] tg3: Fix tx_pending check for MAX_SKB_FRAGS Benjamin Poirier
2014-09-05 1:30 ` [PATCH net v6 3/4] tg3: Move tx queue stop logic to its own function Benjamin Poirier
2014-09-05 1:30 ` [PATCH net v6 4/4] tg3: Fix tx_pending checks for tg3_tso_bug Benjamin Poirier
2014-09-05 23:35 ` Prashant Sreedharan
2014-09-06 0:03 ` Eric Dumazet
2014-09-06 0:13 ` David Miller
2014-09-06 4:39 ` David Miller [this message]
2014-10-01 3:14 ` Prashant
2014-10-01 4:24 ` Eric Dumazet
2014-10-01 18:29 ` Prashant
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=20140905.213902.1124686922505260665.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=bpoirier@suse.de \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mchan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=prashant@broadcom.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
all inboxes | Powered by JetHome®