Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3776056ybi; Mon, 29 Jul 2019 12:24:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWFKG98rpvXf+cvHLPur2l9e7Mg3GDO3x358hmx71aHe/AzTtfdHe13W2oPrpKzwv2M1X0 X-Received: by 2002:a17:90b:949:: with SMTP id dw9mr8842052pjb.49.1564428273206; Mon, 29 Jul 2019 12:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428273; cv=none; d=google.com; s=arc-20160816; b=fZc8xOkVz8s90Kg7WJwykWI0rFHcOz29KO9By7bYpe6hDYUxouIhE/mbaCwgz7R4pV mFy5XmiERiv3qQJv0pSyfQthg8DrD3gpmpQhwvBGxKR5YYVDoQg48C8k4zT6jqdHs65A IA//pxHB/mHtdG+yRFSx4bLJVcZviARH5Q/mylIuhzLkESbTGRPdlkDhqZdd3LbyhEi4 1w29bD4POymzluf+8Nflu6y9xnNNreNIFRXuJJlkl3KEJzPXerP1zdcPBeNUmG2c6AVN 11J4l9QpmPuIiO+Kbh+XAVbdu3AXdsnlf2qfNSPMdBpTt3T8QBwnJZnTRdxqBLUHAid/ HKRA== 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=/niwkJuj+kTChFIxAZJ7R3qyc1S8YzIk+KDkO6xs7tI=; b=LrJEdf5JZ/yUMpQ8YA/aEAZof3CUtperpV/kgkR4TRmM4qGmxMqi1iaJuQ2MIK3cKq mD0eqcPQVLV7yX9sDWHUER6riiZsHw2A1IEcpJiL2qdjZy8Zws+c1lZi8zPfckpsUncB oFaqnyNg144gr0wTdX3PQ/B1kd3AKsV9FQ48FmrYwJP19Ov8cx4tSqHotk3EPJtVp++f qVMLhiAzS1esP+SHZOzglReoZdG7UXfAyPXx48LPDOjk22iH6zIUCEXdjuT8mytmMs/4 +FoJMKD2mNbiZMoHh/eMV0C2a74d2L167/jVuAbIaA5qCWTiin0y0vvuFmhS1NS/5vJS EPBA== 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 f1si22930100pgn.149.2019.07.29.12.24.17; Mon, 29 Jul 2019 12:24:33 -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 S2387998AbfG2PtK (ORCPT + 99 others); Mon, 29 Jul 2019 11:49:10 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:40509 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387495AbfG2PtK (ORCPT ); Mon, 29 Jul 2019 11:49:10 -0400 Received: by mail-vs1-f66.google.com with SMTP id a186so39499069vsd.7 for ; Mon, 29 Jul 2019 08:49:09 -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=/niwkJuj+kTChFIxAZJ7R3qyc1S8YzIk+KDkO6xs7tI=; b=SJxA4BD402OPY1nJjj4RNi9QQ4HJlKuQsgAlE5qIrFcjm29XwqUoZ724tXEb5yRqXV C6cKjpaCMNY6tph5ZHWMIn3eW9D9EE0avh5SUehbdjDNOHGw4/jA0QlHgccLox3vxIcs peDG4FQJ1y/mbKOuXOMg/9lZ0xWr9NwWHgPFEBzLsr9WfvZ4RbeECdwS1bTMw9txdcEx 9weSVsybHHDmsFF7U5E6YjAr9k8312U09z0vkA8o7gta6EjXhA6KZZ8l05F2Cp+gEbEa S0XZkV3gp7UHapU+esjrGEoWGuEreLYTb0vzeRrVg/DIWExYBEh0NJPEN8RO391KTLZF MZCw== X-Gm-Message-State: APjAAAVhOJAABpK3CGXGDZpZvDrJ3LfpQujeCxJTI4N0xSG6olqZtPrm o4eCwcZQWHW1td2B6NxHNtzB3Q== X-Received: by 2002:a67:694f:: with SMTP id e76mr14283114vsc.77.1564415349351; Mon, 29 Jul 2019 08:49:09 -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 h81sm16021382vka.19.2019.07.29.08.49.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 08:49:08 -0700 (PDT) Date: Mon, 29 Jul 2019 11:49:02 -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: <20190729114302-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/ > > > Thanks, > Stefano Interesting. You are right, and at some level the protocol forces copies. We could try to detect that the actual memory is getting close to admin limits and force copies on queued packets after the fact. Is that practical? And yes we can extend the credit accounting to include buffer size. That's a protocol change but maybe it makes sense. -- MST