From nobody Sat Apr 27 13:16:50 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 1491382818061692.2630759733602; Wed, 5 Apr 2017 02:00:18 -0700 (PDT) Received: from localhost ([::1]:39406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvgnY-0005G1-K0 for importer@patchew.org; Wed, 05 Apr 2017 05:00:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvgmT-0004aC-AL for qemu-devel@nongnu.org; Wed, 05 Apr 2017 04:59:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvgmQ-0008Bt-5Y for qemu-devel@nongnu.org; Wed, 05 Apr 2017 04:59:09 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:33972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvgmP-0008BZ-Ul; Wed, 05 Apr 2017 04:59:06 -0400 Received: by mail-pf0-x243.google.com with SMTP id o126so1090383pfb.1; Wed, 05 Apr 2017 01:59:05 -0700 (PDT) Received: from localhost.localdomain ([123.206.110.226]) by smtp.gmail.com with ESMTPSA id u129sm36114740pfu.48.2017.04.05.01.58.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 01:59:04 -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=HEPBLdte+sqMYCsQfIXGRDW8YL3H1q3itzxbPbIlw6c=; b=jXFBrEyJ/yXIm+GTcTkHlVXHtmleOt3KrRKk9ef0GSg5N4mbCWQI74F8WMdcvWcVQF v74fTZqVofpZ/2aOHAojXfCDDZw3l0FDZZIQHGv0AhYajmqGTe/ShbyW3IKzbON5G6JS hWsLPbKgnqCEW66KJ9HeDRxINNvymCKaK877seVXLfHhB/gR6DXRWsSwdsG+UKySzEI8 +eGaRGSwdnDhzZO6ITQ71LAGFqCoiVwoXqnjqrKlAs7p+3lksz2vLefHHIE4iuSKRpDx /h7oVD0Yr6EOFU6wKAqs78qWmr44QucXxG7gHGVKVdamGIdnZI/VMnvPohOPEDq2DfEw Slbw== 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=HEPBLdte+sqMYCsQfIXGRDW8YL3H1q3itzxbPbIlw6c=; b=FRLAnKNahg1yMwi6HXP7sgzkcCXO3aDl4kTgbeYmTTTB9lI1+SUC5nTw4WJJ1GcV/A bkC9Q0URyH3AUZCLOZ/lVXAMBtUw29CYdf8rLToGACgAx4IDRezQPH2soXNyEAb4p3i9 jbYMDIaeEFBkMkkPFSnJXHiNR/O1NAN6ryC6gKUzsgXZFtkxFnEeWm0aGGRCtkcaKoRO +DitJzGPqvYHJOcXiJ/aywerQ1lPfzKQmwBOZ/J/Zcyt7++vbMjV1VekJ9tt+Au+Abvm +H5q9yq7INv1MMrNH8RuZbj5fExY8GLZvBpDGuL045PIhwy0nyzTx3W/xdjTFK8N26PD wZuQ== X-Gm-Message-State: AFeK/H1SPtgBSpFZZF/ITi24STSDbSZysFK9pYSp7YAN1xxzJ8HnpL/YpljnC+V86sueOw== X-Received: by 10.84.247.23 with SMTP id n23mr34618660pll.39.1491382744817; Wed, 05 Apr 2017 01:59:04 -0700 (PDT) From: jemmy858585@gmail.com X-Google-Original-From: lidongchen@tencent.com To: qemu-devel@nongnu.org Date: Wed, 5 Apr 2017 16:58:25 +0800 Message-Id: <1491382705-10279-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::243 Subject: [Qemu-devel] [PATCH v2] 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 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 | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/migration/block.c b/migration/block.c index 7734ff7..9d7a8ee 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); @@ -576,9 +599,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 +776,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 +785,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