Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3622706ybi; Mon, 29 Jul 2019 09:39:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwskSAqFwRTraXzX7XwKcI+wz201LWqMY/jVBW+sL+5faqOPzGvgBM4vk6B0agqppTGUbv X-Received: by 2002:aa7:86cc:: with SMTP id h12mr30035880pfo.2.1564418343928; Mon, 29 Jul 2019 09:39:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564418343; cv=none; d=google.com; s=arc-20160816; b=ngwl6pV4fqM355dNs1uKqT17oyz6FC9mydxEiXVZeLyf+2jUorX9qPw2mRt6fy822i E1RFciiE/GX5FR6lH/E9QP3jzC0PNDiFuDoYHTbi7lZL13HYK5/dgbCdOF9JBd3Z+NUI cinQapThwnGSKVBQgWJTUoMWDmQ5zAo9iJyH7X5tXbiLadsnWB8SUsviMTW50rrIKCzC ibrfBwo1EyzP/u9DHajfpqamI0uH42Efl4goSsM+cMGmvht+dguc66c92MXCvBgUzBU1 g4VebNy1E+CUkAVE1FDqkKCKhli2UwDS6hZqk7Ui+XTlrprZNfIrhAf8bGu2dYySvBVW /kBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=F22IOpvGzuwCs+Et2Wm6c0mIYlOT2lCTjpD6ddOFTas=; b=Yy7UaOOOgabOqxFokO+MjDysTZnDkV1zOjKCD/FJ3eLvbEMxpD3QuumocSjkZJzfz5 LuX6SMC//SAfcAcCgSS/lmVWYF/1+LCj1yJfgPiOWZFh2ipRWr8ozAl7x9UqaQ3LncWe bK1WZEPWxWOFP4aaJjhHhU8kCzuUvfEdnVCtWE6x+hy2qiLbxM/kjxe/1ga+CRnuC7pp zN7OJcXRiuoirWu31FHD5k+5H6NKqg9KoxS9q9SGbGkaXYE3QmymrtMMHsmu9CjX3zXN vbuMokSXxGoPhOz9qwsvj27sfVzFx6gzEhqzsTHqPn3bV+FUQ/0Fq7sDmdyPP9yYvsYv IjZQ== 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 t185si26240829pgd.596.2019.07.29.09.38.49; Mon, 29 Jul 2019 09:39:03 -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 S1727660AbfG2QBo (ORCPT + 99 others); Mon, 29 Jul 2019 12:01:44 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:33300 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbfG2QBo (ORCPT ); Mon, 29 Jul 2019 12:01:44 -0400 Received: by mail-vs1-f67.google.com with SMTP id m8so41225403vsj.0 for ; Mon, 29 Jul 2019 09:01:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=F22IOpvGzuwCs+Et2Wm6c0mIYlOT2lCTjpD6ddOFTas=; b=sKGJe5VGC/t8mBWFQcznheoM7nXOftsRzk0ceZ0jBhRA9uxnlg6pZymgKbtiFDvuIA 2CuiF02DKLyf1uFtX6IlGPKAgKfl2foIc3cTvjhJzGdToXeLy18sWIJWKqT83v8zd0sv oIp9SOESHh0JFS04hx1ZGB8efl8HRr9LbOtkE+ELKzszqFaDFC0/o1NsCTxqIOSGaTNQ RprVQ1FVOEdXzxvpVyMtpsgn467Oebk6OVQQFF9WvGkKP/t8i0XpkXVDESTDHfD0Rfzc cwMAOKohBxxEhSaro9T5N+qdzOkwBV7Rs1ElOuPutDoyDYSOn8mCXi6IKfNoEvpjwgb5 fLRA== X-Gm-Message-State: APjAAAUCQWYHm4eB+oXG8c6KV61W6/mquGJurpas6bpCXV6qx6vUm1Xv lrH2gpisCCz3d33GLzSu4lFifA== X-Received: by 2002:a67:89c7:: with SMTP id l190mr68587815vsd.13.1564416103428; Mon, 29 Jul 2019 09:01:43 -0700 (PDT) Received: from redhat.com (bzq-79-181-91-42.red.bezeqint.net. [79.181.91.42]) by smtp.gmail.com with ESMTPSA id t200sm25600663vke.5.2019.07.29.09.01.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 09:01:42 -0700 (PDT) Date: Mon, 29 Jul 2019 12:01:37 -0400 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Hajnoczi , "David S. Miller" , virtualization@lists.linux-foundation.org, Jason Wang , kvm@vger.kernel.org Subject: Re: [PATCH v4 1/5] vsock/virtio: limit the memory used per-socket Message-ID: <20190729115904-mutt-send-email-mst@kernel.org> References: <20190717113030.163499-1-sgarzare@redhat.com> <20190717113030.163499-2-sgarzare@redhat.com> <20190729095956-mutt-send-email-mst@kernel.org> <20190729153656.zk4q4rob5oi6iq7l@steredhat> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190729153656.zk4q4rob5oi6iq7l@steredhat> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 29, 2019 at 05:36:56PM +0200, Stefano Garzarella wrote: > On Mon, Jul 29, 2019 at 10:04:29AM -0400, Michael S. Tsirkin wrote: > > On Wed, Jul 17, 2019 at 01:30:26PM +0200, Stefano Garzarella wrote: > > > Since virtio-vsock was introduced, the buffers filled by the host > > > and pushed to the guest using the vring, are directly queued in > > > a per-socket list. These buffers are preallocated by the guest > > > with a fixed size (4 KB). > > > > > > The maximum amount of memory used by each socket should be > > > controlled by the credit mechanism. > > > The default credit available per-socket is 256 KB, but if we use > > > only 1 byte per packet, the guest can queue up to 262144 of 4 KB > > > buffers, using up to 1 GB of memory per-socket. In addition, the > > > guest will continue to fill the vring with new 4 KB free buffers > > > to avoid starvation of other sockets. > > > > > > This patch mitigates this issue copying the payload of small > > > packets (< 128 bytes) into the buffer of last packet queued, in > > > order to avoid wasting memory. > > > > > > Reviewed-by: Stefan Hajnoczi > > > Signed-off-by: Stefano Garzarella > > > > This is good enough for net-next, but for net I think we > > should figure out how to address the issue completely. > > Can we make the accounting precise? What happens to > > performance if we do? > > > > In order to do more precise accounting maybe we can use the buffer size, > instead of payload size when we update the credit available. > In this way, the credit available for each socket will reflect the memory > actually used. > > I should check better, because I'm not sure what happen if the peer sees > 1KB of space available, then it sends 1KB of payload (using a 4KB > buffer). > The other option is to copy each packet in a new buffer like I did in > the v2 [2], but this forces us to make a copy for each packet that does > not fill the entire buffer, perhaps too expensive. > > [2] https://patchwork.kernel.org/patch/10938741/ > So one thing we can easily do is to under-report the available credit. E.g. if we copy up to 256bytes, then report just 256bytes for every buffer in the queue. > > Thanks, > Stefano