From nobody Wed Nov 5 15:55:26 2025 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; 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 1496829985540401.2162975403687; Wed, 7 Jun 2017 03:06:25 -0700 (PDT) Received: from localhost ([::1]:42418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXr4-0002yV-7w for importer@patchew.org; Wed, 07 Jun 2017 06:06:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXkU-0005SQ-Lo for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIXkT-0005Jp-Hv for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56660) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIXkT-0005Jl-9Z for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 416DAC0587C6 for ; Wed, 7 Jun 2017 09:59:32 +0000 (UTC) Received: from secure.mitica (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80DA817A8C; Wed, 7 Jun 2017 09:59:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 416DAC0587C6 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 416DAC0587C6 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 11:59:20 +0200 Message-Id: <20170607095926.1834-2-quintela@redhat.com> In-Reply-To: <20170607095926.1834-1-quintela@redhat.com> References: <20170607095926.1834-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 07 Jun 2017 09:59:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/7] ram: Unfold get_xbzrle_cache_stats() into populate_ram_info() 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: lvivier@redhat.com, dgilbert@redhat.com, peterx@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" They were called consecutively always. Signed-off-by: Juan Quintela Reviewed-by: Eric Blake --- migration/migration.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 48c94c9..b1e68c0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -588,20 +588,6 @@ static bool migration_is_setup_or_active(int state) } } =20 -static void get_xbzrle_cache_stats(MigrationInfo *info) -{ - if (migrate_use_xbzrle()) { - info->has_xbzrle_cache =3D true; - info->xbzrle_cache =3D g_malloc0(sizeof(*info->xbzrle_cache)); - info->xbzrle_cache->cache_size =3D migrate_xbzrle_cache_size(); - info->xbzrle_cache->bytes =3D xbzrle_mig_bytes_transferred(); - info->xbzrle_cache->pages =3D xbzrle_mig_pages_transferred(); - info->xbzrle_cache->cache_miss =3D xbzrle_mig_pages_cache_miss(); - info->xbzrle_cache->cache_miss_rate =3D xbzrle_mig_cache_miss_rate= (); - info->xbzrle_cache->overflow =3D xbzrle_mig_pages_overflow(); - } -} - static void populate_ram_info(MigrationInfo *info, MigrationState *s) { info->has_ram =3D true; @@ -619,6 +605,17 @@ static void populate_ram_info(MigrationInfo *info, Mig= rationState *s) info->ram->postcopy_requests =3D ram_postcopy_requests(); info->ram->page_size =3D qemu_target_page_size(); =20 + if (migrate_use_xbzrle()) { + info->has_xbzrle_cache =3D true; + info->xbzrle_cache =3D g_malloc0(sizeof(*info->xbzrle_cache)); + info->xbzrle_cache->cache_size =3D migrate_xbzrle_cache_size(); + info->xbzrle_cache->bytes =3D xbzrle_mig_bytes_transferred(); + info->xbzrle_cache->pages =3D xbzrle_mig_pages_transferred(); + info->xbzrle_cache->cache_miss =3D xbzrle_mig_pages_cache_miss(); + info->xbzrle_cache->cache_miss_rate =3D xbzrle_mig_cache_miss_rate= (); + info->xbzrle_cache->overflow =3D xbzrle_mig_pages_overflow(); + } + if (s->state !=3D MIGRATION_STATUS_COMPLETED) { info->ram->remaining =3D ram_bytes_remaining(); info->ram->dirty_pages_rate =3D ram_dirty_pages_rate(); @@ -664,7 +661,6 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->cpu_throttle_percentage =3D cpu_throttle_get_percentage(= ); } =20 - get_xbzrle_cache_stats(info); break; case MIGRATION_STATUS_POSTCOPY_ACTIVE: /* Mostly the same as active; TODO add some postcopy stats */ @@ -687,15 +683,12 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->disk->total =3D blk_mig_bytes_total(); } =20 - get_xbzrle_cache_stats(info); break; case MIGRATION_STATUS_COLO: info->has_status =3D true; /* TODO: display COLO specific information (checkpoint info etc.) = */ break; case MIGRATION_STATUS_COMPLETED: - get_xbzrle_cache_stats(info); - info->has_status =3D true; info->has_total_time =3D true; info->total_time =3D s->total_time; --=20 2.9.4 From nobody Wed Nov 5 15:55:26 2025 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; 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 1496830099316613.3673628061617; Wed, 7 Jun 2017 03:08:19 -0700 (PDT) Received: from localhost ([::1]:42426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXsv-0004aQ-Lo for importer@patchew.org; Wed, 07 Jun 2017 06:08:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXkV-0005TY-UI for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIXkV-0005KD-8D for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIXkV-0005K0-2a for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5DE87F3F5 for ; Wed, 7 Jun 2017 09:59:33 +0000 (UTC) Received: from secure.mitica (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9350317A8A; Wed, 7 Jun 2017 09:59:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E5DE87F3F5 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E5DE87F3F5 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 11:59:21 +0200 Message-Id: <20170607095926.1834-3-quintela@redhat.com> In-Reply-To: <20170607095926.1834-1-quintela@redhat.com> References: <20170607095926.1834-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 07 Jun 2017 09:59:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/7] ram: We only print throttling information sometimes 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: lvivier@redhat.com, dgilbert@redhat.com, peterx@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Change it to be consistent with everything else. Signed-off-by: Juan Quintela Reviewed-by: Eric Blake --- migration/migration.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b1e68c0..9c5ff57 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -616,6 +616,11 @@ static void populate_ram_info(MigrationInfo *info, Mig= rationState *s) info->xbzrle_cache->overflow =3D xbzrle_mig_pages_overflow(); } =20 + if (cpu_throttle_active()) { + info->has_cpu_throttle_percentage =3D true; + info->cpu_throttle_percentage =3D cpu_throttle_get_percentage(); + } + if (s->state !=3D MIGRATION_STATUS_COMPLETED) { info->ram->remaining =3D ram_bytes_remaining(); info->ram->dirty_pages_rate =3D ram_dirty_pages_rate(); @@ -656,11 +661,6 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->disk->total =3D blk_mig_bytes_total(); } =20 - if (cpu_throttle_active()) { - info->has_cpu_throttle_percentage =3D true; - info->cpu_throttle_percentage =3D cpu_throttle_get_percentage(= ); - } - break; case MIGRATION_STATUS_POSTCOPY_ACTIVE: /* Mostly the same as active; TODO add some postcopy stats */ --=20 2.9.4 From nobody Wed Nov 5 15:55:26 2025 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; 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 1496830139634915.6706281311054; Wed, 7 Jun 2017 03:08:59 -0700 (PDT) Received: from localhost ([::1]:42427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXtZ-00054w-Qy for importer@patchew.org; Wed, 07 Jun 2017 06:08:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXkX-0005VT-Lx for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIXkW-0005Ka-U4 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIXkW-0005KQ-OH for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 955C48553F for ; Wed, 7 Jun 2017 09:59:35 +0000 (UTC) Received: from secure.mitica (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43DC717A7B; Wed, 7 Jun 2017 09:59:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 955C48553F Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 955C48553F From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 11:59:22 +0200 Message-Id: <20170607095926.1834-4-quintela@redhat.com> In-Reply-To: <20170607095926.1834-1-quintela@redhat.com> References: <20170607095926.1834-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 07 Jun 2017 09:59:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/7] ram: Call migration_page_queue_free() at ram_migration_cleanup() 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: lvivier@redhat.com, dgilbert@redhat.com, peterx@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We shouldn't be using memory later than that. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- migration/migration.c | 2 -- migration/ram.c | 5 +++-- migration/ram.h | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 9c5ff57..9cf47d3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -948,8 +948,6 @@ static void migrate_fd_cleanup(void *opaque) qemu_bh_delete(s->cleanup_bh); s->cleanup_bh =3D NULL; =20 - migration_page_queue_free(); - if (s->to_dst_file) { trace_migrate_fd_cleanup(); qemu_mutex_unlock_iothread(); diff --git a/migration/ram.c b/migration/ram.c index f387e9c..701a1e6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1184,10 +1184,9 @@ static bool get_queued_page(RAMState *rs, PageSearch= Status *pss) * be some left. in case that there is any page left, we drop it. * */ -void migration_page_queue_free(void) +static void migration_page_queue_free(RAMState *rs) { struct RAMSrcPageRequest *mspr, *next_mspr; - RAMState *rs =3D &ram_state; /* This queue generally should be empty - but in the case of a failed * migration might have some droppings in. */ @@ -1437,6 +1436,7 @@ void free_xbzrle_decoded_buf(void) =20 static void ram_migration_cleanup(void *opaque) { + RAMState *rs =3D opaque; RAMBlock *block; =20 /* caller have hold iothread lock or is in a bh, so there is @@ -1462,6 +1462,7 @@ static void ram_migration_cleanup(void *opaque) XBZRLE.current_buf =3D NULL; } XBZRLE_cache_unlock(); + migration_page_queue_free(rs); } =20 static void ram_state_reset(RAMState *rs) diff --git a/migration/ram.h b/migration/ram.h index c9563d1..d4da419 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -53,7 +53,6 @@ void migrate_decompress_threads_create(void); void migrate_decompress_threads_join(void); =20 uint64_t ram_pagesize_summary(void); -void migration_page_queue_free(void); int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len); void acct_update_position(QEMUFile *f, size_t size, bool zero); void free_xbzrle_decoded_buf(void); --=20 2.9.4 From nobody Wed Nov 5 15:55:26 2025 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; 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 1496829832746281.02006582864703; Wed, 7 Jun 2017 03:03:52 -0700 (PDT) Received: from localhost ([::1]:42402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXoc-0000mm-Ox for importer@patchew.org; Wed, 07 Jun 2017 06:03:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXkZ-0005X2-K5 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIXkY-0005Kx-PQ for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60192) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIXkY-0005Kq-JW for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 855B161D16 for ; Wed, 7 Jun 2017 09:59:37 +0000 (UTC) Received: from secure.mitica (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6B0717A7B; Wed, 7 Jun 2017 09:59:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 855B161D16 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 855B161D16 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 11:59:23 +0200 Message-Id: <20170607095926.1834-5-quintela@redhat.com> In-Reply-To: <20170607095926.1834-1-quintela@redhat.com> References: <20170607095926.1834-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 07 Jun 2017 09:59:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/7] ram: Move ZERO_TARGET_PAGE inside XBZRLE 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: lvivier@redhat.com, dgilbert@redhat.com, peterx@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It was only used by XBZRLE anyways. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- migration/ram.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 701a1e6..ac30e9e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -69,8 +69,6 @@ /* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 =20 -static uint8_t *ZERO_TARGET_PAGE; - static inline bool is_zero_range(uint8_t *p, uint64_t size) { return buffer_is_zero(p, size); @@ -86,6 +84,8 @@ static struct { /* Cache for XBZRLE, Protected by lock. */ PageCache *cache; QemuMutex lock; + /* it will store a page full of zeros */ + uint8_t *zero_target_page; } XBZRLE; =20 /* buffer used for XBZRLE decoding */ @@ -512,7 +512,7 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_ad= dr_t current_addr) =20 /* We don't care if this fails to allocate a new cache page * as long as it updated an old one */ - cache_insert(XBZRLE.cache, current_addr, ZERO_TARGET_PAGE, + cache_insert(XBZRLE.cache, current_addr, XBZRLE.zero_target_page, rs->bitmap_sync_count); } =20 @@ -1456,10 +1456,11 @@ static void ram_migration_cleanup(void *opaque) cache_fini(XBZRLE.cache); g_free(XBZRLE.encoded_buf); g_free(XBZRLE.current_buf); - g_free(ZERO_TARGET_PAGE); + g_free(XBZRLE.zero_target_page); XBZRLE.cache =3D NULL; XBZRLE.encoded_buf =3D NULL; XBZRLE.current_buf =3D NULL; + XBZRLE.zero_target_page =3D NULL; } XBZRLE_cache_unlock(); migration_page_queue_free(rs); @@ -1880,7 +1881,7 @@ static int ram_state_init(RAMState *rs) =20 if (migrate_use_xbzrle()) { XBZRLE_cache_lock(); - ZERO_TARGET_PAGE =3D g_malloc0(TARGET_PAGE_SIZE); + XBZRLE.zero_target_page =3D g_malloc0(TARGET_PAGE_SIZE); XBZRLE.cache =3D cache_init(migrate_xbzrle_cache_size() / TARGET_PAGE_SIZE, TARGET_PAGE_SIZE); --=20 2.9.4 From nobody Wed Nov 5 15:55:26 2025 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; 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 1496830338512808.1491448219451; Wed, 7 Jun 2017 03:12:18 -0700 (PDT) Received: from localhost ([::1]:42446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXwm-0007GV-GP for importer@patchew.org; Wed, 07 Jun 2017 06:12:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXkf-0005c4-EN for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIXkc-0005LV-7o for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36068) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIXkb-0005LF-Vp for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC3B13E9 for ; Wed, 7 Jun 2017 09:59:40 +0000 (UTC) Received: from secure.mitica (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6D4817A8F; Wed, 7 Jun 2017 09:59:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DC3B13E9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DC3B13E9 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 11:59:24 +0200 Message-Id: <20170607095926.1834-6-quintela@redhat.com> In-Reply-To: <20170607095926.1834-1-quintela@redhat.com> References: <20170607095926.1834-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 07 Jun 2017 09:59:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/7] ram: Use MigrationStats for statistics 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: lvivier@redhat.com, dgilbert@redhat.com, peterx@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" RAM Statistics need to survive migration to make info migrate work, so we need to store them outside of RAMState. As we already have an struct with those fields, just used them. (MigrationStats and XBZRLECacheStats). Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- migration/migration.c | 28 ++++----- migration/ram.c | 163 ++++++++++++++--------------------------------= ---- migration/ram.h | 14 +---- 3 files changed, 61 insertions(+), 144 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 9cf47d3..6f0705a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -592,28 +592,28 @@ static void populate_ram_info(MigrationInfo *info, Mi= grationState *s) { info->has_ram =3D true; info->ram =3D g_malloc0(sizeof(*info->ram)); - info->ram->transferred =3D ram_bytes_transferred(); + info->ram->transferred =3D ram_counters.transferred; info->ram->total =3D ram_bytes_total(); - info->ram->duplicate =3D dup_mig_pages_transferred(); + info->ram->duplicate =3D ram_counters.duplicate; /* legacy value. It is not used anymore */ info->ram->skipped =3D 0; - info->ram->normal =3D norm_mig_pages_transferred(); - info->ram->normal_bytes =3D norm_mig_pages_transferred() * + info->ram->normal =3D ram_counters.normal; + info->ram->normal_bytes =3D ram_counters.normal * qemu_target_page_size(); info->ram->mbps =3D s->mbps; - info->ram->dirty_sync_count =3D ram_dirty_sync_count(); - info->ram->postcopy_requests =3D ram_postcopy_requests(); + info->ram->dirty_sync_count =3D ram_counters.dirty_sync_count; + info->ram->postcopy_requests =3D ram_counters.postcopy_requests; info->ram->page_size =3D qemu_target_page_size(); =20 if (migrate_use_xbzrle()) { info->has_xbzrle_cache =3D true; info->xbzrle_cache =3D g_malloc0(sizeof(*info->xbzrle_cache)); info->xbzrle_cache->cache_size =3D migrate_xbzrle_cache_size(); - info->xbzrle_cache->bytes =3D xbzrle_mig_bytes_transferred(); - info->xbzrle_cache->pages =3D xbzrle_mig_pages_transferred(); - info->xbzrle_cache->cache_miss =3D xbzrle_mig_pages_cache_miss(); - info->xbzrle_cache->cache_miss_rate =3D xbzrle_mig_cache_miss_rate= (); - info->xbzrle_cache->overflow =3D xbzrle_mig_pages_overflow(); + info->xbzrle_cache->bytes =3D xbzrle_counters.bytes; + info->xbzrle_cache->pages =3D xbzrle_counters.pages; + info->xbzrle_cache->cache_miss =3D xbzrle_counters.cache_miss; + info->xbzrle_cache->cache_miss_rate =3D xbzrle_counters.cache_miss= _rate; + info->xbzrle_cache->overflow =3D xbzrle_counters.overflow; } =20 if (cpu_throttle_active()) { @@ -623,7 +623,7 @@ static void populate_ram_info(MigrationInfo *info, Migr= ationState *s) =20 if (s->state !=3D MIGRATION_STATUS_COMPLETED) { info->ram->remaining =3D ram_bytes_remaining(); - info->ram->dirty_pages_rate =3D ram_dirty_pages_rate(); + info->ram->dirty_pages_rate =3D ram_counters.dirty_pages_rate; } } =20 @@ -2018,8 +2018,8 @@ static void *migration_thread(void *opaque) bandwidth, threshold_size); /* if we haven't sent anything, we don't want to recalculate 10000 is a small enough number for our purposes */ - if (ram_dirty_pages_rate() && transferred_bytes > 10000) { - s->expected_downtime =3D ram_dirty_pages_rate() * + if (ram_counters.dirty_pages_rate && transferred_bytes > 10000= ) { + s->expected_downtime =3D ram_counters.dirty_pages_rate * qemu_target_page_size() / bandwidth; } =20 diff --git a/migration/ram.c b/migration/ram.c index ac30e9e..cd6a121 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -74,6 +74,8 @@ static inline bool is_zero_range(uint8_t *p, uint64_t siz= e) return buffer_is_zero(p, size); } =20 +XBZRLECacheStats xbzrle_counters; + /* struct contains XBZRLE cache and a static page used by the compression */ static struct { @@ -177,8 +179,6 @@ struct RAMState { bool ram_bulk_stage; /* How many times we have dirty too many pages */ int dirty_rate_high_cnt; - /* How many times we have synchronized the bitmap */ - uint64_t bitmap_sync_count; /* these variables are used for bitmap sync */ /* last time we did a full bitmap_sync */ int64_t time_last_bitmap_sync; @@ -190,33 +190,11 @@ struct RAMState { uint64_t xbzrle_cache_miss_prev; /* number of iterations at the beginning of period */ uint64_t iterations_prev; - /* Accounting fields */ - /* number of zero pages. It used to be pages filled by the same char.= */ - uint64_t zero_pages; - /* number of normal transferred pages */ - uint64_t norm_pages; /* Iterations since start */ uint64_t iterations; - /* xbzrle transmitted bytes. Notice that this is with - * compression, they can't be calculated from the pages */ - uint64_t xbzrle_bytes; - /* xbzrle transmmited pages */ - uint64_t xbzrle_pages; - /* xbzrle number of cache miss */ - uint64_t xbzrle_cache_miss; - /* xbzrle miss rate */ - double xbzrle_cache_miss_rate; - /* xbzrle number of overflows */ - uint64_t xbzrle_overflows; - /* number of dirty bits in the bitmap */ - uint64_t migration_dirty_pages; - /* total number of bytes transferred */ - uint64_t bytes_transferred; - /* number of dirtied pages in the last second */ - uint64_t dirty_pages_rate; - /* Count of requests incoming from destination */ - uint64_t postcopy_requests; /* protects modification of the bitmap */ + uint64_t migration_dirty_pages; + /* number of dirty bits in the bitmap */ QemuMutex bitmap_mutex; /* The RAMBlock used in the last src_page_requests */ RAMBlock *last_req_rb; @@ -228,65 +206,12 @@ typedef struct RAMState RAMState; =20 static RAMState ram_state; =20 -uint64_t dup_mig_pages_transferred(void) -{ - return ram_state.zero_pages; -} - -uint64_t norm_mig_pages_transferred(void) -{ - return ram_state.norm_pages; -} - -uint64_t xbzrle_mig_bytes_transferred(void) -{ - return ram_state.xbzrle_bytes; -} - -uint64_t xbzrle_mig_pages_transferred(void) -{ - return ram_state.xbzrle_pages; -} - -uint64_t xbzrle_mig_pages_cache_miss(void) -{ - return ram_state.xbzrle_cache_miss; -} - -double xbzrle_mig_cache_miss_rate(void) -{ - return ram_state.xbzrle_cache_miss_rate; -} - -uint64_t xbzrle_mig_pages_overflow(void) -{ - return ram_state.xbzrle_overflows; -} - -uint64_t ram_bytes_transferred(void) -{ - return ram_state.bytes_transferred; -} - uint64_t ram_bytes_remaining(void) { return ram_state.migration_dirty_pages * TARGET_PAGE_SIZE; } =20 -uint64_t ram_dirty_sync_count(void) -{ - return ram_state.bitmap_sync_count; -} - -uint64_t ram_dirty_pages_rate(void) -{ - return ram_state.dirty_pages_rate; -} - -uint64_t ram_postcopy_requests(void) -{ - return ram_state.postcopy_requests; -} +MigrationStats ram_counters; =20 /* used by the search for pages to send */ struct PageSearchStatus { @@ -513,7 +438,7 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_ad= dr_t current_addr) /* We don't care if this fails to allocate a new cache page * as long as it updated an old one */ cache_insert(XBZRLE.cache, current_addr, XBZRLE.zero_target_page, - rs->bitmap_sync_count); + ram_counters.dirty_sync_count); } =20 #define ENCODING_FLAG_XBZRLE 0x1 @@ -539,11 +464,12 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **c= urrent_data, int encoded_len =3D 0, bytes_xbzrle; uint8_t *prev_cached_page; =20 - if (!cache_is_cached(XBZRLE.cache, current_addr, rs->bitmap_sync_count= )) { - rs->xbzrle_cache_miss++; + if (!cache_is_cached(XBZRLE.cache, current_addr, + ram_counters.dirty_sync_count)) { + xbzrle_counters.cache_miss++; if (!last_stage) { if (cache_insert(XBZRLE.cache, current_addr, *current_data, - rs->bitmap_sync_count) =3D=3D -1) { + ram_counters.dirty_sync_count) =3D=3D -1) { return -1; } else { /* update *current_data when the page has been @@ -568,7 +494,7 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **cur= rent_data, return 0; } else if (encoded_len =3D=3D -1) { trace_save_xbzrle_page_overflow(); - rs->xbzrle_overflows++; + xbzrle_counters.overflow++; /* update data in the cache */ if (!last_stage) { memcpy(prev_cached_page, *current_data, TARGET_PAGE_SIZE); @@ -589,9 +515,9 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **cur= rent_data, qemu_put_be16(rs->f, encoded_len); qemu_put_buffer(rs->f, XBZRLE.encoded_buf, encoded_len); bytes_xbzrle +=3D encoded_len + 1 + 2; - rs->xbzrle_pages++; - rs->xbzrle_bytes +=3D bytes_xbzrle; - rs->bytes_transferred +=3D bytes_xbzrle; + xbzrle_counters.pages++; + xbzrle_counters.bytes +=3D bytes_xbzrle; + ram_counters.transferred +=3D bytes_xbzrle; =20 return 1; } @@ -673,7 +599,7 @@ static void migration_bitmap_sync(RAMState *rs) int64_t end_time; uint64_t bytes_xfer_now; =20 - rs->bitmap_sync_count++; + ram_counters.dirty_sync_count++; =20 if (!rs->time_last_bitmap_sync) { rs->time_last_bitmap_sync =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIM= E); @@ -697,9 +623,9 @@ static void migration_bitmap_sync(RAMState *rs) /* more than 1 second =3D 1000 millisecons */ if (end_time > rs->time_last_bitmap_sync + 1000) { /* calculate period counters */ - rs->dirty_pages_rate =3D rs->num_dirty_pages_period * 1000 + ram_counters.dirty_pages_rate =3D rs->num_dirty_pages_period * 1000 / (end_time - rs->time_last_bitmap_sync); - bytes_xfer_now =3D ram_bytes_transferred(); + bytes_xfer_now =3D ram_counters.transferred; =20 if (migrate_auto_converge()) { /* The following detection logic can be refined later. For now: @@ -719,13 +645,13 @@ static void migration_bitmap_sync(RAMState *rs) =20 if (migrate_use_xbzrle()) { if (rs->iterations_prev !=3D rs->iterations) { - rs->xbzrle_cache_miss_rate =3D - (double)(rs->xbzrle_cache_miss - + xbzrle_counters.cache_miss_rate =3D + (double)(xbzrle_counters.cache_miss - rs->xbzrle_cache_miss_prev) / (rs->iterations - rs->iterations_prev); } rs->iterations_prev =3D rs->iterations; - rs->xbzrle_cache_miss_prev =3D rs->xbzrle_cache_miss; + rs->xbzrle_cache_miss_prev =3D xbzrle_counters.cache_miss; } =20 /* reset period counters */ @@ -734,7 +660,7 @@ static void migration_bitmap_sync(RAMState *rs) rs->bytes_xfer_prev =3D bytes_xfer_now; } if (migrate_use_events()) { - qapi_event_send_migration_pass(rs->bitmap_sync_count, NULL); + qapi_event_send_migration_pass(ram_counters.dirty_sync_count, NULL= ); } } =20 @@ -754,11 +680,11 @@ static int save_zero_page(RAMState *rs, RAMBlock *blo= ck, ram_addr_t offset, int pages =3D -1; =20 if (is_zero_range(p, TARGET_PAGE_SIZE)) { - rs->zero_pages++; - rs->bytes_transferred +=3D + ram_counters.duplicate++; + ram_counters.transferred +=3D save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_ZERO= ); qemu_put_byte(rs->f, 0); - rs->bytes_transferred +=3D 1; + ram_counters.transferred +=3D 1; pages =3D 1; } =20 @@ -806,7 +732,7 @@ static int ram_save_page(RAMState *rs, PageSearchStatus= *pss, bool last_stage) ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAGE_SIZE, &bytes_xmit); if (bytes_xmit) { - rs->bytes_transferred +=3D bytes_xmit; + ram_counters.transferred +=3D bytes_xmit; pages =3D 1; } =20 @@ -817,9 +743,9 @@ static int ram_save_page(RAMState *rs, PageSearchStatus= *pss, bool last_stage) if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { if (ret !=3D RAM_SAVE_CONTROL_DELAYED) { if (bytes_xmit > 0) { - rs->norm_pages++; + ram_counters.normal++; } else if (bytes_xmit =3D=3D 0) { - rs->zero_pages++; + ram_counters.duplicate++; } } } else { @@ -845,8 +771,8 @@ static int ram_save_page(RAMState *rs, PageSearchStatus= *pss, bool last_stage) =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - rs->bytes_transferred +=3D save_page_header(rs, rs->f, block, - offset | RAM_SAVE_FLAG_P= AGE); + ram_counters.transferred +=3D + save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_PAGE= ); if (send_async) { qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, migrate_release_ram() & @@ -854,9 +780,9 @@ static int ram_save_page(RAMState *rs, PageSearchStatus= *pss, bool last_stage) } else { qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); } - rs->bytes_transferred +=3D TARGET_PAGE_SIZE; + ram_counters.transferred +=3D TARGET_PAGE_SIZE; pages =3D 1; - rs->norm_pages++; + ram_counters.normal++; } =20 XBZRLE_cache_unlock(); @@ -908,7 +834,7 @@ static void flush_compressed_data(RAMState *rs) qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { len =3D qemu_put_qemu_file(rs->f, comp_param[idx].file); - rs->bytes_transferred +=3D len; + ram_counters.transferred +=3D len; } qemu_mutex_unlock(&comp_param[idx].mutex); } @@ -938,8 +864,8 @@ static int compress_page_with_multi_thread(RAMState *rs= , RAMBlock *block, qemu_cond_signal(&comp_param[idx].cond); qemu_mutex_unlock(&comp_param[idx].mutex); pages =3D 1; - rs->norm_pages++; - rs->bytes_transferred +=3D bytes_xmit; + ram_counters.normal++; + ram_counters.transferred +=3D bytes_xmit; break; } } @@ -979,15 +905,15 @@ static int ram_save_compressed_page(RAMState *rs, Pag= eSearchStatus *pss, ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAGE_SIZE, &bytes_xmit); if (bytes_xmit) { - rs->bytes_transferred +=3D bytes_xmit; + ram_counters.transferred +=3D bytes_xmit; pages =3D 1; } if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { if (ret !=3D RAM_SAVE_CONTROL_DELAYED) { if (bytes_xmit > 0) { - rs->norm_pages++; + ram_counters.normal++; } else if (bytes_xmit =3D=3D 0) { - rs->zero_pages++; + ram_counters.duplicate++; } } } else { @@ -1007,8 +933,8 @@ static int ram_save_compressed_page(RAMState *rs, Page= SearchStatus *pss, blen =3D qemu_put_compression_data(rs->f, p, TARGET_PAGE_S= IZE, migrate_compress_level()); if (blen > 0) { - rs->bytes_transferred +=3D bytes_xmit + blen; - rs->norm_pages++; + ram_counters.transferred +=3D bytes_xmit + blen; + ram_counters.normal++; pages =3D 1; } else { qemu_file_set_error(rs->f, blen); @@ -1216,7 +1142,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr= _t start, ram_addr_t len) RAMBlock *ramblock; RAMState *rs =3D &ram_state; =20 - rs->postcopy_requests++; + ram_counters.postcopy_requests++; rcu_read_lock(); if (!rbname) { /* Reuse last RAMBlock */ @@ -1404,13 +1330,12 @@ static int ram_find_and_save_block(RAMState *rs, bo= ol last_stage) void acct_update_position(QEMUFile *f, size_t size, bool zero) { uint64_t pages =3D size / TARGET_PAGE_SIZE; - RAMState *rs =3D &ram_state; =20 if (zero) { - rs->zero_pages +=3D pages; + ram_counters.duplicate +=3D pages; } else { - rs->norm_pages +=3D pages; - rs->bytes_transferred +=3D size; + ram_counters.normal +=3D pages; + ram_counters.transferred +=3D size; qemu_update_position(f, size); } } @@ -2060,7 +1985,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) ram_control_after_iterate(f, RAM_CONTROL_ROUND); =20 qemu_put_be64(f, RAM_SAVE_FLAG_EOS); - rs->bytes_transferred +=3D 8; + ram_counters.transferred +=3D 8; =20 ret =3D qemu_file_get_error(f); if (ret < 0) { diff --git a/migration/ram.h b/migration/ram.h index d4da419..6272eb0 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -32,19 +32,11 @@ #include "qemu-common.h" #include "exec/cpu-common.h" =20 +extern MigrationStats ram_counters; +extern XBZRLECacheStats xbzrle_counters; + int64_t xbzrle_cache_resize(int64_t new_size); -uint64_t dup_mig_pages_transferred(void); -uint64_t norm_mig_pages_transferred(void); -uint64_t xbzrle_mig_bytes_transferred(void); -uint64_t xbzrle_mig_pages_transferred(void); -uint64_t xbzrle_mig_pages_cache_miss(void); -double xbzrle_mig_cache_miss_rate(void); -uint64_t xbzrle_mig_pages_overflow(void); -uint64_t ram_bytes_transferred(void); uint64_t ram_bytes_remaining(void); -uint64_t ram_dirty_sync_count(void); -uint64_t ram_dirty_pages_rate(void); -uint64_t ram_postcopy_requests(void); uint64_t ram_bytes_total(void); =20 void migrate_compress_threads_create(void); --=20 2.9.4 From nobody Wed Nov 5 15:55:26 2025 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; 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 1496830203012439.1546841972838; Wed, 7 Jun 2017 03:10:03 -0700 (PDT) Received: from localhost ([::1]:42433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXub-0005sF-Ca for importer@patchew.org; Wed, 07 Jun 2017 06:10:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXkf-0005c7-GB for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIXke-0005Lo-9U for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIXke-0005Lf-0T for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC063DC8F5 for ; Wed, 7 Jun 2017 09:59:42 +0000 (UTC) Received: from secure.mitica (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A0E117A7B; Wed, 7 Jun 2017 09:59:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EC063DC8F5 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EC063DC8F5 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 11:59:25 +0200 Message-Id: <20170607095926.1834-7-quintela@redhat.com> In-Reply-To: <20170607095926.1834-1-quintela@redhat.com> References: <20170607095926.1834-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 07 Jun 2017 09:59:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/7] ram: Make RAMState dynamic 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: lvivier@redhat.com, dgilbert@redhat.com, peterx@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We create the variable while we are at migration and we remove it after migration. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 58 ++++++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index cd6a121..9ffd0a5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -204,11 +204,11 @@ struct RAMState { }; typedef struct RAMState RAMState; =20 -static RAMState ram_state; +static RAMState *ram_state; =20 uint64_t ram_bytes_remaining(void) { - return ram_state.migration_dirty_pages * TARGET_PAGE_SIZE; + return ram_state->migration_dirty_pages * TARGET_PAGE_SIZE; } =20 MigrationStats ram_counters; @@ -793,7 +793,7 @@ static int ram_save_page(RAMState *rs, PageSearchStatus= *pss, bool last_stage) static int do_compress_ram_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset) { - RAMState *rs =3D &ram_state; + RAMState *rs =3D ram_state; int bytes_sent, blen; uint8_t *p =3D block->host + (offset & TARGET_PAGE_MASK); =20 @@ -1140,7 +1140,7 @@ static void migration_page_queue_free(RAMState *rs) int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len) { RAMBlock *ramblock; - RAMState *rs =3D &ram_state; + RAMState *rs =3D ram_state; =20 ram_counters.postcopy_requests++; rcu_read_lock(); @@ -1361,7 +1361,7 @@ void free_xbzrle_decoded_buf(void) =20 static void ram_migration_cleanup(void *opaque) { - RAMState *rs =3D opaque; + RAMState **rsp =3D opaque; RAMBlock *block; =20 /* caller have hold iothread lock or is in a bh, so there is @@ -1388,7 +1388,9 @@ static void ram_migration_cleanup(void *opaque) XBZRLE.zero_target_page =3D NULL; } XBZRLE_cache_unlock(); - migration_page_queue_free(rs); + migration_page_queue_free(*rsp); + g_free(*rsp); + *rsp =3D NULL; } =20 static void ram_state_reset(RAMState *rs) @@ -1559,7 +1561,7 @@ static void postcopy_chunk_hostpages_pass(MigrationSt= ate *ms, bool unsent_pass, RAMBlock *block, PostcopyDiscardState *pds) { - RAMState *rs =3D &ram_state; + RAMState *rs =3D ram_state; unsigned long *bitmap =3D block->bmap; unsigned long *unsentmap =3D block->unsentmap; unsigned int host_ratio =3D block->page_size / TARGET_PAGE_SIZE; @@ -1714,7 +1716,7 @@ static int postcopy_chunk_hostpages(MigrationState *m= s, RAMBlock *block) */ int ram_postcopy_send_discard_bitmap(MigrationState *ms) { - RAMState *rs =3D &ram_state; + RAMState *rs =3D ram_state; RAMBlock *block; int ret; =20 @@ -1797,12 +1799,13 @@ err: return ret; } =20 -static int ram_state_init(RAMState *rs) +static int ram_state_init(RAMState **rsp) { - memset(rs, 0, sizeof(*rs)); - qemu_mutex_init(&rs->bitmap_mutex); - qemu_mutex_init(&rs->src_page_req_mutex); - QSIMPLEQ_INIT(&rs->src_page_requests); + *rsp =3D g_new0(RAMState, 1); + + qemu_mutex_init(&(*rsp)->bitmap_mutex); + qemu_mutex_init(&(*rsp)->src_page_req_mutex); + QSIMPLEQ_INIT(&(*rsp)->src_page_requests); =20 if (migrate_use_xbzrle()) { XBZRLE_cache_lock(); @@ -1813,6 +1816,8 @@ static int ram_state_init(RAMState *rs) if (!XBZRLE.cache) { XBZRLE_cache_unlock(); error_report("Error creating cache"); + g_free(*rsp); + *rsp =3D NULL; return -1; } XBZRLE_cache_unlock(); @@ -1821,6 +1826,8 @@ static int ram_state_init(RAMState *rs) XBZRLE.encoded_buf =3D g_try_malloc0(TARGET_PAGE_SIZE); if (!XBZRLE.encoded_buf) { error_report("Error allocating encoded_buf"); + g_free(*rsp); + *rsp =3D NULL; return -1; } =20 @@ -1829,6 +1836,8 @@ static int ram_state_init(RAMState *rs) error_report("Error allocating current_buf"); g_free(XBZRLE.encoded_buf); XBZRLE.encoded_buf =3D NULL; + g_free(*rsp); + *rsp =3D NULL; return -1; } } @@ -1838,7 +1847,7 @@ static int ram_state_init(RAMState *rs) =20 qemu_mutex_lock_ramlist(); rcu_read_lock(); - ram_state_reset(rs); + ram_state_reset(*rsp); =20 /* Skip setting bitmap if there is no RAM */ if (ram_bytes_total()) { @@ -1860,10 +1869,10 @@ static int ram_state_init(RAMState *rs) * Count the total number of pages used by ram blocks not including any * gaps due to alignment or unplugs. */ - rs->migration_dirty_pages =3D ram_bytes_total() >> TARGET_PAGE_BITS; + (*rsp)->migration_dirty_pages =3D ram_bytes_total() >> TARGET_PAGE_BIT= S; =20 memory_global_dirty_log_start(); - migration_bitmap_sync(rs); + migration_bitmap_sync(*rsp); qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_iothread(); rcu_read_unlock(); @@ -1888,16 +1897,16 @@ static int ram_state_init(RAMState *rs) */ static int ram_save_setup(QEMUFile *f, void *opaque) { - RAMState *rs =3D opaque; + RAMState **rsp =3D opaque; RAMBlock *block; =20 /* migration has already setup the bitmap, reuse it. */ if (!migration_in_colo_state()) { - if (ram_state_init(rs) < 0) { + if (ram_state_init(rsp) !=3D 0) { return -1; - } + } } - rs->f =3D f; + (*rsp)->f =3D f; =20 rcu_read_lock(); =20 @@ -1932,7 +1941,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque) */ static int ram_save_iterate(QEMUFile *f, void *opaque) { - RAMState *rs =3D opaque; + RAMState **temp =3D opaque; + RAMState *rs =3D *temp; int ret; int i; int64_t t0; @@ -2007,7 +2017,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) */ static int ram_save_complete(QEMUFile *f, void *opaque) { - RAMState *rs =3D opaque; + RAMState **temp =3D opaque; + RAMState *rs =3D *temp; =20 rcu_read_lock(); =20 @@ -2044,7 +2055,8 @@ static void ram_save_pending(QEMUFile *f, void *opaqu= e, uint64_t max_size, uint64_t *non_postcopiable_pending, uint64_t *postcopiable_pending) { - RAMState *rs =3D opaque; + RAMState **temp =3D opaque; + RAMState *rs =3D *temp; uint64_t remaining_size; =20 remaining_size =3D rs->migration_dirty_pages * TARGET_PAGE_SIZE; --=20 2.9.4 From nobody Wed Nov 5 15:55:26 2025 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; 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 1496830272233605.0042796051122; Wed, 7 Jun 2017 03:11:12 -0700 (PDT) Received: from localhost ([::1]:42444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXvi-0006fW-L2 for importer@patchew.org; Wed, 07 Jun 2017 06:11:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIXkg-0005dE-QM for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIXkg-0005MI-22 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIXkf-0005M2-S9 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 05:59:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C900EC0587D3; Wed, 7 Jun 2017 09:59:44 +0000 (UTC) Received: from secure.mitica (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 495BA17A6B; Wed, 7 Jun 2017 09:59:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C900EC0587D3 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C900EC0587D3 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 11:59:26 +0200 Message-Id: <20170607095926.1834-8-quintela@redhat.com> In-Reply-To: <20170607095926.1834-1-quintela@redhat.com> References: <20170607095926.1834-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 07 Jun 2017 09:59:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/7] qemu/migration: fix the double free problem on from_src_file 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: lvivier@redhat.com, QingFeng Hao , dgilbert@redhat.com, peterx@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: QingFeng Hao In load_snapshot, mis->from_src_file is freed twice, the first free is by qemu_fclose, the second is by migration_incoming_state_destroy and it causes Illegal instruction exception. The fix is just to remove the first free. This problem is found by qemu-iotests case 068 since commit "660819b migration: shut src return path unconditionally". The error is: 068 1s ... - output mismatch (see 068.out.bad) --- tests/qemu-iotests/068.out 2017-05-06 01:00:26.417270437 +0200 +++ 068.out.bad 2017-06-03 13:59:55.360274640 +0200 @@ -6,6 +6,8 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm 0 (qemu) quit +./common.config: line 107: 242472 Illegal instruction (core dumped= ) ( if [ -n "${QEMU_NEED_PID}" ]; then + echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid"; +fi; exec "$QEMU_PROG" $QEMU_OPTIONS "$@" ) QEMU X.Y.Z monitor - type 'help' for more information -(qemu) quit -*** done +(qemu) *** done Signed-off-by: QingFeng Hao Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Signed-off-by: Juan Quintela --- migration/savevm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/migration/savevm.c b/migration/savevm.c index 1993ca2..745caae 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2276,7 +2276,6 @@ int load_snapshot(const char *name, Error **errp) =20 aio_context_acquire(aio_context); ret =3D qemu_loadvm_state(f); - qemu_fclose(f); aio_context_release(aio_context); =20 migration_incoming_state_destroy(); --=20 2.9.4