qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v8 42/54] Postcopy: Use helpers to map pages dur


From: Juan Quintela
Subject: Re: [Qemu-devel] [PATCH v8 42/54] Postcopy: Use helpers to map pages during migration
Date: Wed, 28 Oct 2015 11:58:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

"Dr. David Alan Gilbert (git)" <address@hidden> wrote:
> From: "Dr. David Alan Gilbert" <address@hidden>
>
> In postcopy, the destination guest is running at the same time
> as it's receiving pages; as we receive new pages we must put
> them into the guests address space atomically to avoid a running
> CPU accessing a partially written page.
>
> Use the helpers in postcopy-ram.c to map these pages.
>
> qemu_get_buffer_in_place is used to avoid a copy out of qemu_file
> in the case that postcopy is going to do a copy anyway.
>
> Signed-off-by: Dr. David Alan Gilbert <address@hidden>
> ---
>  migration/ram.c | 128 
> +++++++++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 103 insertions(+), 25 deletions(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index 487e838..6d9cfb5 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -1848,7 +1848,17 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, 
> void *host)
>  /* Must be called from within a rcu critical section.
>   * Returns a pointer from within the RCU-protected ram_list.
>   */
> +/*
> + * Read a RAMBlock ID from the stream f, find the host address of the
> + * start of that block and add on 'offset'
> + *
> + * f: Stream to read from
> + * mis: MigrationIncomingState
> + * offset: Offset within the block
> + * flags: Page flags (mostly to see if it's a continuation of previous block)
> + */
>  static inline void *host_from_stream_offset(QEMUFile *f,
> +                                            MigrationIncomingState *mis,
>                                              ram_addr_t offset,
>                                              int flags)
>  {


Uh, oh, we change the prototype of host_from_stream_offset() but not the
function itself?  Strange, no?

> +        postcopy_place_needed = false;
> +        if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE |
> +                     RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
> +            host = host_from_stream_offset(f, mis, addr, flags);
> +            if (!host) {
> +                error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
> +                ret = -EINVAL;
> +                break;
> +            }
> +            page_buffer = host;

You can move this bit of code here in a different patch, makes review easier.
all_zero can also be on that patch.

> +            if (postcopy_running) {


As discussed on irc, I still think that having a RAM_SAVE_HOST_PAGE make
everything much, much clearer and easier, but I agree that is not
trivial with current code.


You are reusingh ram_load, but have lots and lots of

if (postcopy_running) {

} else {

}

I think that it would be easier to just have:

if (postcopy_running) {
     ram_load_postcopy()
} else {
     ram_load_precopy{}
}

You duplicate a bit of code, but remove lots of ifs from the equation,
not sure which one is really easier.  I just hate bits like the
following one.

> @@ -2062,32 +2123,36 @@ static int ram_load(QEMUFile *f, void *opaque, int 
> version_id)
>              }
>              break;
>          case RAM_SAVE_FLAG_COMPRESS:
>              ch = qemu_get_byte(f);
> -            ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
> +            if (!postcopy_running) {
> +                ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
> +            } else {
> +                memset(page_buffer, ch, TARGET_PAGE_SIZE);
> +                if (ch) {
> +                    all_zero = false;
> +                }
> +            }


> @@ -2123,6 +2188,19 @@ static int ram_load(QEMUFile *f, void *opaque, int 
> version_id)
>                  ret = -EINVAL;
>              }
>          }
> +
> +        if (postcopy_place_needed) {
> +            /* This gets called at the last target page in the host page */
> +            if (!all_zero) {
> +                ret = postcopy_place_page(mis, host + TARGET_PAGE_SIZE -
> +                                               qemu_host_page_size,
> +                                               postcopy_place_source);
> +            } else {
> +                ret = postcopy_place_page_zero(mis,
> +                                               host + TARGET_PAGE_SIZE -
> +                                                 qemu_host_page_size);
> +            }
> +        }


Hahahaha, just change the if or the variable name.

having a

if (!cond) {
   f1();
} else {
   f2();
}

makes no sense, better to have

if (cond) {
   f2()
} else {
   f1()
}
no?



The patch itself is ok.

Thanks, Juan.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]