From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Leonardo Bras <leobras@redhat.com>
Cc: "Elena Ufimtseva" <elena.ufimtseva@oracle.com>,
"John G Johnson" <john.g.johnson@oracle.com>,
"Jagannathan Raman" <jag.raman@oracle.com>,
qemu-block@nongnu.org, "Juan Quintela" <quintela@redhat.com>,
qemu-devel@nongnu.org,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Fam Zheng" <fam@euphon.net>, "Eric Blake" <eblake@redhat.com>
Subject: Re: [PATCH v9 6/7] multifd: Send header packet without flags if zero-copy-send is enabled
Date: Tue, 26 Apr 2022 09:10:23 +0100 [thread overview]
Message-ID: <Ymeo74XfWOwe2Nob@redhat.com> (raw)
In-Reply-To: <20220425215055.611825-7-leobras@redhat.com>
On Mon, Apr 25, 2022 at 06:50:55PM -0300, Leonardo Bras wrote:
> Since d48c3a0445 ("multifd: Use a single writev on the send side"),
> sending the header packet and the memory pages happens in the same
> writev, which can potentially make the migration faster.
>
> Using channel-socket as example, this works well with the default copying
> mechanism of sendmsg(), but with zero-copy-send=true, it will cause
> the migration to often break.
>
> This happens because the header packet buffer gets reused quite often,
> and there is a high chance that by the time the MSG_ZEROCOPY mechanism get
> to send the buffer, it has already changed, sending the wrong data and
> causing the migration to abort.
>
> It means that, as it is, the buffer for the header packet is not suitable
> for sending with MSG_ZEROCOPY.
>
> In order to enable zero copy for multifd, send the header packet on an
> individual write(), without any flags, and the remanining pages with a
> writev(), as it was happening before. This only changes how a migration
> with zero-copy-send=true works, not changing any current behavior for
> migrations with zero-copy-send=false.
>
> Signed-off-by: Leonardo Bras <leobras@redhat.com>
> ---
> migration/multifd.c | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 15fb668e64..6c940aaa98 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -639,6 +639,8 @@ static void *multifd_send_thread(void *opaque)
> if (p->pending_job) {
> uint64_t packet_num = p->packet_num;
> uint32_t flags = p->flags;
> + int iov_offset = 0;
> +
No need for this if you change:
> p->iovs_num = 1;
if (!migrate_use_zero_copy_send()) {
p->iovs_num = 1;
}
> p->normal_num = 0;
>
> @@ -665,15 +667,36 @@ static void *multifd_send_thread(void *opaque)
> trace_multifd_send(p->id, packet_num, p->normal_num, flags,
> p->next_packet_size);
>
> - p->iov[0].iov_len = p->packet_len;
> - p->iov[0].iov_base = p->packet;
> + if (migrate_use_zero_copy_send()) {
> + /* Send header without zerocopy */
> + ret = qio_channel_write_all(p->c, (void *)p->packet,
> + p->packet_len, &local_err);
> + if (ret != 0) {
> + break;
> + }
> +
> + if (!p->normal_num) {
> + /* No pages will be sent */
> + goto skip_send;
> + }
Don't need this AFAIK, because the qio_channel_writev_all
call will be a no-op if iovs_num is zero
>
> - ret = qio_channel_writev_all(p->c, p->iov, p->iovs_num,
> + /* Skip first iov : header */
> + iov_offset = 1;
Don't need to set this
> + } else {
> + /* Send header using the same writev call */
> + p->iov[0].iov_len = p->packet_len;
> + p->iov[0].iov_base = p->packet;
> + }
> +
> + ret = qio_channel_writev_all(p->c, p->iov + iov_offset,
> + p->iovs_num - iov_offset,
> &local_err);
This wouldn't need changing if we don't reserve iovs[0] when
not required.
> +
> if (ret != 0) {
> break;
> }
>
> +skip_send:
> qemu_mutex_lock(&p->mutex);
> p->pending_job--;
> qemu_mutex_unlock(&p->mutex);
> --
> 2.36.0
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2022-04-26 8:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 21:50 [PATCH v9 0/7] MSG_ZEROCOPY + multifd Leonardo Bras
2022-04-25 21:50 ` [PATCH v9 1/7] QIOChannel: Add flags on io_writev and introduce io_flush callback Leonardo Bras
2022-04-25 21:50 ` [PATCH v9 2/7] QIOChannelSocket: Implement io_writev zero copy flag & io_flush for CONFIG_LINUX Leonardo Bras
2022-04-25 21:50 ` [PATCH v9 3/7] migration: Add zero-copy-send parameter for QMP/HMP for Linux Leonardo Bras
2022-05-04 10:48 ` Markus Armbruster
2022-05-04 17:19 ` Leonardo Bras Soares Passos
2022-04-25 21:50 ` [PATCH v9 4/7] migration: Add migrate_use_tls() helper Leonardo Bras
2022-04-25 21:50 ` [PATCH v9 5/7] multifd: multifd_send_sync_main now returns negative on error Leonardo Bras
2022-04-26 8:01 ` Daniel P. Berrangé
2022-04-26 12:59 ` Peter Xu
2022-04-26 16:08 ` Leonardo Bras Soares Passos
2022-04-25 21:50 ` [PATCH v9 6/7] multifd: Send header packet without flags if zero-copy-send is enabled Leonardo Bras
2022-04-26 8:10 ` Daniel P. Berrangé [this message]
2022-04-26 21:59 ` Leonardo Bras Soares Passos
2022-04-25 21:50 ` [PATCH v9 7/7] multifd: Implement zero copy write in multifd migration (multifd-zero-copy) Leonardo Bras
2022-04-26 16:02 ` Peter Xu
2022-04-26 22:58 ` Leonardo Bras Soares Passos
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=Ymeo74XfWOwe2Nob@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=elena.ufimtseva@oracle.com \
--cc=fam@euphon.net \
--cc=jag.raman@oracle.com \
--cc=john.g.johnson@oracle.com \
--cc=leobras@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-block@nongnu.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).