From: Gavin Li <gavinl@nvidia.com>
To: Si-Wei Liu <si-wei.liu@oracle.com>,
mst@redhat.com, stephen@networkplumber.org, davem@davemloft.net,
virtualization@lists.linux-foundation.org,
virtio-dev@lists.oasis-open.org, jesse.brandeburg@intel.com,
alexander.h.duyck@intel.com, kubakici@wp.pl,
sridhar.samudrala@intel.com, jasowang@redhat.com,
loseweigh@gmail.com
Cc: parav@nvidia.com, gavi@nvidia.com
Subject: Re: [virtio-dev] [PATCH] virtio-net: use mtu size as buffer length for big packets
Date: Mon, 8 Aug 2022 15:34:18 +0800 [thread overview]
Message-ID: <d696fa2d-a198-5481-aefd-1727cdab5c32@nvidia.com> (raw)
In-Reply-To: <62682efb-f5ed-65de-d209-566738479025@oracle.com>
On 8/6/2022 7:26 AM, Si-Wei Liu wrote:
> External email: Use caution opening links or attachments
>
>
> On 8/5/2022 3:11 PM, Si-Wei Liu wrote:
>>
>>
>> On 8/1/2022 9:45 PM, Gavin Li wrote:
>>> Currently add_recvbuf_big() allocates MAX_SKB_FRAGS segments for big
>>> packets even when GUEST_* offloads are not present on the device.
>>> However, if GSO is not supported,
>> GUEST GSO (virtio term), or GRO HW (netdev core term) it should have
>> been be called.
>>
>>> it would be sufficient to allocate
>>> segments to cover just up the MTU size and no further. Allocating the
>>> maximum amount of segments results in a large waste of buffer space in
>>> the queue, which limits the number of packets that can be buffered and
>>> can result in reduced performance.
>>>
>>> Therefore, if GSO is not supported,
>> Ditto.
>>
>>> use the MTU to calculate the
>>> optimal amount of segments required.
>>>
>>> Below is the iperf TCP test results over a Mellanox NIC, using vDPA for
>>> 1 VQ, queue size 1024, before and after the change, with the iperf
>>> server running over the virtio-net interface.
>>>
>>> MTU(Bytes)/Bandwidth (Gbit/s)
>>> Before After
>>> 1500 22.5 22.4
>>> 9000 12.8 25.9
>>>
>>> Signed-off-by: Gavin Li <gavinl@nvidia.com>
>>> Reviewed-by: Gavi Teitz <gavi@nvidia.com>
>>> Reviewed-by: Parav Pandit <parav@nvidia.com>
>>> ---
>>> drivers/net/virtio_net.c | 20 ++++++++++++++++----
>>> 1 file changed, 16 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
>>> index ec8e1b3108c3..d36918c1809d 100644
>>> --- a/drivers/net/virtio_net.c
>>> +++ b/drivers/net/virtio_net.c
>>> @@ -222,6 +222,9 @@ struct virtnet_info {
>>> /* I like... big packets and I cannot lie! */
>>> bool big_packets;
>>> + /* Indicates GSO support */
>>> + bool gso_is_supported;
>>> +
>>> /* Host will merge rx buffers for big packets (shake it! shake
>>> it!) */
>>> bool mergeable_rx_bufs;
>>> @@ -1312,14 +1315,21 @@ static int add_recvbuf_small(struct
>>> virtnet_info *vi, struct receive_queue *rq,
>>> static int add_recvbuf_big(struct virtnet_info *vi, struct
>>> receive_queue *rq,
>>> gfp_t gfp)
>>> {
>>> + unsigned int sg_num = MAX_SKB_FRAGS;
>>> struct page *first, *list = NULL;
>>> char *p;
>>> int i, err, offset;
>>> - sg_init_table(rq->sg, MAX_SKB_FRAGS + 2);
>>> + if (!vi->gso_is_supported) {
>>> + unsigned int mtu = vi->dev->mtu;
>>> +
>>> + sg_num = (mtu % PAGE_SIZE) ? mtu / PAGE_SIZE + 1 : mtu /
>>> PAGE_SIZE;
>> DIV_ROUND_UP() can be used?
>>
>> Since this branch slightly adds up cost to the datapath, I wonder if
>> this sg_num can be saved and set only once (generally in virtnet_probe
>> time
> ... , but can align with new mtu during .ndo_change_mtu(), too.
ACK but don't know how to do this.
>> ) in struct virtnet_info?
>
> Thanks,
> -Siwei
>
>>> + }
>>> +
>>> + sg_init_table(rq->sg, sg_num + 2);
>>> /* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */
>> Comment doesn't match code.
>>> - for (i = MAX_SKB_FRAGS + 1; i > 1; --i) {
>>> + for (i = sg_num + 1; i > 1; --i) {
>>> first = get_a_page(rq, gfp);
>>> if (!first) {
>>> if (list)
>>> @@ -1350,7 +1360,7 @@ static int add_recvbuf_big(struct virtnet_info
>>> *vi, struct receive_queue *rq,
>>> /* chain first in list head */
>>> first->private = (unsigned long)list;
>>> - err = virtqueue_add_inbuf(rq->vq, rq->sg, MAX_SKB_FRAGS + 2,
>>> + err = virtqueue_add_inbuf(rq->vq, rq->sg, sg_num + 2,
>>> first, gfp);
>>> if (err < 0)
>>> give_pages(rq, first);
>>> @@ -3571,8 +3581,10 @@ static int virtnet_probe(struct virtio_device
>>> *vdev)
>>> if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
>>> virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) ||
>>> virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN) ||
>>> - virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UFO))
>>> + virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UFO)) {
>>> vi->big_packets = true;
>>> + vi->gso_is_supported = true;
>> Please do the same for virtnet_clear_guest_offloads(), and
>> correspondingly virtnet_restore_guest_offloads() as well. Not sure why
>> virtnet_clear_guest_offloads() or the caller doesn't unset big_packet
>> on successful return, seems like a bug to me.
>>
>>
>> Thanks,
>> -Siwei
>>> + }
>>> if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
>>> vi->mergeable_rx_bufs = true;
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org
next prev parent reply other threads:[~2022-08-08 7:34 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 4:45 [virtio-dev] [PATCH] virtio-net: use mtu size as buffer length for big packets Gavin Li
2022-08-04 5:00 ` Jason Wang
2022-08-04 7:10 ` Michael S. Tsirkin
2022-08-04 7:23 ` Jason Wang
2022-08-04 7:24 ` Jason Wang
2022-08-08 6:54 ` Gavin Li
2022-08-08 6:24 ` Gavin Li
2022-08-05 22:11 ` Si-Wei Liu
2022-08-05 23:26 ` Si-Wei Liu
2022-08-08 7:34 ` Gavin Li [this message]
2022-08-08 7:31 ` Gavin Li
2022-08-08 23:56 ` Si-Wei Liu
2022-08-09 7:06 ` Gavin Li
2022-08-09 7:44 ` Jason Wang
2022-08-09 9:22 ` Michael S. Tsirkin
2022-08-09 9:28 ` Jason Wang
2022-08-09 9:25 ` Michael S. Tsirkin
2022-08-09 9:40 ` Jason Wang
2022-08-09 18:38 ` Si-Wei Liu
2022-08-09 18:42 ` Parav Pandit
2022-08-09 19:08 ` Si-Wei Liu
2022-08-09 19:18 ` Parav Pandit
2022-08-09 20:32 ` Si-Wei Liu
2022-08-09 21:13 ` Parav Pandit
2022-08-09 21:32 ` Michael S. Tsirkin
2022-08-09 21:37 ` Michael S. Tsirkin
2022-08-09 21:49 ` Parav Pandit
2022-08-09 22:25 ` Michael S. Tsirkin
2022-08-09 22:49 ` Parav Pandit
2022-08-09 22:59 ` Michael S. Tsirkin
2022-08-09 23:04 ` Michael S. Tsirkin
2022-08-09 23:24 ` Si-Wei Liu
2022-08-10 6:14 ` Michael S. Tsirkin
2022-08-10 6:15 ` Michael S. Tsirkin
2022-08-10 6:59 ` Jason Wang
2022-08-10 9:03 ` Michael S. Tsirkin
2022-08-10 16:00 ` Parav Pandit
2022-08-10 16:05 ` Michael S. Tsirkin
2022-08-10 16:22 ` Parav Pandit
2022-08-10 16:58 ` Michael S. Tsirkin
2022-08-10 17:02 ` Michael S. Tsirkin
2022-08-10 17:06 ` Parav Pandit
2022-08-10 17:12 ` Michael S. Tsirkin
2022-08-11 0:26 ` Si-Wei Liu
2022-08-09 22:32 ` Si-Wei Liu
2022-08-09 22:37 ` Michael S. Tsirkin
2022-08-09 22:54 ` Si-Wei Liu
2022-08-09 23:03 ` Michael S. Tsirkin
2022-08-10 1:24 ` Jason Wang
2022-08-09 21:34 ` Michael S. Tsirkin
2022-08-09 21:39 ` Si-Wei Liu
2022-08-09 22:27 ` Michael S. Tsirkin
2022-08-10 1:15 ` Jason Wang
2022-08-09 18:06 ` Si-Wei Liu
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=d696fa2d-a198-5481-aefd-1727cdab5c32@nvidia.com \
--to=gavinl@nvidia.com \
--cc=alexander.h.duyck@intel.com \
--cc=davem@davemloft.net \
--cc=gavi@nvidia.com \
--cc=jasowang@redhat.com \
--cc=jesse.brandeburg@intel.com \
--cc=kubakici@wp.pl \
--cc=loseweigh@gmail.com \
--cc=mst@redhat.com \
--cc=parav@nvidia.com \
--cc=si-wei.liu@oracle.com \
--cc=sridhar.samudrala@intel.com \
--cc=stephen@networkplumber.org \
--cc=virtio-dev@lists.oasis-open.org \
--cc=virtualization@lists.linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox