From nobody Thu May 2 07:46:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493971512541492.82540992619477; Fri, 5 May 2017 01:05:12 -0700 (PDT) Received: from localhost ([::1]:45590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6YEg-0000nL-TT for importer@patchew.org; Fri, 05 May 2017 04:05:10 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(); } =20 +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 =3D 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 +=3D nr_sectors; + } + + bdrv_dec_in_flight(blk_bs(data->bb)); + qemu_event_set(&data->event); +} + /* Called with no lock taken. */ =20 static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) @@ -274,17 +298,23 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDe= vState *bmds) int nr_sectors; =20 if (bmds->shared_base) { + AioContext *bb_ctx; + Coroutine *co; + MigNextAllocatedClusterData data =3D { + .cur_sector =3D &cur_sector, + .total_sectors =3D &total_sectors, + .bb =3D 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 +=3D nr_sectors; - } - aio_context_release(blk_get_aio_context(bb)); + bdrv_inc_in_flight(blk_bs(bb)); + bb_ctx =3D blk_get_aio_context(bb); + co =3D qemu_coroutine_create(mig_next_allocated_cluster, &data); + aio_co_schedule(bb_ctx, co); qemu_mutex_unlock_iothread(); + + qemu_event_wait(&data.event); } =20 if (cur_sector >=3D total_sectors) { --=20 1.8.3.1