From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N7YhO-0008HH-2C for qemu-devel@nongnu.org; Mon, 09 Nov 2009 13:10:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N7YhJ-0008B1-Bf for qemu-devel@nongnu.org; Mon, 09 Nov 2009 13:10:41 -0500 Received: from [199.232.76.173] (port=55098 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7YhI-0008AT-T8 for qemu-devel@nongnu.org; Mon, 09 Nov 2009 13:10:37 -0500 Received: from mail-ew0-f206.google.com ([209.85.219.206]:39688) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N7Yba-0004hB-8A for qemu-devel@nongnu.org; Mon, 09 Nov 2009 13:04:42 -0500 Received: by ewy2 with SMTP id 2so1445855ewy.34 for ; Mon, 09 Nov 2009 10:04:40 -0800 (PST) MIME-Version: 1.0 Date: Mon, 9 Nov 2009 20:04:34 +0200 Message-ID: <41be791c0911091004x62d30fbey91ef730475ba3571@mail.gmail.com> From: Saul Tamari Content-Type: text/plain; charset=ISO-8859-1 Subject: [Qemu-devel] [PATCH] qemu-kvm: clear only essential parts of VirtIOBlockReq on object allocation - RESUBMIT List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kvm@vger.kernel.org This patch reduces the size of memory being cleared on every virtio-blk IO. Improve number of IOPS when using avirtio-blk device. On every virtio-blk IO command 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 --- diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 2630b99..de74b00 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -79,12 +79,13 @@ 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; + /* Members that need clearing, must be added prior to elem */ + VirtQueueElement elem; } VirtIOBlockReq; static void virtio_blk_req_complete(VirtIOBlockReq *req, int status) @@ -139,7 +140,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, offsetof(VirtIOBlockReq, elem.in_addr[0])); req->dev = s; return req; }