Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4755639yba; Mon, 20 May 2019 03:15:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZ6RZk1VDT51cLSBgERZIT0ly5eCBW4h2nLtVjonhE6u2HtXyOlIJzr+nceGtKajOF5oKw X-Received: by 2002:a17:902:1621:: with SMTP id g30mr33804789plg.326.1558347336544; Mon, 20 May 2019 03:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558347336; cv=none; d=google.com; s=arc-20160816; b=FmIHzCJ/cZ4ncl+h9XbGl365R8MFbISwn/1Qdc37CtxmlzNJXu9kH+Y5fIWceLUox7 ANAkgbsKRLFhf/nfh0y+uC2XiOoCDJ+GxEG6EHIhsYG0M3grsLGmbvEPibtyHvkqfzc8 RcG/K5+hC3yMda4Eg/WjdgydVuE5vq3wuwd4OkaIcF+wAzaBQ6MF9KVBAN8zTudzRwUZ 6kz+FqUPhX5yM8dJbdxP2XD82JL3e/XtkDeRIzumGHMq78isS/h3SSjSqCBcgf8uftcG czpmcN/CK2B2J98GpmDvbw9q7rh4297M6xO9T5ycJW/IlraptdsWadkpPqFocrsVMdIw tbRA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=EpIChfc7a3W+Pp+iIYDntidmKDKSDJvbAQDwCR+tREI=; b=uY99983hMGJfs5v76XJlmGdonPhwwM1/0SQP18wc14wcPex/8XQHZK/S3171/kaYMy xxiGJgotxE9bBv4kYW/rVjVpF2TAgcr4qHwvgxvdHioR4gcrqVtkNWuarAzjLNivEGR5 zmo4hKzNfNdm2zDgtNz9oULjF7Iu/wkKRGGef5G+dll89WYcLGXhss6rEmMlEDOFinuo B8g1kdF4aynhqTtbIqc6gY3yYpZ8HQTs+uY/IPd2jQxu6ufo8VKPvBUO8kLPb58zTSvV 25iFTGlLLKFpdQt9uyu0+2ApZC2VboxttkB27dOJ/RLtSdwDEr2K/YK/ojv7Gte373Ak wgGQ== 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 u3si18493191pfa.128.2019.05.20.03.15.21; Mon, 20 May 2019 03:15:36 -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 S1731730AbfETI5r (ORCPT + 99 others); Mon, 20 May 2019 04:57:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40668 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731080AbfETI5r (ORCPT ); Mon, 20 May 2019 04:57:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B11D307D90F; Mon, 20 May 2019 08:57:38 +0000 (UTC) Received: from localhost (unknown [10.36.118.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00EB75D719; Mon, 20 May 2019 08:57:32 +0000 (UTC) Date: Mon, 20 May 2019 09:57:31 +0100 From: Stefan Hajnoczi To: Stefano Garzarella 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, Jason Wang Subject: Re: [PATCH v2 1/8] vsock/virtio: limit the memory used per-socket Message-ID: <20190520085731.GA22546@stefanha-x1.localdomain> References: <20190510125843.95587-1-sgarzare@redhat.com> <20190510125843.95587-2-sgarzare@redhat.com> <20190516152533.GB29808@stefanha-x1.localdomain> <20190517082505.ibjkuh7zibumen77@steredhat> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wRRV7LY7NUeQGEoC" Content-Disposition: inline In-Reply-To: <20190517082505.ibjkuh7zibumen77@steredhat> User-Agent: Mutt/1.11.4 (2019-03-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 20 May 2019 08:57:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 17, 2019 at 10:25:05AM +0200, Stefano Garzarella wrote: > On Thu, May 16, 2019 at 04:25:33PM +0100, Stefan Hajnoczi wrote: > > On Fri, May 10, 2019 at 02:58:36PM +0200, Stefano Garzarella wrote: > > > +static struct virtio_vsock_buf * > > > +virtio_transport_alloc_buf(struct virtio_vsock_pkt *pkt, bool zero_c= opy) > > > +{ > > > + struct virtio_vsock_buf *buf; > > > + > > > + if (pkt->len =3D=3D 0) > > > + return NULL; > > > + > > > + buf =3D 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 mecha= nism. > > > + */ > > > + if (zero_copy && pkt->len =3D=3D pkt->buf_len) { > > > + buf->addr =3D pkt->buf; > > > + pkt->buf =3D NULL; > > > + } else { > > > + buf->addr =3D kmalloc(pkt->len, GFP_KERNEL); > >=20 > > buf and buf->addr could be allocated in a single call, though I'm not > > sure how big an optimization this is. > >=20 >=20 > IIUC, in the case of zero-copy I should allocate only the buf, > otherwise I should allocate both buf and buf->addr in a single call > when I'm doing a full-copy. >=20 > Is it correct? Yes, but it's your choice whether optimization is worthwhile. If it increases the complexity of the code and doesn't result in a measurable improvement, then it's not worth it. Stefan --wRRV7LY7NUeQGEoC Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAlzia/sACgkQnKSrs4Gr c8j8/Qf+NOeZJ2tO8MN+lVvjuwE3gShPAFPc2joqHrqQkZPrfOMHyxNPWBjmd06G mJaov5ZMGAQQdvkkJatcCbnrnV2IuYLbZyGpfQAGrjVZ4S5RtU8/2VpksfxRJNDV KrRPS/HoPQrDfJcMnsRxXSpf0dFcG/WptgKFMOlzLPAKiwWZ62dpc/m8ghrHXbzz /x/TaT4NA9m4S3NwFqZYq/kTQwiXtrSU40sPo/QGk6Wn5o4sTcgNDEveJK3KsLI+ p8KQrt7muGMn9FbRrLjwq2VytiLXksXrdFAeWugUon0qEkmxaKiUSNvbgof0/qi3 4DwGQi4FYh6hvSyjckKOVP/y/F8jSg== =1IhX -----END PGP SIGNATURE----- --wRRV7LY7NUeQGEoC--