All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Prasad Pandit <ppandit@redhat.com>
Cc: Fabiano Rosas <farosas@suse.de>,
	qemu-devel@nongnu.org, berrange@redhat.com,
	Prasad Pandit <pjp@fedoraproject.org>
Subject: Re: [PATCH v10 3/3] migration: write zero pages when postcopy enabled
Date: Fri, 9 May 2025 11:11:21 -0400	[thread overview]
Message-ID: <aB4bGYf-EuGES73h@x1.local> (raw)
In-Reply-To: <CAE8KmOzi8Zzy5hE2SMdTbMZJQD5_XH34rfEP_B85jstUF9E08g@mail.gmail.com>

On Fri, May 09, 2025 at 11:34:06AM +0530, Prasad Pandit wrote:
> > > This patch should come before 1/3, otherwise it'll break bisect.
> > We could squash the two together, IMHO.
> 
> * It is adjusting the specific optimisation behaviour for the use case
> of when Multifd and Postcopy are enabled together. I think it's better
> as a separate patch. It'll help to see how that optimization
> changed/evolved over time.

I'd say it'll not help me.. no more than if you squash it with the first.
Both of them are tiny patches, and one should never apply this one alone.
I can just find no good reason to keep this single change separate.

But it's fine to me - you can keep it separate if you prefer, as long as
reorderd.

> 
> > > s/ones/once/
> > >
> > > > +         *
> > > > +         * It becomes a problem when both Multifd & Postcopy options are
> > > > +         * enabled. If the zero page which was skipped during multifd phase,
> > > > +         * is accessed during the Postcopy phase of the migration, a page
> > > > +         * fault occurs. But this page fault is not served because the
> > > > +         * 'receivedmap' says the zero page is already received. Thus the
> > > > +         * migration hangs.
> >
> > More accurate version could be: "the thread accessing the page may hang".
> > As discussed previously, in most cases IIUC it won't hang migration when
> > accessed in vcpu contexts, and will move again when all pages migrated
> > (triggers uffd unregistrations).
> 
> * Okay.
> 
> > Meanwhile when at it.. for postcopy if we want we don't need to set all
> > zeros.. just fault it in either using one inst.  Summary:
> >
> > void multifd_recv_zero_page_process(MultiFDRecvParams *p)
> > {
> >     bool received;
> >
> >     for (int i = 0; i < p->zero_num; i++) {
> >         void *page = p->host + p->zero[i];
> >
> >         received = ramblock_recv_bitmap_test_byte_offset(p->block, p->zero[i]);
> >         if (!received) {
> >             ramblock_recv_bitmap_set_offset(p->block, p->zero[i]);
> >         }
> 
> * Okay.
> 
> >         if (received) {
> >             /* If it has an older version, we must clear the whole page */
> >             memset(page, 0, multifd_ram_page_size());
> >         } else if (migrate_postcopy_ram()) {
> >             /*
> >              * If postcopy is enabled, we must fault in the page because
> >              * XXX (please fill in..).  Here we don't necessarily need to
> >              * zero the whole page because we know it must be pre-filled
> >              * with zeros anyway.
> >              */
> >             *(uint8_t *)page = 0;
> >
> > We could also use MADV_POPULATE_WRITE but not sure which one is faster, and
> > this might still be easier to follow anyway..
> 
> * Not sure how this is to work; During Multifd phase (Postcopy not
> running), when migrate_postcopy_ram() returns true, we shall raise a
> page fault here?

Yes, it's already received==0 reaching here, the page must be zero.  A
fault-in should be enough.

Well.. after a second thought, maybe better memset().. I need to double
check if "migration didn't receive this page" always means it's empty.  I
worry we have other part of code pre-loads the chunk.  So better not do
this trivial trick until some of us is sure..

My apologies of the confusion, please keep the good part of my comments,
and stick with memset().  Please ignore the fault inst and madvise for now.

> 
> * Could we zero-initialise the destination guest memory when migration
> starts? And not migrate the zero pages from the source at all? ie. we
> mark the page received in the 'receivedmap' as is done now, but page
> fault should also not happen for that guest address, because the
> memory was already zero-initialised at the beginning. I think there
> might be some scope to send zero-page entries piggy-backed with
> non-zero pages, whose contents are migrated anyway.
> 
> * Say there are 10 pages (4KB each, Total: 40KB). Of these 10 pages:
> 
>         Non-zero pages: 1, 2, 4, 7, 9, 10
>                Zero Pages: 3, 5-6 and 8
> 
> * We only migrate/send non-zero pages from source to the destination.
> When non-zero page-4 is migrated, an entry/hint of page-3 being zero
> one is piggy-backed with it. When non-zero page-7 is sent an
> entry/hint of pages-5-6 being zero pages is sent with it. Similarly a
> hint of page-8 being zero page is sent along with page-9. (thinking
> aloud)

Isn't that what multifd is doing already?

typedef struct {
    ...
    /*
     * This array contains the pointers to:
     *  - normal pages (initial normal_pages entries)
     *  - zero pages (following zero_pages entries)
     */
    uint64_t offset[];
} __attribute__((packed)) MultiFDPacket_t;

Or maybe I missed what you meant.

Thanks,

-- 
Peter Xu



  reply	other threads:[~2025-05-09 15:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08 12:28 [PATCH v10 0/3] Allow to enable multifd and postcopy migration together Prasad Pandit
2025-05-08 12:28 ` [PATCH v10 1/3] migration: enable multifd and postcopy together Prasad Pandit
2025-05-08 14:06   ` Fabiano Rosas
2025-05-08 12:28 ` [PATCH v10 2/3] tests/qtest/migration: add postcopy tests with multifd Prasad Pandit
2025-05-08 19:04   ` Peter Xu
2025-05-09  5:26     ` Prasad Pandit
2025-05-09 14:30       ` Peter Xu
2025-05-13  6:20         ` Prasad Pandit
2025-05-08 12:28 ` [PATCH v10 3/3] migration: write zero pages when postcopy enabled Prasad Pandit
2025-05-08 13:57   ` Fabiano Rosas
2025-05-08 15:40     ` Peter Xu
2025-05-09  6:04       ` Prasad Pandit
2025-05-09 15:11         ` Peter Xu [this message]
2025-05-12  6:26           ` Prasad Pandit
2025-05-12 15:06             ` Peter Xu
2025-05-09  5:31     ` Prasad Pandit

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=aB4bGYf-EuGES73h@x1.local \
    --to=peterx@redhat.com \
    --cc=berrange@redhat.com \
    --cc=farosas@suse.de \
    --cc=pjp@fedoraproject.org \
    --cc=ppandit@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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.