From patchwork Wed Jul 20 00:20:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 650517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rvHqT6xxpz9stY for ; Wed, 20 Jul 2016 10:29:57 +1000 (AEST) Received: from localhost ([::1]:59737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPfOd-0004l6-Sh for incoming@patchwork.ozlabs.org; Tue, 19 Jul 2016 20:29:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPfGP-0000Qf-DT for qemu-devel@nongnu.org; Tue, 19 Jul 2016 20:21:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPfGO-0000rv-Fn for qemu-devel@nongnu.org; Tue, 19 Jul 2016 20:21:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36638) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPfGI-0000qP-J4; Tue, 19 Jul 2016 20:21:18 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3CBAB44816; Wed, 20 Jul 2016 00:21:18 +0000 (UTC) Received: from localhost (ovpn-112-23.phx2.redhat.com [10.3.112.23]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6K0LG9U009174 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Tue, 19 Jul 2016 20:21:17 -0400 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 19 Jul 2016 20:20:55 -0400 Message-Id: <1468974062-7726-8-git-send-email-jcody@redhat.com> In-Reply-To: <1468974062-7726-1-git-send-email-jcody@redhat.com> References: <1468974062-7726-1-git-send-email-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 20 Jul 2016 00:21:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/14] mirror: efficiently zero out target X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Denis V. Lunev" With a bdrv_co_write_zeroes method on a target BDS and when this method is working as indicated by the bdrv_can_write_zeroes_with_unmap(), zeroes will not be placed into the wire. Thus the target could be very efficiently zeroed out. This should be done with the largest chunk possible. Signed-off-by: Denis V. Lunev Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Message-id: 1468503209-19498-8-git-send-email-den@openvz.org CC: Stefan Hajnoczi CC: Kevin Wolf CC: Max Reitz CC: Jeff Cody CC: Eric Blake Signed-off-by: Jeff Cody --- block/mirror.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index b7b1ded..0262b03 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -538,8 +538,32 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) end = s->bdev_length / BDRV_SECTOR_SIZE; if (base == NULL && !bdrv_has_zero_init(target_bs)) { - bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, end); - return 0; + if (!bdrv_can_write_zeroes_with_unmap(target_bs)) { + bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, end); + return 0; + } + + for (sector_num = 0; sector_num < end; ) { + int nb_sectors = MIN(end - sector_num, + QEMU_ALIGN_DOWN(INT_MAX, s->granularity) >> BDRV_SECTOR_BITS); + + mirror_throttle(s); + + if (block_job_is_cancelled(&s->common)) { + return 0; + } + + if (s->in_flight >= MAX_IN_FLIGHT) { + trace_mirror_yield(s, s->in_flight, s->buf_free_count, -1); + mirror_wait_for_io(s); + continue; + } + + mirror_do_zero_or_discard(s, sector_num, nb_sectors, false); + sector_num += nb_sectors; + } + + mirror_drain(s); } /* First part, loop on the sectors and initialize the dirty bitmap. */