Received: from eggs.gnu.org ([2001:4830:134:3::10]:34142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLYcm-00016i-GX for qemu-devel@nongnu.org; Tue, 19 Jan 2016 10:55:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLYcj-0003ID-7j for qemu-devel@nongnu.org; Tue, 19 Jan 2016 10:55:16 -0500 Received: from e06smtp06.uk.ibm.com ([195.75.94.102]:54896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLYci-0003HU-Um for qemu-devel@nongnu.org; Tue, 19 Jan 2016 10:55:13 -0500 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Jan 2016 15:55:11 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2245417D8059 for ; Tue, 19 Jan 2016 15:55:07 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0JFt1qx52166682 for ; Tue, 19 Jan 2016 15:55:02 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0JFt1vI018469 for ; Tue, 19 Jan 2016 10:55:01 -0500 Date: Tue, 19 Jan 2016 16:54:58 +0100 From: Cornelia Huck Message-ID: <20160119165458.0afc3bb8.cornelia.huck@de.ibm.com> In-Reply-To: <1452861718-25806-6-git-send-email-pbonzini@redhat.com> References: <1452861718-25806-1-git-send-email-pbonzini@redhat.com> <1452861718-25806-6-git-send-email-pbonzini@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 05/10] virtio: slim down allocation of VirtQueueElements List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, mst@redhat.com On Fri, 15 Jan 2016 13:41:53 +0100 Paolo Bonzini wrote: > Build the addresses and s/g lists on the stack, and then copy them > to a VirtQueueElement that is just as big as required to contain this > particular s/g list. The cost of the copy is minimal compared to that > of a large malloc. > > When virtqueue_map is used on the destination side of migration or on > loadvm, the iovecs have already been split at memory region boundary, > so we can just reuse the out_num/in_num we find in the file. > > Signed-off-by: Paolo Bonzini > --- > hw/virtio/virtio.c | 82 +++++++++++++++++++++++++++++++++--------------------- > 1 file changed, 51 insertions(+), 31 deletions(-) > > /* Collect all the descriptors */ > do { > - struct iovec *sg; > + hwaddr pa = vring_desc_addr(vdev, desc_pa, i); > + size_t len = vring_desc_len(vdev, desc_pa, i); > > if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_WRITE) { > - if (elem->in_num >= VIRTQUEUE_MAX_SIZE) { > - error_report("Too many write descriptors in indirect table"); > - exit(1); > - } > - elem->in_addr[elem->in_num] = vring_desc_addr(vdev, desc_pa, i); > - sg = &elem->in_sg[elem->in_num++]; > + virtqueue_map_desc(&in_num, addr + out_num, iov + out_num, > + VIRTQUEUE_MAX_SIZE - out_num, 1, pa, len); Minor nit: I'd probably use 'true' here... > } else { > - if (elem->out_num >= VIRTQUEUE_MAX_SIZE) { > - error_report("Too many read descriptors in indirect table"); > + if (in_num) { > + error_report("Incorrect order for descriptors"); > exit(1); > } > - elem->out_addr[elem->out_num] = vring_desc_addr(vdev, desc_pa, i); > - sg = &elem->out_sg[elem->out_num++]; > + virtqueue_map_desc(&out_num, addr, iov, > + VIRTQUEUE_MAX_SIZE, 0, pa, len); ...and 'false' here. > } > > - sg->iov_len = vring_desc_len(vdev, desc_pa, i); > - > /* If we've got too many, that implies a descriptor loop. */ > - if ((elem->in_num + elem->out_num) > max) { > + if ((in_num + out_num) > max) { > error_report("Looped descriptor"); > exit(1); > } > } while ((i = virtqueue_next_desc(vdev, desc_pa, i, max)) != max); Reviewed-by: Cornelia Huck