From: Peter Xu <peterx@redhat.com>
To: 徐闯 <xuchuangxclwt@bytedance.com>,
"Leonardo Bras Soares Passos" <lsoaresp@redhat.com>
Cc: "Leonardo Bras" <leobras@redhat.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org,
"Fam Zheng" <fam@euphon.net>,
"Markus Armbruster" <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"John G Johnson" <john.g.johnson@oracle.com>,
"Jagannathan Raman" <jag.raman@oracle.com>,
"Elena Ufimtseva" <elena.ufimtseva@oracle.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
lizefan.x@bytedance.com, zhouyibo@bytedance.com
Subject: Re: [External] [PATCH v13 3/8] QIOChannelSocket: Implement io_writev zero copy flag & io_flush for CONFIG_LINUX
Date: Wed, 1 Jun 2022 09:58:08 -0400 [thread overview]
Message-ID: <YpdwcHu7I8dGDimt@xz-m1.local> (raw)
In-Reply-To: <b2fae41c-7f47-9bf1-21b9-1b123818a262@bytedance.com>
On Wed, Jun 01, 2022 at 05:37:10PM +0800, 徐闯 wrote:
>
> On 2022/5/13 下午2:28, Leonardo Bras wrote:
> > For CONFIG_LINUX, implement the new zero copy flag and the optional callback
> > io_flush on QIOChannelSocket, but enables it only when MSG_ZEROCOPY
> > feature is available in the host kernel, which is checked on
> > qio_channel_socket_connect_sync()
> >
> > qio_channel_socket_flush() was implemented by counting how many times
> > sendmsg(...,MSG_ZEROCOPY) was successfully called, and then reading the
> > socket's error queue, in order to find how many of them finished sending.
> > Flush will loop until those counters are the same, or until some error occurs.
> >
> > Notes on using writev() with QIO_CHANNEL_WRITE_FLAG_ZERO_COPY:
> > 1: Buffer
> > - As MSG_ZEROCOPY tells the kernel to use the same user buffer to avoid copying,
> > some caution is necessary to avoid overwriting any buffer before it's sent.
> > If something like this happen, a newer version of the buffer may be sent instead.
> > - If this is a problem, it's recommended to call qio_channel_flush() before freeing
> > or re-using the buffer.
> >
> > 2: Locked memory
> > - When using MSG_ZERCOCOPY, the buffer memory will be locked after queued, and
> > unlocked after it's sent.
> > - Depending on the size of each buffer, and how often it's sent, it may require
> > a larger amount of locked memory than usually available to non-root user.
> > - If the required amount of locked memory is not available, writev_zero_copy
> > will return an error, which can abort an operation like migration,
> > - Because of this, when an user code wants to add zero copy as a feature, it
> > requires a mechanism to disable it, so it can still be accessible to less
> > privileged users.
> >
> > Signed-off-by: Leonardo Bras <leobras@redhat.com>
> > Reviewed-by: Peter Xu <peterx@redhat.com>
> > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> > Reviewed-by: Juan Quintela <quintela@redhat.com>
> > ---
> > include/io/channel-socket.h | 2 +
> > io/channel-socket.c | 116 ++++++++++++++++++++++++++++++++++--
> > 2 files changed, 114 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
> > index e747e63514..513c428fe4 100644
> > --- a/include/io/channel-socket.h
> > +++ b/include/io/channel-socket.h
> > @@ -47,6 +47,8 @@ struct QIOChannelSocket {
> > socklen_t localAddrLen;
> > struct sockaddr_storage remoteAddr;
> > socklen_t remoteAddrLen;
> > + ssize_t zero_copy_queued;
> > + ssize_t zero_copy_sent;
> > };
> Hi, Leonardo. I'm also paying attention to the application of MSG_ZEROCOPY
> in live migration recently. I noticed that you defined a member
> `zero_copy_queued` in the struct QIOChannelSocket, but I can't find out
> where the value of this member has been changed in your patch. Can you
> answer it for me?
>
Good point.. it should probably be increased when queuing the pages. We'd
better fix it up or it seems the flush() will be literally an no-op..
Two things in qio_channel_socket_flush() we can do to make sure it'll work
as expected, imo:
1) make ret=-1 as initial value, rather than 1 - we only check negative
errors in the caller so we could have missed a positive "1"
2) add a tracepoint into the loop of updating zero_copy_sent
Leo, what's your take?
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2022-06-01 14:02 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-13 6:28 [PATCH v13 0/8] MSG_ZEROCOPY + multifd Leonardo Bras
2022-05-13 6:28 ` [PATCH v13 1/8] meson.build: Fix docker-test-build@alpine when including linux/errqueue.h Leonardo Bras
2022-05-16 11:13 ` Dr. David Alan Gilbert
2022-05-16 11:17 ` Daniel P. Berrangé
2022-05-16 11:30 ` Dr. David Alan Gilbert
2022-05-16 11:35 ` Daniel P. Berrangé
2022-05-16 12:51 ` Dr. David Alan Gilbert
2022-05-16 14:04 ` Daniel P. Berrangé
2022-05-13 6:28 ` [PATCH v13 2/8] QIOChannel: Add flags on io_writev and introduce io_flush callback Leonardo Bras
2022-05-13 6:28 ` [PATCH v13 3/8] QIOChannelSocket: Implement io_writev zero copy flag & io_flush for CONFIG_LINUX Leonardo Bras
2022-06-01 9:37 ` [External] " 徐闯
2022-06-01 13:58 ` Peter Xu [this message]
2022-06-08 5:37 ` Leonardo Bras Soares Passos
2022-06-08 11:41 ` Peter Xu
2022-06-08 18:14 ` Leonardo Bras Soares Passos
2022-06-08 20:23 ` Peter Xu
2022-06-13 20:58 ` Leonardo Bras Soares Passos
2022-06-13 22:53 ` Peter Xu
2022-06-14 3:14 ` Leonardo Bras Soares Passos
2022-06-08 5:24 ` Leonardo Bras Soares Passos
2022-06-08 6:48 ` chuang xu
2022-06-14 13:09 ` chuang xu
2022-06-14 14:14 ` Dr. David Alan Gilbert
2022-06-15 14:44 ` chuang xu
2022-05-13 6:28 ` [PATCH v13 4/8] migration: Add zero-copy-send parameter for QMP/HMP for Linux Leonardo Bras
2022-05-13 6:28 ` [PATCH v13 5/8] migration: Add migrate_use_tls() helper Leonardo Bras
2022-05-13 6:28 ` [PATCH v13 6/8] multifd: multifd_send_sync_main now returns negative on error Leonardo Bras
2022-05-13 6:28 ` [PATCH v13 7/8] multifd: Send header packet without flags if zero-copy-send is enabled Leonardo Bras
2022-05-13 6:28 ` [PATCH v13 8/8] multifd: Implement zero copy write in multifd migration (multifd-zero-copy) Leonardo Bras
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=YpdwcHu7I8dGDimt@xz-m1.local \
--to=peterx@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@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=lizefan.x@bytedance.com \
--cc=lsoaresp@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=xuchuangxclwt@bytedance.com \
--cc=zhouyibo@bytedance.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).