From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] qemu-kvm: clear only essential parts of VirtIOBlockReq on object allocation Date: Sun, 08 Nov 2009 15:07:29 +0200 Message-ID: <4AF6C291.90204@redhat.com> References: <41be791c0911040941y3548de23v20959cf1c1300875@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Saul Tamari Return-path: Received: from mx1.redhat.com ([209.132.183.28]:19827 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752968AbZKHNHZ (ORCPT ); Sun, 8 Nov 2009 08:07:25 -0500 In-Reply-To: <41be791c0911040941y3548de23v20959cf1c1300875@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On 11/04/2009 07:41 PM, Saul Tamari wrote: > This patch reduces the size of memory being cleared on every virtio-blk IO. > > On every virtio-blk IO passed to QEMU, virtio_blk_alloc_request() > allocates and clears (with qemu_mallocz()) a VirtIOBlockReq object. > The sizeof(VirtIOBlockReq) equals 41040 bytes on my x86-64 machine. > By moving the 'elem' variable to the end of VirtIOBlockReq and > clearing only upto the address of the 'elem.in_addr' field, the > memset() call now clears only 80 bytes. > > > Signed-off-by: Saul Tamari > Use the full email in signoffs. > @@ -79,12 +79,12 @@ static inline void virtio_identify_template(struct > virtio_blk_config *bc) > typedef struct VirtIOBlockReq > { > VirtIOBlock *dev; > - VirtQueueElement elem; > struct virtio_blk_inhdr *in; > struct virtio_blk_outhdr *out; > struct virtio_scsi_inhdr *scsi; > QEMUIOVector qiov; > struct VirtIOBlockReq *next; > + VirtQueueElement elem; > } VirtIOBlockReq; > Needs a comment to indicate new members must be before 'elem' if they need to be cleared. > static void virtio_blk_req_complete(VirtIOBlockReq *req, int status) > @@ -139,7 +139,8 @@ static void virtio_blk_flush_complete(void *opaque, int ret) > > static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s) > { > - VirtIOBlockReq *req = qemu_mallocz(sizeof(*req)); > + VirtIOBlockReq *req = qemu_malloc(sizeof(*req)); > + memset(req, 0, (size_t)&(((VirtIOBlockReq*)0)->elem.in_addr[0])); > Please use offsetof() instead of open-coding it. Submit to qemu-devel@nongnu.org since this came from upstream. -- error compiling committee.c: too many arguments to function