From nobody Mon Feb 9 23:19:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623009047; cv=none; d=zohomail.com; s=zohoarc; b=Q1cQDTMnkzSKuCcSEfFSPAWjUhZFQjPtyNwrfAB2ssWIA83E7F6hjy2Epok3zGLHiHOmUshkv0orl6n6IvMI3Gtb5n+3Ur0o/65ws+nFlzfb2fFzydxt1YsxDHIzeTZReFQ9A3/obsXt5x1VYf0w0ETFN8y3xOvGZUA5PtWK46w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623009047; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UcuerpxZwL3UMrkMEQ1Qc6taq+Ao7HryOB6UdtZVEzY=; b=NHnm9zSnnUsE3gj1kngYN2KHmM6N91hesHN3g+znQpuTDxZCNSWi0D8NkBouFplVFmXyZdYPkEKlTGXqhhU3uBDrlZ+Fb+l1PNFogj7+vEzRLGSAFJFiFiGz8dDHyFddN74MmhSAz8ddeL38VNGMARDvr68ymmx2K/AhA+XG7kE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162300904755488.28755305612822; Sun, 6 Jun 2021 12:50:47 -0700 (PDT) Received: from localhost ([::1]:46786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpynG-0003xh-AS for importer@patchew.org; Sun, 06 Jun 2021 15:50:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpykq-0006zA-Ez for qemu-devel@nongnu.org; Sun, 06 Jun 2021 15:48:16 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.219]:53744 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpyko-00029r-4s for qemu-devel@nongnu.org; Sun, 06 Jun 2021 15:48:16 -0400 Received: from clientip-182.138.181.182?logid-79f23ceaf5444379afae7500096028c7 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id 25B1A28009F; Mon, 7 Jun 2021 03:48:13 +0800 (CST) Received: from ([172.18.0.48]) by app0024 with ESMTP id 79f23ceaf5444379afae7500096028c7 for qemu-devel@nongnu.org; Mon Jun 7 03:48:12 2021 HMM_SOURCE_IP: 172.18.0.48:48410.2126697830 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 79f23ceaf5444379afae7500096028c7 X-filter-score: filter<0> X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 172.18.0.48 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel@nongnu.org Subject: [PATCH v2 5/6] memory: make global_dirty_log a bitmask Date: Mon, 7 Jun 2021 03:48:08 +0800 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.219; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Juan Quintela , Hyman , "Dr. David Alan Gilbert" , Peter Xu , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Hyman Huang(=E9=BB=84=E5=8B=87) dirty rate measurement may start or stop dirty logging during calculation. this conflict with migration because stop dirty log make migration leave dirty pages out then that'll be a problem. make global_dirty_log a bitmask can let both migration and dirty rate measurement work fine. introduce GLOBAL_DIRTY_MIGRATION and GLOBAL_DIRTY_DIRTY_RATE to distinguish what current dirty log aims for, migration or dirty rate. all references to global_dirty_log should be untouched because any bit set there should justify that global dirty logging is enabled. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- include/exec/memory.h | 13 ++++++++++--- migration/ram.c | 8 ++++---- softmmu/memory.c | 36 +++++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index c158fd7084..94c7088299 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -55,7 +55,10 @@ static inline void fuzz_dma_read_cb(size_t addr, } #endif =20 -extern bool global_dirty_log; +#define GLOBAL_DIRTY_MIGRATION (1U<<0) +#define GLOBAL_DIRTY_DIRTY_RATE (1U<<1) + +extern int global_dirty_log; =20 typedef struct MemoryRegionOps MemoryRegionOps; =20 @@ -2099,13 +2102,17 @@ void memory_listener_unregister(MemoryListener *lis= tener); =20 /** * memory_global_dirty_log_start: begin dirty logging for all regions + * + * @flags: purpose of start dirty log, migration or dirty rate */ -void memory_global_dirty_log_start(void); +void memory_global_dirty_log_start(int flags); =20 /** * memory_global_dirty_log_stop: end dirty logging for all regions + * + * @flags: purpose of stop dirty log, migration or dirty rate */ -void memory_global_dirty_log_stop(void); +void memory_global_dirty_log_stop(int flags); =20 void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabl= ed); =20 diff --git a/migration/ram.c b/migration/ram.c index 60ea913c54..9ce31af9d1 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2190,7 +2190,7 @@ static void ram_save_cleanup(void *opaque) /* caller have hold iothread lock or is in a bh, so there is * no writing race against the migration bitmap */ - memory_global_dirty_log_stop(); + memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); } =20 RAMBLOCK_FOREACH_NOT_IGNORED(block) { @@ -2652,7 +2652,7 @@ static void ram_init_bitmaps(RAMState *rs) ram_list_init_bitmaps(); /* We don't use dirty log with background snapshots */ if (!migrate_background_snapshot()) { - memory_global_dirty_log_start(); + memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); migration_bitmap_sync_precopy(rs); } } @@ -3393,7 +3393,7 @@ void colo_incoming_start_dirty_log(void) /* Discard this dirty bitmap record */ bitmap_zero(block->bmap, block->max_length >> TARGET_PAGE_BITS= ); } - memory_global_dirty_log_start(); + memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); } ram_state->migration_dirty_pages =3D 0; qemu_mutex_unlock_ramlist(); @@ -3405,7 +3405,7 @@ void colo_release_ram_cache(void) { RAMBlock *block; =20 - memory_global_dirty_log_stop(); + memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); RAMBLOCK_FOREACH_NOT_IGNORED(block) { g_free(block->bmap); block->bmap =3D NULL; diff --git a/softmmu/memory.c b/softmmu/memory.c index c19b0be6b1..b93baba82d 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -39,7 +39,7 @@ static unsigned memory_region_transaction_depth; static bool memory_region_update_pending; static bool ioeventfd_update_pending; -bool global_dirty_log; +int global_dirty_log; =20 static QTAILQ_HEAD(, MemoryListener) memory_listeners =3D QTAILQ_HEAD_INITIALIZER(memory_listeners); @@ -2659,14 +2659,20 @@ void memory_global_after_dirty_log_sync(void) =20 static VMChangeStateEntry *vmstate_change; =20 -void memory_global_dirty_log_start(void) +void memory_global_dirty_log_start(int flags) { if (vmstate_change) { qemu_del_vm_change_state_handler(vmstate_change); vmstate_change =3D NULL; } =20 - global_dirty_log =3D true; + if (flags & GLOBAL_DIRTY_MIGRATION) { + global_dirty_log |=3D GLOBAL_DIRTY_MIGRATION; + } + + if (flags & GLOBAL_DIRTY_DIRTY_RATE) { + global_dirty_log |=3D GLOBAL_DIRTY_DIRTY_RATE; + } =20 MEMORY_LISTENER_CALL_GLOBAL(log_global_start, Forward); =20 @@ -2676,9 +2682,15 @@ void memory_global_dirty_log_start(void) memory_region_transaction_commit(); } =20 -static void memory_global_dirty_log_do_stop(void) +static void memory_global_dirty_log_do_stop(int flags) { - global_dirty_log =3D false; + if (flags & GLOBAL_DIRTY_MIGRATION) { + global_dirty_log &=3D ~GLOBAL_DIRTY_MIGRATION; + } + + if (flags & GLOBAL_DIRTY_DIRTY_RATE) { + global_dirty_log &=3D ~GLOBAL_DIRTY_DIRTY_RATE; + } =20 /* Refresh DIRTY_MEMORY_MIGRATION bit. */ memory_region_transaction_begin(); @@ -2691,8 +2703,10 @@ static void memory_global_dirty_log_do_stop(void) static void memory_vm_change_state_handler(void *opaque, bool running, RunState state) { + int *flags =3D opaque; if (running) { - memory_global_dirty_log_do_stop(); + memory_global_dirty_log_do_stop(*flags); + g_free(opaque); =20 if (vmstate_change) { qemu_del_vm_change_state_handler(vmstate_change); @@ -2701,18 +2715,22 @@ static void memory_vm_change_state_handler(void *op= aque, bool running, } } =20 -void memory_global_dirty_log_stop(void) +void memory_global_dirty_log_stop(int flags) { + int *opaque =3D NULL; if (!runstate_is_running()) { if (vmstate_change) { return; } + + opaque =3D g_malloc0(sizeof(opaque)); + *opaque =3D flags; vmstate_change =3D qemu_add_vm_change_state_handler( - memory_vm_change_state_handler, NULL); + memory_vm_change_state_handler, opaque); return; } =20 - memory_global_dirty_log_do_stop(); + memory_global_dirty_log_do_stop(flags); } =20 static void listener_add_address_space(MemoryListener *listener, --=20 2.18.2