From: Jason Wang <jasowang@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
netdev <netdev@vger.kernel.org>,
Alexander Duyck <alexanderduyck@fb.com>,
Paolo Abeni <pabeni@redhat.com>, Greg Thelen <gthelen@google.com>,
"David S.Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
su-lifan@linux.alibaba.com, "dust.li" <dust.li@linux.alibaba.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [PATCH net] net: avoid 32 x truesize under-estimation for tiny skbs
Date: Tue, 6 Apr 2021 10:04:37 +0800 [thread overview]
Message-ID: <56eaaf7c-a9f1-c631-737a-8ec0b09d7f65@redhat.com> (raw)
In-Reply-To: <1617361253.1788838-2-xuanzhuo@linux.alibaba.com>
在 2021/4/2 下午7:00, Xuan Zhuo 写道:
> On Fri, 2 Apr 2021 10:52:12 +0800, Jason Wang <jasowang@redhat.com> wrote:
>> So I wonder something like the following like this help. We know the
>> frag size, that means, if we know there's sufficient tailroom we can use
>> build_skb() without reserving dedicated room for skb_shared_info.
>>
>> Thanks
>>
>>
> Do you mean so?
>
> I have also considered this scenario, although build_skb is not always used, but
> it is also very good for the right situation.
Something like this. Would you mind to post a formal patch to net-next
with some perf numbers?
Thanks
>
> Thanks.
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index bb4ea9dbc16b..3db207c67422 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -383,17 +383,12 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
> {
> struct sk_buff *skb;
> struct virtio_net_hdr_mrg_rxbuf *hdr;
> - unsigned int copy, hdr_len, hdr_padded_len;
> - char *p;
> + unsigned int copy, hdr_len, hdr_padded_len, shinfo_size;
> + char *p, *hdr_p;
>
> p = page_address(page) + offset;
> + hdr_p = p;
>
> - /* copy small packet so we can reuse these pages for small data */
> - skb = napi_alloc_skb(&rq->napi, GOOD_COPY_LEN);
> - if (unlikely(!skb))
> - return NULL;
> -
> - hdr = skb_vnet_hdr(skb);
>
> hdr_len = vi->hdr_len;
> if (vi->mergeable_rx_bufs)
> @@ -401,27 +396,57 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
> else
> hdr_padded_len = sizeof(struct padded_vnet_hdr);
>
> - /* hdr_valid means no XDP, so we can copy the vnet header */
> - if (hdr_valid)
> - memcpy(hdr, p, hdr_len);
> -
> len -= hdr_len;
> offset += hdr_padded_len;
> p += hdr_padded_len;
>
> - copy = len;
> - if (copy > skb_tailroom(skb))
> - copy = skb_tailroom(skb);
> - skb_put_data(skb, p, copy);
> + shinfo_size = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
> + if (truesize - len - hdr_len >= shinfo_size && len > GOOD_COPY_LEN) {
> + skb = build_skb(p, truesize);
> + if (unlikely(!skb))
> + return NULL;
> +
> + skb_put(skb, len);
> +
> + /* hdr_valid means no XDP, so we can copy the vnet header */
> + if (hdr_valid) {
> + hdr = skb_vnet_hdr(skb);
> + memcpy(hdr, hdr_p, hdr_len);
> + }
> +
> + if (metasize) {
> + __skb_pull(skb, metasize);
> + skb_metadata_set(skb, metasize);
> + }
> +
> + return skb;
> + } else {
> + /* copy small packet so we can reuse these pages for small data */
> + skb = napi_alloc_skb(&rq->napi, GOOD_COPY_LEN);
> + if (unlikely(!skb))
> + return NULL;
> +
> + copy = len;
> + if (copy > skb_tailroom(skb))
> + copy = skb_tailroom(skb);
> + skb_put_data(skb, p, copy);
> +
> + len -= copy;
> + offset += copy;
> + }
> +
> + hdr = skb_vnet_hdr(skb);
> +
> + /* hdr_valid means no XDP, so we can copy the vnet header */
> + if (hdr_valid)
> + memcpy(hdr, hdr_p, hdr_len);
>
> if (metasize) {
> __skb_pull(skb, metasize);
> skb_metadata_set(skb, metasize);
> }
>
> - len -= copy;
> - offset += copy;
> -
> if (vi->mergeable_rx_bufs) {
> if (len)
> skb_add_rx_frag(skb, 0, page, offset, len, truesize);
>
next prev parent reply other threads:[~2021-04-06 2:04 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-13 16:18 [PATCH net] net: avoid 32 x truesize under-estimation for tiny skbs Eric Dumazet
2021-01-13 18:00 ` Alexander Duyck
2021-01-13 19:19 ` Michael S. Tsirkin
2021-01-13 22:23 ` David Laight
2021-01-14 5:16 ` Eric Dumazet
2021-01-14 9:29 ` David Laight
2021-01-14 19:00 ` patchwork-bot+netdevbpf
[not found] ` <1617007696.5731978-1-xuanzhuo@linux.alibaba.com>
2021-03-29 9:06 ` Eric Dumazet
2021-03-31 8:11 ` Michael S. Tsirkin
2021-03-31 8:36 ` Eric Dumazet
2021-03-31 8:46 ` Eric Dumazet
2021-03-31 8:49 ` Eric Dumazet
2021-03-31 8:54 ` Eric Dumazet
[not found] ` <1617248264.4993114-2-xuanzhuo@linux.alibaba.com>
2021-04-01 5:06 ` Eric Dumazet
[not found] ` <1617357110.3822439-1-xuanzhuo@linux.alibaba.com>
2021-04-02 12:52 ` Eric Dumazet
2021-04-01 13:51 ` Michael S. Tsirkin
2021-04-01 14:08 ` Eric Dumazet
2021-04-01 7:14 ` Jason Wang
[not found] ` <1617267183.5697193-1-xuanzhuo@linux.alibaba.com>
2021-04-01 9:58 ` Eric Dumazet
2021-04-02 2:52 ` Jason Wang
[not found] ` <1617361253.1788838-2-xuanzhuo@linux.alibaba.com>
2021-04-02 12:53 ` Eric Dumazet
2021-04-06 2:04 ` Jason Wang [this message]
[not found] ` <1617190239.1035674-1-xuanzhuo@linux.alibaba.com>
2021-03-31 12:08 ` Eric Dumazet
2021-04-01 13:36 ` Michael S. Tsirkin
2022-09-07 20:19 ` Paolo Abeni
2022-09-07 20:40 ` Eric Dumazet
2022-09-08 10:48 ` Paolo Abeni
2022-09-08 12:20 ` Eric Dumazet
2022-09-08 14:26 ` Paolo Abeni
2022-09-08 16:00 ` Eric Dumazet
2022-09-07 21:36 ` Alexander H Duyck
2022-09-08 11:00 ` Paolo Abeni
2022-09-08 14:53 ` Alexander H Duyck
2022-09-08 18:01 ` Paolo Abeni
2022-09-08 19:26 ` Alexander Duyck
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=56eaaf7c-a9f1-c631-737a-8ec0b09d7f65@redhat.com \
--to=jasowang@redhat.com \
--cc=alexanderduyck@fb.com \
--cc=davem@davemloft.net \
--cc=dust.li@linux.alibaba.com \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=gthelen@google.com \
--cc=kuba@kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=su-lifan@linux.alibaba.com \
--cc=xuanzhuo@linux.alibaba.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).