Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5246436ybi; Tue, 28 May 2019 09:46:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkpZaVS7VBXjMQJZ8b5/hICZ7LuSjoLqODjRHHYR0DHuWMGb0f2Nt40V/qoU6rAV2dq6X8 X-Received: by 2002:a63:555a:: with SMTP id f26mr132090172pgm.197.1559062019663; Tue, 28 May 2019 09:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559062019; cv=none; d=google.com; s=arc-20160816; b=Jzuy/IGm+xsvOz7igeukHJPJG+EEuCnazI9/ZJ4jjWWZskIozfLM9rfDozc2V7TvgG HGCQQzOxJZlAm6AVa8WEe22S+VQkaJGihe/qLNP9tU2sFoZpKfztpmVOmyeJ1jdkETeR 4212oURjln82fLQo+tu+vaoqthqV4rjk+nlWww8Yd5KNXlc9jaalO5Kc6dxf3/dm0r3S Zj7RVlePpMMKdhUJx7hGDi/UETuSU1xkuu6FguEhRc0704+6p3w3039HG1TcPAEDxIyo Ij8Px9cfxW5bVGrn9L6WseMrAirXbN838MlcN64E1z4nucd+KhrbHTeClBhN8tJPxFVS BHXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=YfCDy8k/dL7Dko33LF05Qlo/QHsbXR3MAXNOFcVS/RA=; b=vxOgrH2jBm1kowSBvSqa1gbAFegNYfa2zgR1erLJ9es6D9U+hNpeYpdMGwepD0ZDRc oVfGZkYLid6jHfpigNut7mQLn8MbpZ+1J9MxZurEVzuv2Q4zweimKD1hmaI7+fingz7y hG68QOUPqkp066Iq3j3IlcXve1DTGtxUEVpJTQs67vy3mHRdPhnmE5KlNNDWOgP1jM1z SqmEEKGqg8ebhalDBfB4nDzMErGb1jEQPb02mSPiN5caCsP3FZy0rhBIpgC6erGYcUt2 zWiCdAoswOJDFMxjFi7JsiY+R2VKI+1CPpDc5mPDGNtEXoKyThtovv5upbU+3DEAaeOY icyQ== 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 q203si22019160pgq.384.2019.05.28.09.46.43; Tue, 28 May 2019 09:46:59 -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 S1727216AbfE1Qp3 (ORCPT + 99 others); Tue, 28 May 2019 12:45:29 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53362 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726820AbfE1Qp1 (ORCPT ); Tue, 28 May 2019 12:45:27 -0400 Received: by mail-wm1-f67.google.com with SMTP id d17so3720709wmb.3 for ; Tue, 28 May 2019 09:45:26 -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:content-transfer-encoding :in-reply-to:user-agent; bh=YfCDy8k/dL7Dko33LF05Qlo/QHsbXR3MAXNOFcVS/RA=; b=d22ntN0ExRAk/vHw87t82ksuZ5lTexm9CDWsdwhC2t8O6Fqte1iWmsnXrn4IL8g0d/ yA6rZ3PDB4fe4GIbE5RTA7n8xwTYLyR2GrXLURxj1pAZudfHCCLCOiv32nU6+0T2a6yY fgJoi0AJF4dSFpCZDgxvJ0ox3XZLvMlAfdy/hs/N7t6L/XeAbGASupRdCFysryUUWFrk p8r6l16nZPobaKA3faYpv6q02KWrbmy1fR9NDwLp20S8VKIfjs2juL8vlykn1w5NPH4l kY8J46uE0YhXd90QgC87ysBZkj6LAoMJFZThDXACgTfZhBMt1DdPfPvXgSY7EyZa1Mib jxOA== X-Gm-Message-State: APjAAAWf/YdIEF/PfIqJNUGxM4bQcXCNB8gGSMArQARRgUyp5Pf0Te/2 ZL0d2lqeA/cVBgmVjFvZ8wUjNw== X-Received: by 2002:a1c:7d56:: with SMTP id y83mr3545448wmc.77.1559061925586; Tue, 28 May 2019 09:45:25 -0700 (PDT) Received: from steredhat.homenet.telecomitalia.it (host253-229-dynamic.248-95-r.retail.telecomitalia.it. [95.248.229.253]) by smtp.gmail.com with ESMTPSA id x7sm1868809wmc.44.2019.05.28.09.45.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 09:45:24 -0700 (PDT) Date: Tue, 28 May 2019 18:45:21 +0200 From: Stefano Garzarella To: Jason Wang , Stefan Hajnoczi Cc: netdev@vger.kernel.org, "David S. Miller" , "Michael S. Tsirkin" , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v2 1/8] vsock/virtio: limit the memory used per-socket Message-ID: <20190528164521.k2euedfcmtvvynew@steredhat.homenet.telecomitalia.it> References: <20190510125843.95587-1-sgarzare@redhat.com> <20190510125843.95587-2-sgarzare@redhat.com> <3b275b52-63d9-d260-1652-8e8bf7dd679f@redhat.com> <20190513172322.vcgenx7xk4v6r2ay@steredhat> <20190514163500.a7moalixvpn5mkcr@steredhat> <034a5081-b4fb-011f-b5b7-fbf293c13b23@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <034a5081-b4fb-011f-b5b7-fbf293c13b23@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 15, 2019 at 10:48:44AM +0800, Jason Wang wrote: > > On 2019/5/15 上午12:35, Stefano Garzarella wrote: > > On Tue, May 14, 2019 at 11:25:34AM +0800, Jason Wang wrote: > > > On 2019/5/14 上午1:23, Stefano Garzarella wrote: > > > > On Mon, May 13, 2019 at 05:58:53PM +0800, Jason Wang wrote: > > > > > On 2019/5/10 下午8:58, Stefano Garzarella wrote: > > > > > > +static struct virtio_vsock_buf * > > > > > > +virtio_transport_alloc_buf(struct virtio_vsock_pkt *pkt, bool zero_copy) > > > > > > +{ > > > > > > + struct virtio_vsock_buf *buf; > > > > > > + > > > > > > + if (pkt->len == 0) > > > > > > + return NULL; > > > > > > + > > > > > > + buf = kzalloc(sizeof(*buf), GFP_KERNEL); > > > > > > + if (!buf) > > > > > > + return NULL; > > > > > > + > > > > > > + /* If the buffer in the virtio_vsock_pkt is full, we can move it to > > > > > > + * the new virtio_vsock_buf avoiding the copy, because we are sure that > > > > > > + * we are not use more memory than that counted by the credit mechanism. > > > > > > + */ > > > > > > + if (zero_copy && pkt->len == pkt->buf_len) { > > > > > > + buf->addr = pkt->buf; > > > > > > + pkt->buf = NULL; > > > > > > + } else { > > > > > Is the copy still needed if we're just few bytes less? We meet similar issue > > > > > for virito-net, and virtio-net solve this by always copy first 128bytes for > > > > > big packets. > > > > > > > > > > See receive_big() > > > > I'm seeing, It is more sophisticated. > > > > IIUC, virtio-net allocates a sk_buff with 128 bytes of buffer, then copies the > > > > first 128 bytes, then adds the buffer used to receive the packet as a frag to > > > > the skb. > > > > > > Yes and the point is if the packet is smaller than 128 bytes the pages will > > > be recycled. > > > > > > > > So it's avoid the overhead of allocation of a large buffer. I got it. > > > > Just a curiosity, why the threshold is 128 bytes? > > > From its name (GOOD_COPY_LEN), I think it just a value that won't lose much > performance, e.g the size two cachelines. > Jason, Stefan, since I'm removing the patches to increase the buffers to 64 KiB and I'm adding a threshold for small packets, I would simplify this patch, removing the new buffer allocation and copying small packets into the buffers already queued (if there is a space). In this way, I should solve the issue of 1 byte packets. Do you think could be better? Thanks, Stefano