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,
kwolf@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 4/5] migration: Convert ram to use new load_setup()/load_cleanup()
Date: Wed, 21 Jun 2017 19:57:20 +0100 [thread overview]
Message-ID: <20170621185720.GA2099@work-vm> (raw)
In-Reply-To: <20170621102005.18701-5-quintela@redhat.com>
* Juan Quintela (quintela@redhat.com) wrote:
> Once there, I rename ram_migration_cleanup() to ram_save_cleanup().
> Notice that this is the first pass, and I only passed XBZRLE to the
> new scheme. Moved decoded_buf to inside XBZRLE struct.
> As a bonus, I don't have to export xbzrle functions from ram.c.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
Note a tiny comment typo below, but other than that:
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> --
>
> loaded_data pointer was needed because called can change it (dave)
> ---
> migration/migration.c | 3 ---
> migration/ram.c | 49 ++++++++++++++++++++++++++++++++++++-------------
> migration/ram.h | 1 -
> 3 files changed, 36 insertions(+), 17 deletions(-)
>
> diff --git a/migration/migration.c b/migration/migration.c
> index 520d9b9..aaaf7ff 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -350,9 +350,6 @@ static void process_incoming_migration_co(void *opaque)
> migrate_decompress_threads_join();
> exit(EXIT_FAILURE);
> }
> -
> - free_xbzrle_decoded_buf();
> -
> mis->bh = qemu_bh_new(process_incoming_migration_bh, mis);
> qemu_bh_schedule(mis->bh);
> }
> diff --git a/migration/ram.c b/migration/ram.c
> index 649f76c..a619e0b 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -85,11 +85,10 @@ static struct {
> QemuMutex lock;
> /* it will store a page full of zeros */
> uint8_t *zero_target_page;
> + /* buffer used for XBZRLE decoding */
> + uint8_t *decoded_buf;
> } XBZRLE;
>
> -/* buffer used for XBZRLE decoding */
> -static uint8_t *xbzrle_decoded_buf;
> -
> static void XBZRLE_cache_lock(void)
> {
> if (migrate_use_xbzrle())
> @@ -1350,13 +1349,18 @@ uint64_t ram_bytes_total(void)
> return total;
> }
>
> -void free_xbzrle_decoded_buf(void)
> +static void xbzrle_load_setup(void)
> {
> - g_free(xbzrle_decoded_buf);
> - xbzrle_decoded_buf = NULL;
> + XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE);
> }
>
> -static void ram_migration_cleanup(void *opaque)
> +static void xbzrle_load_cleanup(void)
> +{
> + g_free(XBZRLE.decoded_buf);
> + XBZRLE.decoded_buf = NULL;
> +}
> +
> +static void ram_save_cleanup(void *opaque)
> {
> RAMState **rsp = opaque;
> RAMBlock *block;
> @@ -2078,11 +2082,6 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
> int xh_flags;
> uint8_t *loaded_data;
>
> - if (!xbzrle_decoded_buf) {
> - xbzrle_decoded_buf = g_malloc(TARGET_PAGE_SIZE);
> - }
> - loaded_data = xbzrle_decoded_buf;
> -
> /* extract RLE header */
> xh_flags = qemu_get_byte(f);
> xh_len = qemu_get_be16(f);
> @@ -2096,7 +2095,9 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
> error_report("Failed to load XBZRLE page - len overflow!");
> return -1;
> }
> + loaded_data = XBZRLE.decoded_buf;
> /* load data and decode */
> + /* it can change laded_data to point to an internal buffer */
^--- o
> qemu_get_buffer_in_place(f, &loaded_data, xh_len);
>
> /* decode RLE */
> @@ -2310,6 +2311,26 @@ static void decompress_data_with_multi_threads(QEMUFile *f,
> }
>
> /**
> + * ram_load_setup: Setup RAM for migration incoming side
> + *
> + * Returns zero to indicate success and negative for error
> + *
> + * @f: QEMUFile where to receive the data
> + * @opaque: RAMState pointer
> + */
> +static int ram_load_setup(QEMUFile *f, void *opaque)
> +{
> + xbzrle_load_setup();
> + return 0;
> +}
> +
> +static int ram_load_cleanup(void *opaque)
> +{
> + xbzrle_load_cleanup();
> + return 0;
> +}
> +
> +/**
> * ram_postcopy_incoming_init: allocate postcopy data structures
> *
> * Returns 0 for success and negative if there was one error
> @@ -2629,7 +2650,9 @@ static SaveVMHandlers savevm_ram_handlers = {
> .save_live_complete_precopy = ram_save_complete,
> .save_live_pending = ram_save_pending,
> .load_state = ram_load,
> - .save_cleanup = ram_migration_cleanup,
> + .save_cleanup = ram_save_cleanup,
> + .load_setup = ram_load_setup,
> + .load_cleanup = ram_load_cleanup,
> };
>
> void ram_mig_init(void)
> diff --git a/migration/ram.h b/migration/ram.h
> index 6272eb0..a8b79a4 100644
> --- a/migration/ram.h
> +++ b/migration/ram.h
> @@ -47,7 +47,6 @@ void migrate_decompress_threads_join(void);
> uint64_t ram_pagesize_summary(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);
> void ram_debug_dump_bitmap(unsigned long *todump, bool expected,
> unsigned long pages);
> void ram_postcopy_migrated_memory_release(MigrationState *ms);
> --
> 2.9.4
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2017-06-21 18:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-21 10:20 [Qemu-devel] [PATCH v3 0/5] Create setup/cleanup methods for migration incoming side Juan Quintela
2017-06-21 10:20 ` [Qemu-devel] [PATCH v3 1/5] migration: Rename save_live_setup() to save_setup() Juan Quintela
2017-06-21 10:20 ` [Qemu-devel] [PATCH v3 2/5] migration: Rename cleanup() to save_cleanup() Juan Quintela
2017-06-21 10:20 ` [Qemu-devel] [PATCH v3 3/5] migration: Create load_setup()/cleanup() methods Juan Quintela
2017-06-22 10:33 ` Dr. David Alan Gilbert
2017-06-28 8:17 ` Juan Quintela
2017-06-21 10:20 ` [Qemu-devel] [PATCH v3 4/5] migration: Convert ram to use new load_setup()/load_cleanup() Juan Quintela
2017-06-21 18:57 ` Dr. David Alan Gilbert [this message]
2017-06-21 10:20 ` [Qemu-devel] [PATCH v3 5/5] migration: Make compression_threads use save/load_setup/cleanup() 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=20170621185720.GA2099@work-vm \
--to=dgilbert@redhat.com \
--cc=kwolf@redhat.com \
--cc=lvivier@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@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.