From nobody Thu May 2 10:32:44 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 1490693097031633.2287836239842; Tue, 28 Mar 2017 02:24:57 -0700 (PDT) Received: from localhost ([::1]:51915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csnN1-0005IP-Mq for importer@patchew.org; Tue, 28 Mar 2017 05:24:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csnMB-0004f4-AF for qemu-devel@nongnu.org; Tue, 28 Mar 2017 05:24:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csnM7-0002PK-Bm for qemu-devel@nongnu.org; Tue, 28 Mar 2017 05:24:03 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:33308) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1csnM7-0002P0-5q; Tue, 28 Mar 2017 05:23:59 -0400 Received: by mail-pg0-x242.google.com with SMTP id 79so19929611pgf.0; Tue, 28 Mar 2017 02:23:58 -0700 (PDT) Received: from localhost.localdomain ([123.206.110.226]) by smtp.gmail.com with ESMTPSA id 194sm6041312pfx.134.2017.03.28.02.23.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 02:23:57 -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=S5lqrHwZr30hgv1u7gRVncKA+K5XJ6mskEJ3ge9JT6M=; b=fkHK8FJvUxr9T/tG8LqPNqlYlirBMe/z7+0KH9Rj+seHdW+fT0ieycgWCCmZ/WG1sS uYuVdCjNPBSGnIUdFUYFol/5HugrCF8JdFOLCbep+NoZNJT1D33Ycslpjxnqct9o44T4 l3Tbzbb3AE2GGV4zrAcP7C+s4c2bnKzfF1UFiM/pObenAkILf/eL8aTj5gIwCV+SNwAM 10sHBbfffa7mc2DNdlXXstETbn5xSYmwAGXafzpUewPIGHs/Uf3z8fMRmy3uSY+i//YU cC/+YlaufxjnResc7y1auV9EtzF9HbcJY3at7emWG+EfeVOdyO4F5f7lLjG1qy3deWjv WT3Q== 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=S5lqrHwZr30hgv1u7gRVncKA+K5XJ6mskEJ3ge9JT6M=; b=OudqNk0jbyrsM7M6wiTRDRDWfTREj0xBoV03S6cJKwKMcw+gee0Ipjk4llOeYJpSqw q8Nk4JztyR1vVmsHFank5KHrGBZ/MB3XSxIANbOGye4TNNs0Wey1F9SRZ2U0kiZIMCYV rAbgwNWhFuS8KvUoJOI/PZkryf4vhoB1TULJ27bXsNGGn9HNMw71YDxOj+SHpjoxZd71 JvQMbisVh4FTMcRiK15rwsMJTbCmVeIvtxgPgGllEfqEXJrQ0CzYw+KOSVWdT/H9MMmU z6dMk98EpI6FBe1IBQVLjH3y1Sf6XBqPI87dQ4ISYBtwUPLUjEwi9SWjywJl16Qq83um 3T4Q== X-Gm-Message-State: AFeK/H2rkSCvImOeziE1roDV3C5+lY3nm1Vp0CPkL2vaM9o3t3ZWTpA5+kRMmAropcwlSg== X-Received: by 10.84.138.193 with SMTP id 59mr35343885plp.167.1490693038048; Tue, 28 Mar 2017 02:23:58 -0700 (PDT) From: Lidong Chen X-Google-Original-From: Lidong Chen To: qemu-devel@nongnu.org Date: Tue, 28 Mar 2017 17:23:29 +0800 Message-Id: <1490693009-10037-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:c05::242 Subject: [Qemu-devel] [RFC] 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" when migration with quick 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 | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/migration/block.c b/migration/block.c index 7734ff7..d3e81ca 100644 --- a/migration/block.c +++ b/migration/block.c @@ -110,6 +110,7 @@ typedef struct BlkMigState { int transferred; int prev_progress; int bulk_completed; + int time_ns_used; =20 /* Lock must be taken _inside_ the iothread lock and any AioContexts. = */ QemuMutex lock; @@ -263,6 +264,7 @@ static void blk_mig_read_cb(void *opaque, int ret) blk_mig_unlock(); } =20 +#define BILLION 1000000000L /* Called with no lock taken. */ =20 static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) @@ -272,16 +274,33 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDe= vState *bmds) BlockBackend *bb =3D bmds->blk; BlkMigBlock *blk; int nr_sectors; + struct timespec ts1, ts2; + int ret =3D 0; + int timeout_flag =3D 0; =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) { + clock_gettime(CLOCK_MONOTONIC_RAW, &ts1); + ret =3D bdrv_is_allocated(blk_bs(bb), cur_sector, + MAX_IS_ALLOCATED_SEARCH, &nr_sectors); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts2); + + block_mig_state.time_ns_used +=3D (ts2.tv_sec - ts1.tv_sec) * = BILLION + + (ts2.tv_nsec - ts1.tv_nsec); + + if (!ret) { + cur_sector +=3D nr_sectors; + if (block_mig_state.time_ns_used > 100000) { + timeout_flag =3D 1; + break; + } + } else { + break; + } } aio_context_release(blk_get_aio_context(bb)); qemu_mutex_unlock_iothread(); @@ -292,6 +311,11 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDev= State *bmds) return 1; } =20 + if (timeout_flag =3D=3D 1) { + 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); @@ -576,9 +600,6 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDev= State *bmds, } =20 bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, sector, nr_sectors= ); - sector +=3D nr_sectors; - bmds->cur_dirty =3D sector; - break; } sector +=3D BDRV_SECTORS_PER_DIRTY_CHUNK; @@ -756,6 +777,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 +786,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 100000) { blk_mig_unlock(); if (block_mig_state.bulk_completed =3D=3D 0) { /* first finish the bulk phase */ --=20 1.8.3.1