From patchwork Fri Jul 16 16:17:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 59114 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E8623B6F14 for ; Sat, 17 Jul 2010 02:20:09 +1000 (EST) Received: from localhost ([127.0.0.1]:37926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OZndu-0007eb-DW for incoming@patchwork.ozlabs.org; Fri, 16 Jul 2010 12:20:06 -0400 Received: from [140.186.70.92] (port=50548 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OZnbd-0006zU-L3 for qemu-devel@nongnu.org; Fri, 16 Jul 2010 12:17:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OZnbc-0005V2-1e for qemu-devel@nongnu.org; Fri, 16 Jul 2010 12:17:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65186) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OZnbb-0005UE-RF for qemu-devel@nongnu.org; Fri, 16 Jul 2010 12:17:44 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6GGHeou012496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Jul 2010 12:17:40 -0400 Received: from dhcp-5-188.str.redhat.com (vpn2-8-96.ams2.redhat.com [10.36.8.96]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6GGHc7I027822; Fri, 16 Jul 2010 12:17:38 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 16 Jul 2010 18:17:36 +0200 Message-Id: <1279297056-13392-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH] block: Change bdrv_commit to handle multiple sectors at once X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 | 35 ++++++++++++++++++----------------- 1 files changed, 18 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index 65cf4dc..12dbc43 100644 --- a/block.c +++ b/block.c @@ -729,9 +729,9 @@ int bdrv_commit(BlockDriverState *bs) { BlockDriver *drv = bs->drv; int64_t i, total_sectors; - int n, j, ro, open_flags; + 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; @@ -774,25 +774,26 @@ int bdrv_commit(BlockDriverState *bs) } total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; + buf = qemu_malloc(2048 * BDRV_SECTOR_SIZE); + 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; - } + if (drv->bdrv_is_allocated(bs, i, 2048, &n)) { - if (bdrv_write(bs->backing_hd, i, sector, 1) != 0) { - ret = -EIO; - goto ro_cleanup; - } - i++; - } - } else { - i += n; + if (bdrv_read(bs, i, buf, n) != 0) { + ret = -EIO; + goto ro_cleanup; + } + + if (bdrv_write(bs->backing_hd, i, buf, n) != 0) { + ret = -EIO; + goto ro_cleanup; + } } + i += n; } + qemu_free(buf); + if (drv->bdrv_make_empty) { ret = drv->bdrv_make_empty(bs); bdrv_flush(bs);