From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Juan Quintela <quintela@redhat.com>
Cc: qemu-devel@nongnu.org, lvivier@redhat.com, peterx@redhat.com
Subject: Re: [Qemu-devel] [PATCH 5/5] ram: Make RAMState dynamic
Date: Mon, 5 Jun 2017 16:00:10 +0100 [thread overview]
Message-ID: <20170605150009.GL2109@work-vm> (raw)
In-Reply-To: <20170601220813.30535-6-quintela@redhat.com>
* Juan Quintela (quintela@redhat.com) wrote:
> We create the variable while we are at migration and we remove it
> after migration.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/ram.c | 52 ++++++++++++++++++++++++++++++++--------------------
> 1 file changed, 32 insertions(+), 20 deletions(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index 6c48219..1164f14 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -199,7 +199,7 @@ struct RAMState {
> };
> typedef struct RAMState RAMState;
>
> -static RAMState ram_state;
> +static RAMState *ram_state;
>
> MigrationStats ram_counters;
>
> @@ -783,7 +783,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 = &ram_state;
> + RAMState *rs = ram_state;
> int bytes_sent, blen;
> uint8_t *p = block->host + (offset & TARGET_PAGE_MASK);
>
> @@ -1130,7 +1130,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 = &ram_state;
> + RAMState *rs = ram_state;
>
> ram_counters.postcopy_requests++;
> rcu_read_lock();
> @@ -1351,7 +1351,7 @@ void free_xbzrle_decoded_buf(void)
>
> static void ram_migration_cleanup(void *opaque)
> {
> - RAMState *rs = opaque;
> + RAMState **rsp = opaque;
> RAMBlock *block;
>
> /* caller have hold iothread lock or is in a bh, so there is
> @@ -1378,7 +1378,9 @@ static void ram_migration_cleanup(void *opaque)
> XBZRLE.zero_target_page = NULL;
> }
> XBZRLE_cache_unlock();
> - migration_page_queue_free(rs);
> + migration_page_queue_free(*rsp);
> + g_free(*rsp);
> + *rsp = NULL;
Yes, I think that's a safe place to free it.
> }
>
> static void ram_state_reset(RAMState *rs)
> @@ -1703,7 +1705,7 @@ static int postcopy_chunk_hostpages(MigrationState *ms, RAMBlock *block)
> */
> int ram_postcopy_send_discard_bitmap(MigrationState *ms)
> {
> - RAMState *rs = &ram_state;
> + RAMState *rs = ram_state;
> RAMBlock *block;
> int ret;
>
> @@ -1786,12 +1788,13 @@ err:
> return ret;
> }
>
> -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 = g_new0(RAMState, 1);
> +
> + qemu_mutex_init(&(*rsp)->bitmap_mutex);
> + qemu_mutex_init(&(*rsp)->src_page_req_mutex);
> + QSIMPLEQ_INIT(&(*rsp)->src_page_requests);
>
> if (migrate_use_xbzrle()) {
> XBZRLE_cache_lock();
> @@ -1802,6 +1805,8 @@ static int ram_state_init(RAMState *rs)
> if (!XBZRLE.cache) {
> XBZRLE_cache_unlock();
> error_report("Error creating cache");
> + g_free(*rsp);
> + *rsp = NULL;
> return -1;
> }
> XBZRLE_cache_unlock();
> @@ -1810,6 +1815,8 @@ static int ram_state_init(RAMState *rs)
> XBZRLE.encoded_buf = g_try_malloc0(TARGET_PAGE_SIZE);
> if (!XBZRLE.encoded_buf) {
> error_report("Error allocating encoded_buf");
> + g_free(*rsp);
> + *rsp = NULL;
> return -1;
> }
>
> @@ -1818,6 +1825,8 @@ static int ram_state_init(RAMState *rs)
> error_report("Error allocating current_buf");
> g_free(XBZRLE.encoded_buf);
> XBZRLE.encoded_buf = NULL;
> + g_free(*rsp);
> + *rsp = NULL;
> return -1;
> }
> }
> @@ -1827,7 +1836,7 @@ static int ram_state_init(RAMState *rs)
>
> qemu_mutex_lock_ramlist();
> rcu_read_lock();
> - ram_state_reset(rs);
> + ram_state_reset(*rsp);
>
> /* Skip setting bitmap if there is no RAM */
> if (ram_bytes_total()) {
> @@ -1852,7 +1861,7 @@ static int ram_state_init(RAMState *rs)
> ram_counters.remaining_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
>
> memory_global_dirty_log_start();
> - migration_bitmap_sync(rs);
> + migration_bitmap_sync(*rsp);
> qemu_mutex_unlock_ramlist();
> qemu_mutex_unlock_iothread();
> rcu_read_unlock();
> @@ -1877,16 +1886,16 @@ static int ram_state_init(RAMState *rs)
> */
> static int ram_save_setup(QEMUFile *f, void *opaque)
> {
> - RAMState *rs = opaque;
> + RAMState **rsp = opaque;
> RAMBlock *block;
>
> /* migration has already setup the bitmap, reuse it. */
> if (!migration_in_colo_state()) {
> - if (ram_state_init(rs) < 0) {
> + if (ram_state_init(rsp) != 0) {
> return -1;
> - }
> + }
> }
> - rs->f = f;
> + (*rsp)->f = f;
>
> rcu_read_lock();
>
> @@ -1921,7 +1930,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
> */
> static int ram_save_iterate(QEMUFile *f, void *opaque)
> {
> - RAMState *rs = opaque;
> + RAMState **temp = opaque;
> + RAMState *rs = *temp;
OK, to be honest my preference would be
RAMState *rs = *(RAMState **)opaque;
that I think works; but that's jus ttaste if you had to redo it.
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> int ret;
> int i;
> int64_t t0;
> @@ -1996,7 +2006,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
> */
> static int ram_save_complete(QEMUFile *f, void *opaque)
> {
> - RAMState *rs = opaque;
> + RAMState **temp = opaque;
> + RAMState *rs = *temp;
>
> rcu_read_lock();
>
> @@ -2033,7 +2044,8 @@ static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,
> uint64_t *non_postcopiable_pending,
> uint64_t *postcopiable_pending)
> {
> - RAMState *rs = opaque;
> + RAMState **temp = opaque;
> + RAMState *rs = *temp;
> uint64_t remaining_size;
>
> remaining_size = ram_counters.remaining_pages * TARGET_PAGE_SIZE;
> --
> 2.9.4
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2017-06-05 15:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-01 22:08 [Qemu-devel] [PATCH 0/5] Make RAMState dynamic Juan Quintela
2017-06-01 22:08 ` [Qemu-devel] [PATCH 1/5] ram: Call migration_page_queue_free() at ram_migration_cleanup() Juan Quintela
2017-06-05 11:24 ` Dr. David Alan Gilbert
2017-06-06 7:58 ` Peter Xu
2017-06-01 22:08 ` [Qemu-devel] [PATCH 2/5] ram: Move ZERO_TARGET_PAGE inside XBZRLE Juan Quintela
2017-06-05 11:27 ` Dr. David Alan Gilbert
2017-06-06 7:59 ` Peter Xu
2017-06-01 22:08 ` [Qemu-devel] [PATCH 3/5] migration: Print statistics about the number of remaining target pages Juan Quintela
2017-06-02 15:15 ` Eric Blake
2017-06-02 16:36 ` Juan Quintela
2017-06-06 17:48 ` Juan Quintela
2017-06-01 22:08 ` [Qemu-devel] [PATCH 4/5] ram: Use MigrationStats for statistics Juan Quintela
2017-06-05 12:34 ` Dr. David Alan Gilbert
2017-06-06 8:05 ` Peter Xu
2017-06-06 17:33 ` Juan Quintela
2017-06-07 3:08 ` Peter Xu
2017-06-01 22:08 ` [Qemu-devel] [PATCH 5/5] ram: Make RAMState dynamic Juan Quintela
2017-06-05 15:00 ` Dr. David Alan Gilbert [this message]
2017-06-06 8:16 ` Peter Xu
2017-06-06 17:39 ` Juan Quintela
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170605150009.GL2109@work-vm \
--to=dgilbert@redhat.com \
--cc=lvivier@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.