Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp526738ybl; Fri, 23 Aug 2019 04:39:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzM54zKM2TlQPwRQWFlDANxKiPSpSTx3OI5WbhNOOLscKFG+Oe4LoN4lLTuCSwrPGDbYK8 X-Received: by 2002:a17:902:a70c:: with SMTP id w12mr4355129plq.288.1566560352575; Fri, 23 Aug 2019 04:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566560352; cv=none; d=google.com; s=arc-20160816; b=caPNnoZFWLO9Lc6RUqjPPXIbk2WuzCONBPHKgK6gYwd/RaZUe4qI5p9iiFOvxdCWpr Np/WtNrrKmss32tXwAvOObL0IXx9xmYpNWxJ4hKmmYvIElqDnv9Fl1XoQK1eLzAV7QMY sOWA5aIdCi4jGqkKtRNWmOPulCZxeSpsNR6ipyZkOy17oVXOtDiqZ1j41/5E5VL+5IZy v6kpskJ0/GT781/HGB3iw4V/brsr8iC8/HV1OgFOA23PLDSPPSYXVPkhLllS+VsnQNgv NXlWB4nnPRWS9sXhYdLxG1Kf2k8y0IIYZgOPnE2dUWHLyEmy8DPOsjC7pxEmO+r/szJd mRnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aQ83pb+kxMA4PRMfH8YgWbNCnOXFKZ9EpFfDi/w7Z3g=; b=xocCW6mkMkBDVJqXo8JJMHnKBc8Vyp9a/6QCL+Cg+nHmX8rfmMdQQBQlocHyuNpOei t6xw/uu9Djbkl7hLZMPZcDpGXZ/INxF9qrsqHLq3q+lM/cn3ZEO6pcTj4wgzURzSzevj 6+4X2UsoYwvBelZmkyH73BAm1TyyOfzlijTPsPoqSl7765chv320sIYu63XXsh4yHb0n 0sTC1VESt6cJDi2YQxCItTfLdCRcw5SmkBcDaz4t4thEA8wqNoZWr7VP6P64l5pOefDy zEgykw3j1RECsYx45KP3iKD0DPde/Ngwh5wOhR+RSfrZMaVM/RiO+AnVJZgBMTEgNCBO iWvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yfziqd57; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si2072420pji.69.2019.08.23.04.38.57; Fri, 23 Aug 2019 04:39:12 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Yfziqd57; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392706AbfHVRn4 (ORCPT + 99 others); Thu, 22 Aug 2019 13:43:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:43830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403987AbfHVRXk (ORCPT ); Thu, 22 Aug 2019 13:23:40 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 04C7D2342A; Thu, 22 Aug 2019 17:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494620; bh=enGPf8cAiY/xVc+54XdG/OYlHtSqG8aj/NsQHCuhuIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yfziqd57Fprv0bbWjdjwWhoQ0GdpyNb8UZWRHU77HlNZbiQ1/2+a346N2A1Yefnkj +Tn+aNN49M36sW9a22BiTth10A0e0IBjUInpGFnAYxVhtP8InEXVwwp4Q35G+HfBD3 Mqu88nEY2ftwcMH1b6nE3PxoDNuDtT4uhTwzmd8g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Abeni , Jason Wang , "David S. Miller" , Ben Hutchings Subject: [PATCH 4.9 049/103] vhost_net: use packet weight for rx handler, too Date: Thu, 22 Aug 2019 10:18:37 -0700 Message-Id: <20190822171730.779400756@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171728.445189830@linuxfoundation.org> References: <20190822171728.445189830@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Abeni commit db688c24eada63b1efe6d0d7d835e5c3bdd71fd3 upstream. Similar to commit a2ac99905f1e ("vhost-net: set packet weight of tx polling to 2 * vq size"), we need a packet-based limit for handler_rx, too - elsewhere, under rx flood with small packets, tx can be delayed for a very long time, even without busypolling. The pkt limit applied to handle_rx must be the same applied by handle_tx, or we will get unfair scheduling between rx and tx. Tying such limit to the queue length makes it less effective for large queue length values and can introduce large process scheduler latencies, so a constant valued is used - likewise the existing bytes limit. The selected limit has been validated with PVP[1] performance test with different queue sizes: queue size 256 512 1024 baseline 366 354 362 weight 128 715 723 670 weight 256 740 745 733 weight 512 600 460 583 weight 1024 423 427 418 A packet weight of 256 gives peek performances in under all the tested scenarios. No measurable regression in unidirectional performance tests has been detected. [1] https://developers.redhat.com/blog/2017/06/05/measuring-and-comparing-open-vswitch-performance/ Signed-off-by: Paolo Abeni Acked-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/net.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -40,8 +40,10 @@ MODULE_PARM_DESC(experimental_zcopytx, " #define VHOST_NET_WEIGHT 0x80000 /* Max number of packets transferred before requeueing the job. - * Using this limit prevents one virtqueue from starving rx. */ -#define VHOST_NET_PKT_WEIGHT(vq) ((vq)->num * 2) + * Using this limit prevents one virtqueue from starving others with small + * pkts. + */ +#define VHOST_NET_PKT_WEIGHT 256 /* MAX number of TX used buffers for outstanding zerocopy */ #define VHOST_MAX_PEND 128 @@ -480,7 +482,7 @@ static void handle_tx(struct vhost_net * total_len += len; vhost_net_tx_packet(net); if (unlikely(total_len >= VHOST_NET_WEIGHT) || - unlikely(++sent_pkts >= VHOST_NET_PKT_WEIGHT(vq))) { + unlikely(++sent_pkts >= VHOST_NET_PKT_WEIGHT)) { vhost_poll_queue(&vq->poll); break; } @@ -662,6 +664,7 @@ static void handle_rx(struct vhost_net * struct socket *sock; struct iov_iter fixup; __virtio16 num_buffers; + int recv_pkts = 0; mutex_lock_nested(&vq->mutex, 0); sock = vq->private_data; @@ -760,7 +763,8 @@ static void handle_rx(struct vhost_net * vhost_log_write(vq, vq_log, log, vhost_len, vq->iov, in); total_len += vhost_len; - if (unlikely(total_len >= VHOST_NET_WEIGHT)) { + if (unlikely(total_len >= VHOST_NET_WEIGHT) || + unlikely(++recv_pkts >= VHOST_NET_PKT_WEIGHT)) { vhost_poll_queue(&vq->poll); goto out; }