From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=60865 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OD2t3-0008Lo-FN for qemu-devel@nongnu.org; Fri, 14 May 2010 17:57:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OD2oC-0002xd-S5 for qemu-devel@nongnu.org; Fri, 14 May 2010 17:52:48 -0400 Received: from mtagate2.de.ibm.com ([195.212.17.162]:52953) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OD2oC-0002wx-KQ for qemu-devel@nongnu.org; Fri, 14 May 2010 17:52:40 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate2.de.ibm.com (8.13.1/8.13.1) with ESMTP id o4ELqarS000754 for ; Fri, 14 May 2010 21:52:36 GMT Received: from d12av03.megacenter.de.ibm.com (d12av03.megacenter.de.ibm.com [9.149.165.213]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o4ELqYKF1654846 for ; Fri, 14 May 2010 23:52:36 +0200 Received: from d12av03.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av03.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o4ELqYKI001546 for ; Fri, 14 May 2010 23:52:34 +0200 From: Stefan Hajnoczi Date: Fri, 14 May 2010 22:52:30 +0100 Message-Id: <1273873950-25756-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] virtio-blk: Avoid zeroing every request structure List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi The VirtIOBlockRequest structure is about 40 KB in size. This patch avoids zeroing every request by only initializing fields that are read. The other fields are either written to or may not be used at all. Oprofile shows about 10% of CPU samples in memset called by virtio_blk_alloc_request(). The workload is dd if=/dev/vda of=/dev/null iflag=direct bs=8k running concurrently 4 times. This patch makes memset disappear to the bottom of the profile. Signed-off-by: Stefan Hajnoczi --- This applies to qemu.git and qemu-kvm.git. A related change would be a pool of requests to avoid malloc/free for every single request. That's a separate change and malloc/free do not show up at the top of the profile, so I am not introducing a pool yet. hw/virtio-blk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index b05d15e..d270225 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -105,8 +105,10 @@ 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)); req->dev = s; + req->qiov.size = 0; + req->next = NULL; return req; } -- 1.7.1