Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K9i8s-0002sS-L3 for qemu-devel@nongnu.org; Fri, 20 Jun 2008 11:03:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K9i8n-0002rH-Cu for qemu-devel@nongnu.org; Fri, 20 Jun 2008 11:03:09 -0400 Received: from [199.232.76.173] (port=46849 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K9i8n-0002rB-6P for qemu-devel@nongnu.org; Fri, 20 Jun 2008 11:03:05 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:43373) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K9i8m-0004eZ-EE for qemu-devel@nongnu.org; Fri, 20 Jun 2008 11:03:04 -0400 Received: from localhost (localhost [127.0.0.1]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 3B41419DAA1 for ; Fri, 20 Jun 2008 17:02:54 +0200 (CEST) Received: from ecfrec.frec.bull.fr ([127.0.0.1]) by localhost (ecfrec.frec.bull.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13606-03 for ; Fri, 20 Jun 2008 17:02:40 +0200 (CEST) Received: from cyclope.frec.bull.fr (cyclope.frec.bull.fr [129.183.4.9]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 2CF0719D9D9 for ; Fri, 20 Jun 2008 16:38:35 +0200 (CEST) Received: from [129.183.101.63] (frecb007144.frec.bull.fr [129.183.101.63]) by cyclope.frec.bull.fr (Postfix) with ESMTP id A4C0927289 for ; Fri, 20 Jun 2008 16:38:29 +0200 (CEST) From: Laurent Vivier Content-Type: multipart/mixed; boundary="=-E4N1v/JYz0iByWmmNt9I" Date: Fri, 20 Jun 2008 16:38:00 +0200 Message-Id: <1213972680.3859.34.camel@frecb07144> Mime-Version: 1.0 Subject: [Qemu-devel] [PATCH] qcow2: improve I/O performance with cache=off Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" --=-E4N1v/JYz0iByWmmNt9I Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, this patch improves qcow2 I/O performance when used with cache=off. It modifies qcow_aio_[read|write]_cb() to read as many clusters as possible per bdrv_aio_[read|write](). I've made some tests with dbench: WITHOUT PATCH WITH PATCH ide, cache=off,snapshot=off 20.8494 MB/sec 24.0711 MB/sec ide, cache=off,snapshot=on 20.9349 MB/sec 24.5031 MB/sec scsi,cache=off,snapshot=off 21.0264 MB/sec 24.6119 MB/sec scsi,cache=off,snapshot=on 21.4184 MB/sec 24.6739 MB/sec The gain is approximately 15%. Regards, Laurent -- ------------- Laurent.Vivier@bull.net --------------- "The best way to predict the future is to invent it." - Alan Kay --=-E4N1v/JYz0iByWmmNt9I Content-Disposition: attachment; filename=qcow2.patch Content-Type: text/x-patch; name=qcow2.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Index: qemu/block-qcow2.c =================================================================== --- qemu.orig/block-qcow2.c 2008-06-19 14:38:59.000000000 +0200 +++ qemu/block-qcow2.c 2008-06-20 14:23:35.000000000 +0200 @@ -808,6 +808,8 @@ static void qcow_aio_read_cb(void *opaqu BlockDriverState *bs = acb->common.bs; BDRVQcowState *s = bs->opaque; int index_in_cluster, n1; + uint64_t next; + int n; acb->hd_aiocb = NULL; if (ret < 0) { @@ -846,11 +848,22 @@ static void qcow_aio_read_cb(void *opaqu acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, 0, 0, 0, 0); index_in_cluster = acb->sector_num & (s->cluster_sectors - 1); - acb->n = s->cluster_sectors - index_in_cluster; - if (acb->n > acb->nb_sectors) - acb->n = acb->nb_sectors; if (!acb->cluster_offset) { + /* seek how many clusters we must read from the base image */ + n = s->cluster_sectors; + while (n < acb->nb_sectors + index_in_cluster) { + next = get_cluster_offset(bs, (acb->sector_num + n) << 9, + 0, 0, 0, 0); + if (next) + break; + n += s->cluster_sectors; + } + n -= index_in_cluster; + if (n > acb->nb_sectors) + n = acb->nb_sectors; + acb->n = n; + if (bs->backing_hd) { /* read from the base image */ n1 = backing_read1(bs->backing_hd, acb->sector_num, @@ -869,6 +882,9 @@ static void qcow_aio_read_cb(void *opaqu goto redo; } } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) { + acb->n = s->cluster_sectors - index_in_cluster; + if (acb->n > acb->nb_sectors) + acb->n = acb->nb_sectors; /* add AIO support for compressed blocks ? */ if (decompress_cluster(s, acb->cluster_offset) < 0) goto fail; @@ -880,6 +896,22 @@ static void qcow_aio_read_cb(void *opaqu ret = -EIO; goto fail; } + + /* seek how many clusters we can read */ + + n = s->cluster_sectors; + while (n < acb->nb_sectors + index_in_cluster) { + next = get_cluster_offset(bs, (acb->sector_num + n) << 9, + 0, 0, 0, 0); + if (next != acb->cluster_offset + (n << 9)) + break; + n += s->cluster_sectors; + } + n -= index_in_cluster; + if (n > acb->nb_sectors) + n = acb->nb_sectors; + acb->n = n; + acb->hd_aiocb = bdrv_aio_read(s->hd, (acb->cluster_offset >> 9) + index_in_cluster, acb->buf, acb->n, qcow_aio_read_cb, acb); @@ -928,6 +960,9 @@ static void qcow_aio_write_cb(void *opaq int index_in_cluster; uint64_t cluster_offset; const uint8_t *src_buf; + uint64_t next; + int n; + int alloc; acb->hd_aiocb = NULL; @@ -972,6 +1007,25 @@ static void qcow_aio_write_cb(void *opaq acb->n, 1, &s->aes_encrypt_key); src_buf = acb->cluster_data; } else { + + /* seek how many clusters we can write */ + + n = s->cluster_sectors; + while(n < acb->nb_sectors + index_in_cluster) { + alloc = s->cluster_sectors; + if (n + alloc > acb->nb_sectors + index_in_cluster) + alloc = acb->nb_sectors + index_in_cluster - n; + next = get_cluster_offset(bs, (acb->sector_num + n) << 9, + 1, 0, 0, alloc); + if (next != cluster_offset + (n << 9)) + break; + n += alloc; + } + n -= index_in_cluster; + if (n > acb->nb_sectors) + n = acb->nb_sectors; + acb->n = n; + src_buf = acb->buf; } acb->hd_aiocb = bdrv_aio_write(s->hd, --=-E4N1v/JYz0iByWmmNt9I--