From nobody Wed May 1 22:41:19 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.zohomail.com; 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 1501123192069407.39783921738274; Wed, 26 Jul 2017 19:39:52 -0700 (PDT) Received: from localhost ([::1]:40836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daYiM-0004Ez-2i for importer@patchew.org; Wed, 26 Jul 2017 22:39:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daYhG-0003QD-Up for qemu-devel@nongnu.org; Wed, 26 Jul 2017 22:38:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1daYhC-0004sZ-Vm for qemu-devel@nongnu.org; Wed, 26 Jul 2017 22:38:43 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:4347) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1daYhC-0004pi-DC for qemu-devel@nongnu.org; Wed, 26 Jul 2017 22:38:38 -0400 Received: from 172.30.72.56 (EHLO dggeml406-hub.china.huawei.com) ([172.30.72.56]) by dggrg03-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id ASF78979; Thu, 27 Jul 2017 10:38:16 +0800 (CST) Received: from localhost (10.177.19.14) by dggeml406-hub.china.huawei.com (10.3.17.50) with Microsoft SMTP Server id 14.3.301.0; Thu, 27 Jul 2017 10:38:04 +0800 From: Jay Zhou To: Date: Thu, 27 Jul 2017 10:36:14 +0800 Message-ID: <1501122974-18860-1-git-send-email-jianjay.zhou@huawei.com> X-Mailer: git-send-email 2.6.1.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.19.14] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.59795219.0113, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: dabd9307d85463a57ae435592243f652 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.189 Subject: [Qemu-devel] [PATCH v2] migration: optimize the downtime 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: weidong.huang@huawei.com, zhang.zhanghailiang@huawei.com, wangxinxin.wang@huawei.com, xiaoguangrong@tencent.com, dgilbert@redhat.com, arei.gonglei@huawei.com, huangzhichao@huawei.com, Jay Zhou , pbonzini@redhat.com, jdenemar@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Qemu_savevm_state_cleanup takes about 300ms in my ram migration tests with a 8U24G vm(20G is really occupied), the main cost comes from KVM_SET_USER_MEMORY_REGION ioctl when mem.memory_size =3D 0 in kvm_set_user_memory_region. In kmod, the main cost is kvm_zap_obsolete_pages, which traverses the active_mmu_pages list to zap the unsync sptes. It can be optimized by delaying memory_global_dirty_log_stop to the next vm_start. Changes v1->v2: - create a VMChangeStateHandler in memory.c to reduce the coupling [Paolo] Signed-off-by: Jay Zhou --- memory.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/memory.c b/memory.c index a7bc70a..4c22b7e 100644 --- a/memory.c +++ b/memory.c @@ -2357,8 +2357,14 @@ void memory_global_dirty_log_sync(void) } } =20 +static VMChangeStateEntry *vmstate_change; + void memory_global_dirty_log_start(void) { + if (vmstate_change) { + qemu_del_vm_change_state_handler(vmstate_change); + } + global_dirty_log =3D true; =20 MEMORY_LISTENER_CALL_GLOBAL(log_global_start, Forward); @@ -2369,7 +2375,7 @@ void memory_global_dirty_log_start(void) memory_region_transaction_commit(); } =20 -void memory_global_dirty_log_stop(void) +static void memory_global_dirty_log_do_stop(void) { global_dirty_log =3D false; =20 @@ -2381,6 +2387,25 @@ void memory_global_dirty_log_stop(void) MEMORY_LISTENER_CALL_GLOBAL(log_global_stop, Reverse); } =20 +static void memory_vm_change_state_handler(void *opaque, int running, + RunState state) +{ + if (running) { + memory_global_dirty_log_do_stop(); + } +} + +void memory_global_dirty_log_stop(void) +{ + if (!runstate_is_running()) { + vmstate_change =3D qemu_add_vm_change_state_handler( + memory_vm_change_state_handler, NULL); + return; + } + + memory_global_dirty_log_do_stop(); +} + static void listener_add_address_space(MemoryListener *listener, AddressSpace *as) { --=20 1.8.3.1