All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Lukas Straub <lukasstraub2@web.de>
Cc: qemu-devel@nongnu.org, Fabiano Rosas <farosas@suse.de>,
	Laurent Vivier <lvivier@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Zhang Chen <zhangckid@gmail.com>,
	Juan Quintela <quintela@trasno.org>
Subject: Re: [PATCH 1/3] multifd: Add colo support
Date: Tue, 6 Jan 2026 14:54:55 -0500	[thread overview]
Message-ID: <aV1oj75xvV8IfrU8@x1.local> (raw)
In-Reply-To: <20251230-colo_unit_test_multifd-v1-1-f9734bc74c71@web.de>

On Tue, Dec 30, 2025 at 03:05:44PM +0100, Lukas Straub wrote:
> Like in the normal ram_load() path, put the received pages into the
> colo cache and mark the pages in the bitmap so that they will be
> flushed to the guest later.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> Signed-off-by: Lukas Straub <lukasstraub2@web.de>
> ---
>  migration/meson.build    |  2 +-
>  migration/multifd-colo.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
>  migration/multifd-colo.h | 26 ++++++++++++++++++++++
>  migration/multifd.c      | 14 +++++++++---
>  4 files changed, 95 insertions(+), 4 deletions(-)
> 
> diff --git a/migration/meson.build b/migration/meson.build
> index 16909d54c5110fc5d8187fd3a68c4a5b08b59ea7..1e59fe4f1f0bbfffed90df38e8f39fa87bceb9b9 100644
> --- a/migration/meson.build
> +++ b/migration/meson.build
> @@ -40,7 +40,7 @@ system_ss.add(files(
>  ), gnutls, zlib)
>  
>  if get_option('replication').allowed()
> -  system_ss.add(files('colo-failover.c', 'colo.c'))
> +  system_ss.add(files('colo-failover.c', 'colo.c', 'multifd-colo.c'))
>  else
>    system_ss.add(files('colo-stubs.c'))
>  endif
> diff --git a/migration/multifd-colo.c b/migration/multifd-colo.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..05a81e57b2bda517cbc0844b4f03dc78453f6af8
> --- /dev/null
> +++ b/migration/multifd-colo.c
> @@ -0,0 +1,57 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * multifd colo implementation
> + *
> + * Copyright (c) Lukas Straub <lukasstraub2@web.de>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "exec/target_page.h"
> +#include "qemu/error-report.h"
> +#include "qapi/error.h"
> +#include "ram.h"
> +#include "multifd.h"
> +#include "options.h"
> +#include "io/channel-socket.h"
> +#include "migration/colo.h"
> +#include "multifd-colo.h"
> +#include "system/ramblock.h"
> +
> +void multifd_colo_prepare_recv(MultiFDRecvParams *p)
> +{
> +    if (!migrate_colo()) {

We should avoid invoking *_colo_*() function, then check COLO enabled or
not only reaching here.  Instead, we'd check "migrate_colo()" first and
invoke it only if it's enabled.

> +        return;
> +    }
> +
> +    assert(p->block->colo_cache);
> +
> +    /*
> +     * While we're still in precopy state (not yet in colo state), we copy
> +     * received pages to both guest and cache. No need to set dirty bits,
> +     * since guest and cache memory are in sync.
> +     */
> +    if (migration_incoming_in_colo_state()) {
> +        colo_record_bitmap(p->block, p->normal, p->normal_num);
> +    }
> +    p->host = p->block->colo_cache;

May want to update the comment of "host" then, because it isn't always
pointing to ramblock's buffer now when COLO is enabled.

> +}
> +
> +void multifd_colo_process_recv(MultiFDRecvParams *p)
> +{
> +    if (!migrate_colo()) {

Same here.

> +        return;
> +    }
> +
> +    if (!migration_incoming_in_colo_state()) {
> +        for (int i = 0; i < p->normal_num; i++) {
> +            void *guest = p->block->host + p->normal[i];
> +            void *cache = p->host + p->normal[i];
> +            memcpy(guest, cache, multifd_ram_page_size());
> +        }
> +    }
> +    p->host = p->block->host;
> +}
> diff --git a/migration/multifd-colo.h b/migration/multifd-colo.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..82eaf3f48c47de2f090f9de52f9d57a337d4754a
> --- /dev/null
> +++ b/migration/multifd-colo.h
> @@ -0,0 +1,26 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * multifd colo header
> + *
> + * Copyright (c) Lukas Straub <lukasstraub2@web.de>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#ifndef QEMU_MIGRATION_MULTIFD_COLO_H
> +#define QEMU_MIGRATION_MULTIFD_COLO_H
> +
> +#ifdef CONFIG_REPLICATION
> +
> +void multifd_colo_prepare_recv(MultiFDRecvParams *p);
> +void multifd_colo_process_recv(MultiFDRecvParams *p);
> +
> +#else
> +
> +static inline void multifd_colo_prepare_recv(MultiFDRecvParams *p) {}
> +static inline void multifd_colo_process_recv(MultiFDRecvParams *p) {}
> +
> +#endif
> +#endif
> diff --git a/migration/multifd.c b/migration/multifd.c
> index bf6da85af8a1e207235ce06b8dbace33beded6d8..9006f73cc5b52e8814da107c0b5c867ee6d03a95 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -29,6 +29,7 @@
>  #include "qemu-file.h"
>  #include "trace.h"
>  #include "multifd.h"
> +#include "multifd-colo.h"
>  #include "threadinfo.h"
>  #include "options.h"
>  #include "qemu/yank.h"
> @@ -1398,11 +1399,18 @@ static void *multifd_recv_thread(void *opaque)
>              if (is_device_state) {
>                  assert(use_packets);
>                  ret = multifd_device_state_recv(p, &local_err);
> +                if (ret != 0) {
> +                    break;
> +                }
>              } else {
> +                multifd_colo_prepare_recv(p);
> +
>                  ret = multifd_recv_state->ops->recv(p, &local_err);
> -            }
> -            if (ret != 0) {
> -                break;
> +                if (ret != 0) {
> +                    break;
> +                }
> +
> +                multifd_colo_process_recv(p);

Personally I'd suggest we introduce multifd_ram_state_recv() and put
everything there.

Thanks,

>              }
>          } else if (is_device_state) {
>              error_setg(&local_err,
> 
> -- 
> 2.39.5
> 

-- 
Peter Xu



  reply	other threads:[~2026-01-06 19:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-30 14:05 [PATCH 0/3] migration: Add COLO multifd support and COLO migration unit test Lukas Straub
2025-12-30 14:05 ` [PATCH 1/3] multifd: Add colo support Lukas Straub
2026-01-06 19:54   ` Peter Xu [this message]
2026-01-15 22:43     ` Lukas Straub
2025-12-30 14:05 ` [PATCH 2/3] migration-test: Add -snapshot option for COLO Lukas Straub
2026-01-06 19:55   ` Peter Xu
2026-01-15 22:37     ` Lukas Straub
2025-12-30 14:05 ` [PATCH 3/3] migration-test: Add COLO migration unit test Lukas Straub
2026-01-06 20:03   ` Peter Xu
2026-01-15 22:35     ` Lukas Straub
2026-01-15 22:42       ` Peter Xu
2025-12-30 15:02 ` [PATCH 0/3] migration: Add COLO multifd support and " Peter Xu
2026-01-04  5:44   ` Zhang Chen
2026-01-04  5:48     ` Zhang Chen
2026-01-06 19:48     ` Peter Xu
2026-01-15 21:45       ` Lukas Straub
2026-01-06 20:05 ` Peter Xu

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=aV1oj75xvV8IfrU8@x1.local \
    --to=peterx@redhat.com \
    --cc=farosas@suse.de \
    --cc=lukasstraub2@web.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@trasno.org \
    --cc=zhangckid@gmail.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.