From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=57884 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgIjI-00069J-JZ for qemu-devel@nongnu.org; Tue, 03 Aug 2010 10:44:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgIjH-0004F9-GT for qemu-devel@nongnu.org; Tue, 03 Aug 2010 10:44:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17838) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgIjH-0004Ez-8X for qemu-devel@nongnu.org; Tue, 03 Aug 2010 10:44:31 -0400 From: Kevin Wolf Date: Tue, 3 Aug 2010 16:44:25 +0200 Message-Id: <1280846670-27063-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1280846670-27063-1-git-send-email-kwolf@redhat.com> References: <1280846670-27063-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/6] block: Change bdrv_commit to handle multiple sectors at once List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org bdrv_commit copies the image to its backing file sector by sector, which is (surprise!) relatively slow. Let's take a larger buffer and handle more sectors at once if possible. With a 1G qcow2 file, this brought the time bdrv_commit takes down from 5:06 min to 1:14 min for me. Signed-off-by: Kevin Wolf --- block.c | 39 ++++++++++++++++++++------------------- 1 files changed, 20 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index 452ae94..c4d6814 100644 --- a/block.c +++ b/block.c @@ -739,14 +739,16 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res) return bs->drv->bdrv_check(bs, res); } +#define COMMIT_BUF_SECTORS 2048 + /* commit COW file into the raw image */ int bdrv_commit(BlockDriverState *bs) { BlockDriver *drv = bs->drv; - int64_t i, total_sectors; - int n, j, ro, open_flags; + int64_t sector, total_sectors; + int n, ro, open_flags; int ret = 0, rw_ret = 0; - unsigned char sector[BDRV_SECTOR_SIZE]; + uint8_t *buf; char filename[1024]; BlockDriverState *bs_rw, *bs_ro; @@ -789,22 +791,20 @@ int bdrv_commit(BlockDriverState *bs) } total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; - for (i = 0; i < total_sectors;) { - if (drv->bdrv_is_allocated(bs, i, 65536, &n)) { - for(j = 0; j < n; j++) { - if (bdrv_read(bs, i, sector, 1) != 0) { - ret = -EIO; - goto ro_cleanup; - } + buf = qemu_malloc(COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); - if (bdrv_write(bs->backing_hd, i, sector, 1) != 0) { - ret = -EIO; - goto ro_cleanup; - } - i++; - } - } else { - i += n; + for (sector = 0; sector < total_sectors; sector += n) { + if (drv->bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n)) { + + if (bdrv_read(bs, sector, buf, n) != 0) { + ret = -EIO; + goto ro_cleanup; + } + + if (bdrv_write(bs->backing_hd, sector, buf, n) != 0) { + ret = -EIO; + goto ro_cleanup; + } } } @@ -821,6 +821,7 @@ int bdrv_commit(BlockDriverState *bs) bdrv_flush(bs->backing_hd); ro_cleanup: + qemu_free(buf); if (ro) { /* re-open as RO */ -- 1.7.2