From nobody Sun Feb 8 23:51:57 2026 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