From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0C5C8ECAAD4 for ; Wed, 31 Aug 2022 13:12:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7263241899; Wed, 31 Aug 2022 13:12:06 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 7263241899 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NEF3PwdS X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C4yfYk2eOSjx; Wed, 31 Aug 2022 13:12:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 159B341884; Wed, 31 Aug 2022 13:12:04 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 159B341884 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EE85CC0032; Wed, 31 Aug 2022 13:12:03 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 54461C002D for ; Wed, 31 Aug 2022 13:12:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 21F7D82D14 for ; Wed, 31 Aug 2022 13:12:03 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 21F7D82D14 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NEF3PwdS X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TTOcjT642x7y for ; Wed, 31 Aug 2022 13:12:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 2FD1682D0F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 2FD1682D0F for ; Wed, 31 Aug 2022 13:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661951521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=z/T15etvI12VltqvvTSCKLwx0EjkTTPcjNU7x17rAxU=; b=NEF3PwdS8CIRO6F5Xw51SYVuGhEjE1u+nz/0SvQO+/jX+ZO8pB3HCwz5VpLv0b/HnJP4DB Onj5rtK0BhuWBvtQVD4BfwGxZ4TZbhTLk6ZuEJtPHf5uVzDDphXhamrEk0OY+N2CBT+Nxc cRiYHwxctFpDl4xDLGxl4QkspQVOp04= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-220-HSsWnuYfPMqsszaIBQX1sw-1; Wed, 31 Aug 2022 09:12:00 -0400 X-MC-Unique: HSsWnuYfPMqsszaIBQX1sw-1 Received: by mail-wr1-f71.google.com with SMTP id h16-20020adfaa90000000b00226e36cc014so1018392wrc.8 for ; Wed, 31 Aug 2022 06:11:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=z/T15etvI12VltqvvTSCKLwx0EjkTTPcjNU7x17rAxU=; b=tJmFBveMRWZws4cFx4ypEiY6FngLrheSAnxSOez/U8/YJ5MDzAxmyvJjkEfNYVRmLC 05b16pwo5VaDMV/deVndgnLj+uBTXK6elDRzKeNQFCH3uo/zSFDs/CLR/iazuJRpDmnY vm8YvB4/npD1Jx4xdXvo5ZyHycxMqFm0827o8Gy9yjnTwIm4z4vxXKRcEaovlxnxRaHq NKoy+CZXLVVhdJYLFBpUoFtkF2ORvUZja+YwW+9Bng62Cuk48rwRMCUFOCb72/ZU73ex yZzj3Oy/6C6BSVqrYFFcJlcPE3axhjRrlmhiOR58nsOEoxYZ4stn7SICT9Mzn0SgsZOF 54MA== X-Gm-Message-State: ACgBeo2wV3+G/+RWR9fehTiSRlVVjPhx9btT4XmLCVOhJkd39ZaEDgbJ ve+/51wQeqit2qK8EI399sQ4c2Bedn1LscD5xITBPDU+ezGq5aRz7nMLUDkU9AQhdN4+bHBYips q3QaKJMOo5zPUDmJSzU7XHJgS/+zsOz2FF+1Qf19+JQ== X-Received: by 2002:a5d:6c62:0:b0:222:cda4:e09e with SMTP id r2-20020a5d6c62000000b00222cda4e09emr11718913wrz.449.1661951518846; Wed, 31 Aug 2022 06:11:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ZSYkA7fjm+OZ6sn+qmpM5mhoBEcsS0wdTyllOziEPy0pfYIn3m8l0JSgMpQ2wkc0TAxe4RQ== X-Received: by 2002:a5d:6c62:0:b0:222:cda4:e09e with SMTP id r2-20020a5d6c62000000b00222cda4e09emr11718900wrz.449.1661951518513; Wed, 31 Aug 2022 06:11:58 -0700 (PDT) Received: from redhat.com ([2.55.191.225]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c3b8500b003a319b67f64sm7823457wms.0.2022.08.31.06.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 06:11:58 -0700 (PDT) Date: Wed, 31 Aug 2022 09:11:53 -0400 From: "Michael S. Tsirkin" To: Gavin Li Subject: Re: [PATCH RESEND v4 2/2] virtio-net: use mtu size as buffer length for big packets Message-ID: <20220831090907-mutt-send-email-mst@kernel.org> References: <20220831130541.81217-1-gavinl@nvidia.com> <20220831130541.81217-3-gavinl@nvidia.com> MIME-Version: 1.0 In-Reply-To: <20220831130541.81217-3-gavinl@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Cc: alexander.h.duyck@intel.com, virtio-dev@lists.oasis-open.org, sridhar.samudrala@intel.com, jesse.brandeburg@intel.com, gavi@nvidia.com, virtualization@lists.linux-foundation.org, stephen@networkplumber.org, loseweigh@gmail.com, netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Wed, Aug 31, 2022 at 04:05:41PM +0300, 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 guest GSO is not supported, 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 guest GSO is not supported, use the MTU to calculate the > optimal amount of segments required. > > When guest offload is enabled at runtime, RQ already has packets of bytes > less than 64K. So when packet of 64KB arrives, all the packets of such > size will be dropped. and RQ is now not usable. > > So this means that during set_guest_offloads() phase, RQs have to be > destroyed and recreated, which requires almost driver reload. > > If VIRTIO_NET_F_CTRL_GUEST_OFFLOADS has been negotiated, then it should > always treat them as GSO enabled. a better way to put this last sentence: Accordingly, for now we assume that if GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through VIRTIO_NET_F_CTRL_GUEST_OFFLOADS. > 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 > Reviewed-by: Gavi Teitz > Reviewed-by: Parav Pandit > Reviewed-by: Xuan Zhuo > Reviewed-by: Si-Wei Liu > --- > changelog: > v3->v4 > - Addressed comments from Si-Wei > - Rename big_packets_sg_num with big_packets_num_skbfrags > v2->v3 > - Addressed comments from Si-Wei > - Simplify the condition check to enable the optimization > v1->v2 > - Addressed comments from Jason, Michael, Si-Wei. > - Remove the flag of guest GSO support, set sg_num for big packets and > use it directly > - Recalculate sg_num for big packets in virtnet_set_guest_offloads > - Replace the round up algorithm with DIV_ROUND_UP > --- > drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- > 1 file changed, 24 insertions(+), 13 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index e1904877d461..ba2852b41795 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -225,6 +225,9 @@ struct virtnet_info { > /* I like... big packets and I cannot lie! */ > bool big_packets; > > + /* number of sg entries allocated for big packets */ > + unsigned int big_packets_num_skbfrags; > + > /* Host will merge rx buffers for big packets (shake it! shake it!) */ > bool mergeable_rx_bufs; > > @@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, > char *p; > int i, err, offset; > > - sg_init_table(rq->sg, MAX_SKB_FRAGS + 2); > + sg_init_table(rq->sg, vi->big_packets_num_skbfrags + 2); > > - /* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ > - for (i = MAX_SKB_FRAGS + 1; i > 1; --i) { > + /* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ > + for (i = vi->big_packets_num_skbfrags + 1; i > 1; --i) { > first = get_a_page(rq, gfp); > if (!first) { > if (list) > @@ -1365,7 +1368,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, vi->big_packets_num_skbfrags + 2, > first, gfp); > if (err < 0) > give_pages(rq, first); > @@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi) > virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO)); > } > > +static void virtnet_set_big_packets_fields(struct virtnet_info *vi, const int mtu) > +{ > + bool guest_gso = virtnet_check_guest_gso(vi); > + > + /* If device can receive ANY guest GSO packets, regardless of mtu, > + * allocate packets of maximum size, otherwise limit it to only > + * mtu size worth only. > + */ > + if (mtu > ETH_DATA_LEN || guest_gso) { > + vi->big_packets = true; > + vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS : DIV_ROUND_UP(mtu, PAGE_SIZE); > + } > +} > + > static int virtnet_probe(struct virtio_device *vdev) > { > int i, err = -ENOMEM; > struct net_device *dev; > struct virtnet_info *vi; > u16 max_queue_pairs; > - int mtu; > + int mtu = 0; > > /* Find if host supports multiqueue/rss virtio_net device */ > max_queue_pairs = 1; > @@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev) > INIT_WORK(&vi->config_work, virtnet_config_changed_work); > spin_lock_init(&vi->refill_lock); > > - /* If we can receive ANY GSO packets, we must allocate large ones. */ > - if (virtnet_check_guest_gso(vi)) > - vi->big_packets = true; > - > if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) > vi->mergeable_rx_bufs = true; > > @@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) > > dev->mtu = mtu; > dev->max_mtu = mtu; > - > - /* TODO: size buffers correctly in this case. */ > - if (dev->mtu > ETH_DATA_LEN) > - vi->big_packets = true; > } > > + virtnet_set_big_packets_fields(vi, mtu); > + > if (vi->any_header_sg) > dev->needed_headroom = vi->hdr_len; > > -- > 2.31.1 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization