From nobody Sun Apr 28 06:14:17 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 1491384547852831.6980015368919; Wed, 5 Apr 2017 02:29:07 -0700 (PDT) Received: from localhost ([::1]:39561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvhFS-0004sG-1m for importer@patchew.org; Wed, 05 Apr 2017 05:29:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvhEj-0004YB-Jv for qemu-devel@nongnu.org; Wed, 05 Apr 2017 05:28:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvhEf-0004zi-Jf for qemu-devel@nongnu.org; Wed, 05 Apr 2017 05:28:21 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:33410) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvhEf-0004zW-Dw; Wed, 05 Apr 2017 05:28:17 -0400 Received: by mail-pf0-x241.google.com with SMTP id 197so1167420pfv.0; Wed, 05 Apr 2017 02:28:17 -0700 (PDT) Received: from localhost.localdomain ([123.206.110.226]) by smtp.gmail.com with ESMTPSA id i3sm36345646pfg.117.2017.04.05.02.28.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:28:15 -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=u3QhWWotuH18bdQQ948P7fmjRtJhESt/ReEdPpH7iZs=; b=r9q+LM1JuvzWIKK/0MehAlHNPJof1cvKWhsZnKtBcodA3H02l4hjsJtLdRB1sUg1NB sFjJ1LXXEn6SS2QvTvAodKbXHMN2LHGZJ3p9r69wBr5cYIZadnXHT9uCMLephx9kQGUJ 4fN0Lwm+vBZIug7jYngUdXl7wJBKqbx2wNKGxnllKg6MXLwr94qXV4do8sentFaPmjCN qIopgt6UXiPywd8t29ihz5LzM8mi3knqFOikn8jWYp4cFWgHnwExGDnKOEUF+MJVuZ7P LWJL85tNyaaMkAWg/YTvQ4kMWtg4WRP+LWOX7VEVpZghEu0B4qCzJLAXgbEVGiikq1i3 h/qA== 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=u3QhWWotuH18bdQQ948P7fmjRtJhESt/ReEdPpH7iZs=; b=IsQ04W8RGyw5VIGPjS6CJ/cnWwonsuPF5yMjeGZTcjaAQ6rzOGb5HVXJdsBuXeZSoH uZ6OzLo4ctkwMBKQisS62RELtGDTXusQ+Cn1B80fInkXcbp6hR2iXfk1g8lJOe849RZA ecGdaOffP4FxFY2omlX8CgcSrNYwiVc2OPOhSGJNEXkUX9uhvNmMV0ethmNEqvKzTAum +DYenKn9EHEL8JGpb/ziDgyHL9IF7GPJVb0rreLCHa8qgjDOoviTTFK/SqvqL1TThQE8 skdTaiirWzHdcDxDERFziK8QUopZfD5eSnD+yOghKl+zAZShJURPubrWnn/uBdHkw9bV vyLw== X-Gm-Message-State: AFeK/H24nXdOkanYljhwBwHgVjH//QaHx0cLF5tNfx3jmsBD9YdYcATeEhBls7aGBwB6Tg== X-Received: by 10.99.54.69 with SMTP id d66mr28349779pga.116.1491384496210; Wed, 05 Apr 2017 02:28:16 -0700 (PDT) From: jemmy858585@gmail.com X-Google-Original-From: lidongchen@tencent.com To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 17:27:58 +0800 Message-Id: <1491384478-12325-1-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH v3] migration/block:limit the time used for block migration 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 migration with high speed, mig_save_device_bulk invoke bdrv_is_allocated too frequently, and cause vnc reponse slowly. this patch limit the time used for bdrv_is_allocated. Signed-off-by: Lidong Chen --- migration/block.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/migration/block.c b/migration/block.c index 7734ff7..dbce931 100644 --- a/migration/block.c +++ b/migration/block.c @@ -39,6 +39,7 @@ #define MAX_IS_ALLOCATED_SEARCH 65536 =20 #define MAX_INFLIGHT_IO 512 +#define BIG_DELAY 500000 =20 //#define DEBUG_BLK_MIGRATION =20 @@ -110,6 +111,7 @@ typedef struct BlkMigState { int transferred; int prev_progress; int bulk_completed; + int64_t time_ns_used; =20 /* Lock must be taken _inside_ the iothread lock and any AioContexts. = */ QemuMutex lock; @@ -272,16 +274,32 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDe= vState *bmds) BlockBackend *bb =3D bmds->blk; BlkMigBlock *blk; int nr_sectors; + uint64_t ts1, ts2; + int ret =3D 0; + bool timeout_flag =3D false; =20 if (bmds->shared_base) { 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; + while (cur_sector < total_sectors) { + ts1 =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + ret =3D bdrv_is_allocated(blk_bs(bb), cur_sector, + MAX_IS_ALLOCATED_SEARCH, &nr_sectors); + ts2 =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + + block_mig_state.time_ns_used +=3D ts2 - ts1; + + if (!ret) { + cur_sector +=3D nr_sectors; + if (block_mig_state.time_ns_used > BIG_DELAY) { + timeout_flag =3D true; + break; + } + } else { + break; + } } aio_context_release(blk_get_aio_context(bb)); qemu_mutex_unlock_iothread(); @@ -292,6 +310,11 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDev= State *bmds) return 1; } =20 + if (timeout_flag) { + bmds->cur_sector =3D bmds->completed_sectors =3D cur_sector; + return 0; + } + bmds->completed_sectors =3D cur_sector; =20 cur_sector &=3D ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1); @@ -756,6 +779,7 @@ static int block_save_iterate(QEMUFile *f, void *opaque) } =20 blk_mig_reset_dirty_cursor(); + block_mig_state.time_ns_used =3D 0; =20 /* control the rate of transfer */ blk_mig_lock(); @@ -764,7 +788,8 @@ static int block_save_iterate(QEMUFile *f, void *opaque) qemu_file_get_rate_limit(f) && (block_mig_state.submitted + block_mig_state.read_done) < - MAX_INFLIGHT_IO) { + MAX_INFLIGHT_IO && + block_mig_state.time_ns_used <=3D BIG_DELAY) { blk_mig_unlock(); if (block_mig_state.bulk_completed =3D=3D 0) { /* first finish the bulk phase */ --=20 1.8.3.1