From patchwork Fri May 5 08:03:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 858585 jemmy X-Patchwork-Id: 9713139 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 B77D460362 for ; Fri, 5 May 2017 08:04:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BEE1286A8 for ; Fri, 5 May 2017 08:04:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 903B4286BB; Fri, 5 May 2017 08:04:50 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 26D57286A8 for ; Fri, 5 May 2017 08:04:50 +0000 (UTC) Received: from localhost ([::1]:45586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6YEL-0000M6-Gm for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 May 2017 04:04:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6YDe-0000M0-QW for qemu-devel@nongnu.org; Fri, 05 May 2017 04:04:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6YDZ-00006G-UA for qemu-devel@nongnu.org; Fri, 05 May 2017 04:04:06 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34256) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6YDZ-00005R-Ny; Fri, 05 May 2017 04:04:01 -0400 Received: by mail-pf0-x241.google.com with SMTP id d1so5201106pfe.1; Fri, 05 May 2017 01:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PAmeD59Y2T2I0A5amB38ixXk9KcUvreikYYdiabQqa0=; b=rl215IBFBE7DvcdVxLJfgJLxnYkduM2FH4b86/hw0KYb31YyFWpKWRVHFLG1SqgyPo 295QXxQLAp7kBaVEM1wTSfOeOAI47zdL4HLiySPhNVbh/OS+YD8DZeTXYcH+Dt3U1wZx CB092o3dxXJkHy4rCs7Bsae10V6MUsaabZltiswOCG1iGMv1ed0kzaGdmCp0SM3qoxsk TLAPu8Y3kiRgnKZ97ohR3kA/Z/ttf+WKXnCCRYJycvuhfL2DOtxETWHVTbwDa7jKWcNU 1QivTlpCkUuU5gNI6D2Tos/N3BQq4AUHvEJYh/mXMz2bxkIvSu0xHUubnXRhNR8XUtZE 3cKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PAmeD59Y2T2I0A5amB38ixXk9KcUvreikYYdiabQqa0=; b=NBHCZ1bjCMmXT9Eu5fvxP3KHfcRreCcJ9hiGeaGgvlqeGKccMiq2wBZYZLtPmG/q7A sIO/vcmWNqMgzs11mYheymg8XTMHl0gtN0JbnUG7og3O3/h7iv3CTzlmf8NpcJ+Udhxo 5t/O78Vne17XbpHfqxDk99RFUjcPj/rUdNblu+7aMVBefOQ6iWmPlsepiQ0Lhgiv53IS XlJt8B1BrW0wnD0EmLoD0KcgvQn/uSBzYsJaXXPJv/zbC2/CtX8EYyUamX+aFz7KMF4m kJmEJKBHyamxWQCwD8a6jWmzM+UoqE+NHihFRHUGgwuHGOOrfzvgfQdDO/GWTsarML/G wxRQ== X-Gm-Message-State: AN3rC/7a9+ZM+vzFWqcXbyZaNVAcGOLN9PMf5LztceP0I+jRLgl2WCQA Cmcr7LR9rbVwXkEg X-Received: by 10.98.152.215 with SMTP id d84mr15471842pfk.7.1493971438812; Fri, 05 May 2017 01:03:58 -0700 (PDT) Received: from localhost.localdomain ([119.28.70.25]) by smtp.gmail.com with ESMTPSA id q16sm7290901pfk.12.2017.05.05.01.03.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2017 01:03:58 -0700 (PDT) From: jemmy858585@gmail.com X-Google-Original-From: lidongchen@tencent.com To: qemu-devel@nongnu.org Date: Fri, 5 May 2017 16:03:49 +0800 Message-Id: <1493971429-10441-1-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH v4] migration/block: move bdrv_is_allocated() into bb's AioContext 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: famz@redhat.com, qemu-block@nongnu.org, quintela@redhat.com, dgilbert@redhat.com, stefanha@redhat.com, Lidong Chen Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lidong Chen when block migration with high-speed, mig_save_device_bulk hold the BQL and invoke bdrv_is_allocated frequently. This patch moves bdrv_is_allocated() into bb's AioContext. It will execute without blocking other I/O activity. Signed-off-by: Lidong Chen --- v4 changelog: Use the prototype code written by Stefan and fix some bug. moves bdrv_is_allocated() into bb's AioContext. --- migration/block.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/migration/block.c b/migration/block.c index 060087f..c871361 100644 --- a/migration/block.c +++ b/migration/block.c @@ -263,6 +263,30 @@ static void blk_mig_read_cb(void *opaque, int ret) blk_mig_unlock(); } +typedef struct { + int64_t *total_sectors; + int64_t *cur_sector; + BlockBackend *bb; + QemuEvent event; +} MigNextAllocatedClusterData; + +static void coroutine_fn mig_next_allocated_cluster(void *opaque) +{ + MigNextAllocatedClusterData *data = opaque; + int nr_sectors; + + /* Skip unallocated sectors; intentionally treats failure as + * an allocated sector */ + while (*data->cur_sector < *data->total_sectors && + !bdrv_is_allocated(blk_bs(data->bb), *data->cur_sector, + MAX_IS_ALLOCATED_SEARCH, &nr_sectors)) { + *data->cur_sector += nr_sectors; + } + + bdrv_dec_in_flight(blk_bs(data->bb)); + qemu_event_set(&data->event); +} + /* Called with no lock taken. */ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) @@ -274,17 +298,23 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) int nr_sectors; if (bmds->shared_base) { + AioContext *bb_ctx; + Coroutine *co; + MigNextAllocatedClusterData data = { + .cur_sector = &cur_sector, + .total_sectors = &total_sectors, + .bb = bb, + }; + qemu_event_init(&data.event, false); + qemu_mutex_lock_iothread(); - aio_context_acquire(blk_get_aio_context(bb)); - /* Skip unallocated sectors; intentionally treats failure as - * an allocated sector */ - while (cur_sector < total_sectors && - !bdrv_is_allocated(blk_bs(bb), cur_sector, - MAX_IS_ALLOCATED_SEARCH, &nr_sectors)) { - cur_sector += nr_sectors; - } - aio_context_release(blk_get_aio_context(bb)); + bdrv_inc_in_flight(blk_bs(bb)); + bb_ctx = blk_get_aio_context(bb); + co = qemu_coroutine_create(mig_next_allocated_cluster, &data); + aio_co_schedule(bb_ctx, co); qemu_mutex_unlock_iothread(); + + qemu_event_wait(&data.event); } if (cur_sector >= total_sectors) {