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: 9238581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3FE676075D for ; Wed, 20 Jul 2016 00:29:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C8C926253 for ; Wed, 20 Jul 2016 00:29:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F41626B4A; Wed, 20 Jul 2016 00:29:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BAD2926253 for ; Wed, 20 Jul 2016 00:29:16 +0000 (UTC) Received: from localhost ([::1]:59734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPfNz-0002gH-Pd for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 20:29:15 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. */