Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1532912imm; Tue, 22 May 2018 05:40:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZprT+ZQLlQiC4I+0UGJm2cnl6rUtIafRQP1fcHdo6/4JKzJnidOpIdjigCP2RfW9PCjfT3V X-Received: by 2002:a17:902:7405:: with SMTP id g5-v6mr24636506pll.102.1526992832545; Tue, 22 May 2018 05:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526992832; cv=none; d=google.com; s=arc-20160816; b=KDC1X1w7jY+R2bvQWULOWlDdipTxgMf/aV/SyAZNTDAsvWaQwpDIa18BzR/bQOKqB7 QaMtu9ezxXUWEkp804noU/soQXurHkmkdBuKoK3YdmwIKHuDLuRGLjbrG462bSLf4UcD RBgDsyQIxb4KdghsYv5T4lCA8za0+51qbixa3cXgg0PNAmJyfaHh6aR6pT/J1WqCBsxM koSt2F6tBf+k3kw8lqFkbWUf/qJXtW8jdVZLhg4WUX/ZAM41Rxmg3+oEwOZpAxPV5+8w RKn4yNylu46PKDsBidBWjOBHjDaY7xIngetzw2beJbwxLorMibxbj/MAdtmTaodpQKLN jXtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=WD1S7LyG8qM9B56zmv67XMZZmBsyUC7yWTLPfmv3Lmo=; b=mf6PnxSScQYZRllLAOQMQmVXpLhJ/DFoS0XYvnS5DPBDRBvj8pHeYfsjiLXtk6onLe wyrv3htYb9jY1pes33xL4b6KXEIsUNL8t8BPTw07OUUozsjl0PNk+DOddX5SKRDXtxQY 2dokvMAXkisV+mSLaNl+E0DdaeFlBVmbqWgiuYU3FdUBNvwnv3QSxQoikz/vnKPBFBvf juaJF4MmBuzDmonRA729JEvDi5aPpq8V0rtkaZbpxgGDBQk3lzLCDIZlSFNOxIOseppH oAKUtTDpPJKp1DNfgPQO/0yv0H+5yk8RdG94Q/GVa75Oo45ej17ESLFofsNl2fJjj+dA qhLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v12-v6si15661565plo.264.2018.05.22.05.40.17; Tue, 22 May 2018 05:40:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbeEVMkA (ORCPT + 99 others); Tue, 22 May 2018 08:40:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37758 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751036AbeEVMj6 (ORCPT ); Tue, 22 May 2018 08:39:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6ABD40122A2; Tue, 22 May 2018 12:39:57 +0000 (UTC) Received: from [10.72.12.75] (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8ED0D6352E; Tue, 22 May 2018 12:39:52 +0000 (UTC) Subject: Re: [RFC PATCH net-next 04/12] vhost_net: split out datacopy logic To: Jesse Brandeburg Cc: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <1526893473-20128-1-git-send-email-jasowang@redhat.com> <1526893473-20128-5-git-send-email-jasowang@redhat.com> <20180521094646.00002dee@intel.com> From: Jason Wang Message-ID: Date: Tue, 22 May 2018 20:39:49 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180521094646.00002dee@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 22 May 2018 12:39:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 22 May 2018 12:39:57 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018年05月22日 00:46, Jesse Brandeburg wrote: > On Mon, 21 May 2018 17:04:25 +0800 Jason wrote: >> Instead of mixing zerocopy and datacopy logics, this patch tries to >> split datacopy logic out. This results for a more compact code and >> specific optimization could be done on top more easily. >> >> Signed-off-by: Jason Wang >> --- >> drivers/vhost/net.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++----- >> 1 file changed, 102 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c >> index 4ebac76..4682fcc 100644 >> --- a/drivers/vhost/net.c >> +++ b/drivers/vhost/net.c >> @@ -492,9 +492,95 @@ static bool vhost_has_more_pkts(struct vhost_net *net, >> likely(!vhost_exceeds_maxpend(net)); >> } >> >> +static void handle_tx_copy(struct vhost_net *net) >> +{ >> + struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX]; >> + struct vhost_virtqueue *vq = &nvq->vq; >> + unsigned out, in; > move "out" and "in" down to inside the for loop as well. > >> + int head; > move this "head" declaration inside for-loop below. Will do these in next version, basically this function were just copied from handle_tx_zerocopy and remove unnecessary parts. So I'm thinking an independent patch from the beginning to avoid changes in two places. > >> + struct msghdr msg = { >> + .msg_name = NULL, >> + .msg_namelen = 0, >> + .msg_control = NULL, >> + .msg_controllen = 0, >> + .msg_flags = MSG_DONTWAIT, >> + }; >> + size_t len, total_len = 0; >> + int err; >> + size_t hdr_size; >> + struct socket *sock; >> + struct vhost_net_ubuf_ref *uninitialized_var(ubufs); >> + int sent_pkts = 0; > why do we need so many locals? So it looks to me ubufs is unnecessary but all other is really needed. > >> + >> + mutex_lock(&vq->mutex); >> + sock = vq->private_data; >> + if (!sock) >> + goto out; >> + >> + if (!vq_iotlb_prefetch(vq)) >> + goto out; >> + >> + vhost_disable_notify(&net->dev, vq); >> + vhost_net_disable_vq(net, vq); >> + >> + hdr_size = nvq->vhost_hlen; >> + >> + for (;;) { >> + head = vhost_net_tx_get_vq_desc(net, vq, vq->iov, >> + ARRAY_SIZE(vq->iov), >> + &out, &in); >> + /* On error, stop handling until the next kick. */ >> + if (unlikely(head < 0)) >> + break; >> + /* Nothing new? Wait for eventfd to tell us they refilled. */ >> + if (head == vq->num) { >> + if (unlikely(vhost_enable_notify(&net->dev, vq))) { >> + vhost_disable_notify(&net->dev, vq); >> + continue; >> + } >> + break; >> + } >> + if (in) { >> + vq_err(vq, "Unexpected descriptor format for TX: " >> + "out %d, int %d\n", out, in); > don't break strings, keep all the bits between " " together, even if it > is longer than 80 chars. Ok. > >> + break; >> + } >> + >> + len = init_iov_iter(vq, &msg.msg_iter, hdr_size, out); >> + if (len < 0) >> + break; > same comment as previous patch, len is a size_t which is unsigned. Yes. > >> + >> + total_len += len; >> + if (total_len < VHOST_NET_WEIGHT && >> + vhost_has_more_pkts(net, vq)) { >> + msg.msg_flags |= MSG_MORE; >> + } else { >> + msg.msg_flags &= ~MSG_MORE; >> + } > don't need { } here. Right. >> + >> + /* TODO: Check specific error and bomb out unless ENOBUFS? */ >> + err = sock->ops->sendmsg(sock, &msg, len); >> + if (unlikely(err < 0)) { >> + vhost_discard_vq_desc(vq, 1); >> + vhost_net_enable_vq(net, vq); >> + break; >> + } >> + if (err != len) >> + pr_debug("Truncated TX packet: " >> + " len %d != %zd\n", err, len); > single line " " string please > Will fix. Thanks