Zero copy improvements (QIOChannel + multifd)
v2 cover Zero copy improvements (QIOChannel + multifd)
The first patch avoid spuriously returning 1 [*] when zero-copy flush is attempted before any buffer was sent using MSG_ZEROCOPY.
[*] zero-copy not being used, even though it's enabled and supported by kernel
The second patch introduces a new migration stat (zero-copy-copied) that will be used to keep track of [*].
Honestly I would like some help with this naming, which I don't think is quite good, but I could also not think on anything better.
The third patch keeps track of how many zero-copy flushes retured 1 [*]
Leonardo Bras (3):
QIOChannelSocket: Fix zero-copy flush returning code 1 when nothing
sent
Add zero-copy-copied migration stat
migration/multifd: Warn user when zerocopy not working
qapi/migration.json | 5 ++++- migration/ram.h | 2 ++ io/channel-socket.c | 8 +++++++- migration/migration.c | 1 + migration/multifd.c | 2 ++ migration/ram.c | 5 +++++ monitor/hmp-cmds.c | 4 ++++ 7 files changed, 25 insertions(+), 2 deletions(-)
Signature · 1 line
2.36.1
PATCH v2 1/3 QIOChannelSocket: Fix zero-copy flush returning code 1 when nothing sent
If flush is called when no buffer was sent with MSG_ZEROCOPY, it currently returns 1. This return code should be used only when Linux fails to use MSG_ZEROCOPY on a lot of sendmsg().
Fix this by returning early from flush if no sendmsg(...,MSG_ZEROCOPY) was attempted.
--- io/channel-socket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
io/channel-socket.c +7 -1
@@ -716,12 +716,18 @@ static int qio_channel_socket_flush(QIOChannel *ioc,struct cmsghdr *cm;char control[CMSG_SPACE (sizeof (*serr))];int received; -int ret =1 ; +int ret; + +if (!sioc->zero_copy_queued) { +return 0 ; + } msg.msg_control = control; msg.msg_controllen =sizeof (control);memset (control,0 ,sizeof (control)); + ret =1 ; +while (sioc->zero_copy_sent < sioc->zero_copy_queued) { received =recvmsg (sioc->fd, &msg,MSG_ERRQUEUE );if (received <0 ) {
Signature · 1 line
2.36.1
PATCH v2 2/3 Add zero-copy-copied migration stat
In reply to Leonardo Bras--- qapi/migration.json | 5 ++++- migration/migration.c | 1 + monitor/hmp-cmds.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)
qapi/migration.json +4 -1
@@ -55,6 +55,9 @@ # @postcopy-bytes: The number of bytes sent during the post-copy phase # (since 7.0). # +# @zero-copy-copied: The number of zero-copy flushes that reported data sent +# using zero-copy that ended up being copied. (since 7.2) +# # Since: 0.14 ## { 'struct': 'MigrationStats',
@@ -65,7 +68,7 @@ 'postcopy-requests' : 'int', 'page-size' : 'int', 'multifd-bytes' : 'uint64', 'pages-per-second' : 'uint64', 'precopy-bytes' : 'uint64', 'downtime-bytes' : 'uint64', - 'postcopy-bytes' : 'uint64' } } + 'postcopy-bytes' : 'uint64', 'zero-copy-copied' : 'uint64' } } ## # @XBZRLECacheStats:
migration/migration.c +1 -0
@@ -1034,6 +1034,7 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s) info->ram->precopy_bytes = ram_counters.precopy_bytes; info->ram->downtime_bytes = ram_counters.downtime_bytes; info->ram->postcopy_bytes = ram_counters.postcopy_bytes; + info->ram->zero_copy_copied = ram_counters.zero_copy_copied;if (migrate_use_xbzrle ()) { info->has_xbzrle_cache = true;
monitor/hmp-cmds.c +4 -0
@@ -307,6 +307,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)monitor_printf (mon,"postcopy ram: %" PRIu64" kbytes\n" , info->ram->postcopy_bytes >>10 ); } +if (info->ram->zero_copy_copied) { +monitor_printf (mon,"zero-copy copied: %" PRIu64" iterations\n" , + info->ram->zero_copy_copied); + } }if (info->has_disk) {
Signature · 1 line
2.36.1
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 12 lines · Leonardo Bras
Signed-off-by Leonardo Bras <[email protected]>--- qapi/migration.json | 5 ++++- migration/migration.c | 1 + monitor/hmp-cmds.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)qapi/migration.json +0
-0
qapi/migration.json line 59
Quoted 5 lines
qapi/migration.json +2
-0@@ -55,6 +55,9 @@ # @postcopy-bytes: The number of bytes sent during the post-copy phase # (since 7.0). # +# @zero-copy-copied: The number of zero-copy flushes that reported data sent +# using zero-copy that ended up being copied. (since 7.2)
The description feels awkward. What's a "zero-copy flush", and why should the user care? I figure what users care about is the number of all-zero pages we had to "copy", i.e. send the bulky way. Is this what @zero-copy-copied reports?
Quoted 13 lines
qapi/migration.json +2
-1+# # Since: 0.14 ## { 'struct': 'MigrationStats',@@ -65,7 +68,7 @@ 'postcopy-requests' : 'int', 'page-size' : 'int', 'multifd-bytes' : 'uint64', 'pages-per-second' : 'uint64', 'precopy-bytes' : 'uint64', 'downtime-bytes' : 'uint64', - 'postcopy-bytes' : 'uint64' } } + 'postcopy-bytes' : 'uint64', 'zero-copy-copied' : 'uint64' } } ## # @XBZRLECacheStats:
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Leonardo Bras
Signed-off-by Leonardo Bras <[email protected]>--- qapi/migration.json | 5 ++++- migration/migration.c | 1 + monitor/hmp-cmds.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)
Quoted 15 lines
qapi/migration.json line 59
Quoted 10 lines
qapi/migration.json +2
-0@@ -55,6 +55,9 @@ # @postcopy-bytes: The number of bytes sent during the post-copy phase # (since 7.0). # +# @zero-copy-copied: The number of zero-copy flushes that reported data sent +# using zero-copy that ended up being copied. (since 7.2)The description feels awkward. What's a "zero-copy flush", and why should the user care? I figure what users care about is the number of all-zero pages we had to "copy", i.e. send the bulky way. Is this what @zero-copy-copied reports?
MigrationCapability field @zero-copy-send instructs QEMU to try to avoid copying data between userspace and kernel space when transmitting RAM region.
Even if the kernel supports zero copy, it is not guaranteed to happen, it is merely a request to try.
QEMU periodically (once per migration iteration) flushes outstanding zero-copy requests and gets an indication back of whether any copies took place or not.
So this counter is a reflection of how many iterations resulted in zero-copy not being fully honoured.
IOW, ideally this counter will always be zero. If it is non-zero, then the magnitude gives a very very very rough guide to what's going on. If it is '1' then it was just a transient limitation. If it matches the number of migration iterations, then it is a more systemic limitation.
Incidentally, do we report the migration iteration count ? I thought we did, but i'm not finding it now that I look.
With regards,
Daniel
Signature · 3 lines
|: 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 :|
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 33 lines · Daniel P. Berrangé
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Leonardo Bras
Signed-off-by Leonardo Bras <[email protected]>--- qapi/migration.json | 5 ++++- migration/migration.c | 1 + monitor/hmp-cmds.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)Quoted 15 lines
qapi/migration.json line 59
Quoted 10 lines
qapi/migration.json +2
-0@@ -55,6 +55,9 @@ # @postcopy-bytes: The number of bytes sent during the post-copy phase # (since 7.0). # +# @zero-copy-copied: The number of zero-copy flushes that reported data sent +# using zero-copy that ended up being copied. (since 7.2)The description feels awkward. What's a "zero-copy flush", and why should the user care? I figure what users care about is the number of all-zero pages we had to "copy", i.e. send the bulky way. Is this what @zero-copy-copied reports?
MigrationCapability field @zero-copy-send instructs QEMU to try to avoid copying data between userspace and kernel space when transmitting RAM region.
Even if the kernel supports zero copy, it is not guaranteed to happen, it is merely a request to try.
Quoted 6 lines
QEMU periodically (once per migration iteration) flushes outstanding zero-copy requests and gets an indication back of whether any copies took place or not.
So this counter is a reflection of how many iterations resulted in zero-copy not being fully honoured.
Aha. Thanks!
Quoted 5 lines
IOW, ideally this counter will always be zero. If it is non-zero, then the magnitude gives a very very very rough guide to what's going on. If it is '1' then it was just a transient limitation. If it matches the number of migration iterations, then it is a more systemic limitation.
I think we should rephrase the documentation in terms of migration iterations instead of "flushes", because the latter is a non-obvious term without a definition.
Quoted 2 lines
Incidentally, do we report the migration iteration count ? I thought we did, but i'm not finding it now that I look.
I was about to ask exactly that. I'm not sure the value of @zero-copy-copied can be usefully interpreted without.
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
In reply to Daniel P. BerrangéQuoted 40 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Leonardo Bras
Signed-off-by Leonardo Bras <[email protected]>--- qapi/migration.json | 5 ++++- migration/migration.c | 1 + monitor/hmp-cmds.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)Quoted 15 lines
qapi/migration.json line 59
Quoted 10 lines
qapi/migration.json +2
-0@@ -55,6 +55,9 @@ # @postcopy-bytes: The number of bytes sent during the post-copy phase # (since 7.0). # +# @zero-copy-copied: The number of zero-copy flushes that reported data sent +# using zero-copy that ended up being copied. (since 7.2)The description feels awkward. What's a "zero-copy flush", and why should the user care? I figure what users care about is the number of all-zero pages we had to "copy", i.e. send the bulky way. Is this what @zero-copy-copied reports?
MigrationCapability field @zero-copy-send instructs QEMU to try to avoid copying data between userspace and kernel space when transmitting RAM region.
Even if the kernel supports zero copy, it is not guaranteed to happen, it is merely a request to try.
QEMU periodically (once per migration iteration) flushes outstanding zero-copy requests and gets an indication back of whether any copies took place or not.
So this counter is a reflection of how many iterations resulted in zero-copy not being fully honoured.
Quoted 8 lines
IOW, ideally this counter will always be zero. If it is non-zero, then the magnitude gives a very very very rough guide to what's going on. If it is '1' then it was just a transient limitation. If it matches the number of migration iterations, then it is a more systemic limitation.
Incidentally, do we report the migration iteration count ? I thought we did, but i'm not finding it now that I look.
Yes we do; it's dirty-sync-count
Dave
Quoted 8 lines
With regards,
DanielSignature · 3 lines
|: 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 :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 11 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Leonardo Bras
Signed-off-by Leonardo Bras <[email protected]>--- qapi/migration.json | 5 ++++- migration/migration.c | 1 + monitor/hmp-cmds.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
qapi/migration.json line 59
Quoted 10 lines
qapi/migration.json +2
-0@@ -55,6 +55,9 @@ # @postcopy-bytes: The number of bytes sent during the post-copy phase # (since 7.0). # +# @zero-copy-copied: The number of zero-copy flushes that reported data sent +# using zero-copy that ended up being copied. (since 7.2)
since 7.1, unless you're planning for really tortuous review :)
Quoted 26 lines
Quoted 26 lines
Quoted 5 lines
The description feels awkward. What's a "zero-copy flush", and why should the user care? I figure what users care about is the number of all-zero pages we had to "copy", i.e. send the bulky way. Is this what @zero-copy-copied reports?
MigrationCapability field @zero-copy-send instructs QEMU to try to avoid copying data between userspace and kernel space when transmitting RAM region.
Even if the kernel supports zero copy, it is not guaranteed to happen, it is merely a request to try.
QEMU periodically (once per migration iteration) flushes outstanding zero-copy requests and gets an indication back of whether any copies took place or not.
So this counter is a reflection of how many iterations resulted in zero-copy not being fully honoured.
IOW, ideally this counter will always be zero. If it is non-zero, then the magnitude gives a very very very rough guide to what's going on. If it is '1' then it was just a transient limitation. If it matches the number of migration iterations, then it is a more systemic limitation.
Quoted 4 lines
Quoted 2 lines
Incidentally, do we report the migration iteration count ? I thought we did, but i'm not finding it now that I look.
Yes we do; it's dirty-sync-count
Please rephrase the documentation of @zero-copy-copied in terms of @dirty-sync-count. Here's my attempt.
# @zero-copy-copied: Number of times dirty RAM synchronization could not
# avoid copying zero pages. This is between 0 and
# @dirty-sync-count. (since 7.1)
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 55 lines · Markus Armbruster
Quoted 11 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Leonardo Bras
Signed-off-by Leonardo Bras <[email protected]>--- qapi/migration.json | 5 ++++- migration/migration.c | 1 + monitor/hmp-cmds.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
qapi/migration.json line 59
Quoted 10 lines
qapi/migration.json +2
-0@@ -55,6 +55,9 @@ # @postcopy-bytes: The number of bytes sent during the post-copy phase # (since 7.0). # +# @zero-copy-copied: The number of zero-copy flushes that reported data sent +# using zero-copy that ended up being copied. (since 7.2)since 7.1, unless you're planning for really tortuous review :)
Quoted 29 lines
Quoted 28 lines
Quoted 5 lines
The description feels awkward. What's a "zero-copy flush", and why should the user care? I figure what users care about is the number of all-zero pages we had to "copy", i.e. send the bulky way. Is this what @zero-copy-copied reports?
MigrationCapability field @zero-copy-send instructs QEMU to try to avoid copying data between userspace and kernel space when transmitting RAM region.
Even if the kernel supports zero copy, it is not guaranteed to happen, it is merely a request to try.
QEMU periodically (once per migration iteration) flushes outstanding zero-copy requests and gets an indication back of whether any copies took place or not.
So this counter is a reflection of how many iterations resulted in zero-copy not being fully honoured.
IOW, ideally this counter will always be zero. If it is non-zero, then the magnitude gives a very very very rough guide to what's going on. If it is '1' then it was just a transient limitation. If it matches the number of migration iterations, then it is a more systemic limitation.
Incidentally, do we report the migration iteration count ? I thought we did, but i'm not finding it now that I look.
Quoted 8 lines
Quoted 1 line
Yes we do; it's dirty-sync-count
Please rephrase the documentation of @zero-copy-copied in terms of @dirty-sync-count. Here's my attempt.
# @zero-copy-copied: Number of times dirty RAM synchronization could not
# avoid copying zero pages. This is between 0 and
# @dirty-sync-count. (since 7.1)
Any one have preferences on the name - i get slight put off by the repeated word in the property name here.
@zero-copy-rejects ?
@zero-copy-misses ?
@zero-copy-fails ?
With regards,
Daniel
Signature · 3 lines
|: 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 :|
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 1 line · Daniel P. Berrangé
On Mon, Jul 04, 2022 at 02:04:41PM +0200, Markus Armbruster wrote:
[...]
Quoted 7 lines
Quoted 6 lines
Please rephrase the documentation of @zero-copy-copied in terms of @dirty-sync-count. Here's my attempt.
# @zero-copy-copied: Number of times dirty RAM synchronization could not
# avoid copying zero pages. This is between 0 and
# @dirty-sync-count. (since 7.1)
Quoted 6 lines
Any one have preferences on the name - i get slight put off by the repeated word in the property name here.
@zero-copy-rejects ?
@zero-copy-misses ?
@zero-copy-fails ?
I'd consider any of these an improvement. Not a native speaker, but perhaps "failures" instead of "fails".
We could also express the connection to @dirty-sync-count right in the name, like @dirty-sync-rejected-zero-copy, @dirty-sync-missed-zero-copy, @dirty-sync-failed-zero-copy. Or maybe -copies.
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 20 lines · Markus Armbruster
Quoted 1 line · Daniel P. Berrangé
On Mon, Jul 04, 2022 at 02:04:41PM +0200, Markus Armbruster wrote:
[...]
Quoted 7 lines
Quoted 6 lines
Please rephrase the documentation of @zero-copy-copied in terms of @dirty-sync-count. Here's my attempt.
# @zero-copy-copied: Number of times dirty RAM synchronization could not
# avoid copying zero pages. This is between 0 and
# @dirty-sync-count. (since 7.1)Quoted 6 lines
Any one have preferences on the name - i get slight put off by the repeated word in the property name here.
@zero-copy-rejects ?
@zero-copy-misses ?
@zero-copy-fails ?
Quoted 6 lines
I'd consider any of these an improvement. Not a native speaker, but perhaps "failures" instead of "fails".
We could also express the connection to @dirty-sync-count right in the name, like @dirty-sync-rejected-zero-copy, @dirty-sync-missed-zero-copy, @dirty-sync-failed-zero-copy. Or maybe -copies.
Yeah, @dirty-sync-missed-zero-copy is probably my favourite.
With regards,
Daniel
Signature · 3 lines
|: 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 :|
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Thanks Daniel, Markus and Dave for the feedback!
Quoted 5 lines · Daniel P. Berrangé
Quoted 4 lines · Markus Armbruster
Quoted 1 line · Daniel P. Berrangé
On Mon, Jul 04, 2022 at 02:04:41PM +0200, Markus Armbruster wrote:
[...]
Quoted 3 lines
since 7.1, unless you're planning for really tortuous review :)
Ok, updated :)
Quoted 8 lines
Quoted 8 lines
[...]
Quoted 6 lines
Quoted 6 lines
Please rephrase the documentation of @zero-copy-copied in terms of @dirty-sync-count. Here's my attempt.
# @zero-copy-copied: Number of times dirty RAM synchronization could not # avoid copying zero pages. This is between 0 and # @dirty-sync-count. (since 7.1)
That's a great description! And it's almost 100% correct.
IIUC dirty-sync-count increments on migration_bitmap_sync() once after each full dirty-bitmap scan, and even with multifd syncing at the same point, it could potentially have a increment per multifd channel.
The only change would be having:
# This is between 0 and @dirty-sync-count * @multifd-channel.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Any one have preferences on the name - i get slight put off by the repeated word in the property name here.
@zero-copy-rejects ?
@zero-copy-misses ?
@zero-copy-fails ?
Quoted 8 lines
Quoted 6 lines
I'd consider any of these an improvement. Not a native speaker, but perhaps "failures" instead of "fails".
We could also express the connection to @dirty-sync-count right in the name, like @dirty-sync-rejected-zero-copy, @dirty-sync-missed-zero-copy, @dirty-sync-failed-zero-copy. Or maybe -copies.
Yeah, @dirty-sync-missed-zero-copy is probably my favourite.
Ok then, this one there is :)
I will update my patchset with the suggestions, and I should publish a v3 shortly.
Best regards,
Leo
Quoted 3 lines
With regards,
Daniel
Re: [PATCH v2 2/3] Add zero-copy-copied migration stat
Quoted 18 lines · Leonardo Brás
Thanks Daniel, Markus and Dave for the feedback!
Quoted 5 lines · Daniel P. Berrangé
Quoted 4 lines · Markus Armbruster
Quoted 1 line · Daniel P. Berrangé
On Mon, Jul 04, 2022 at 02:04:41PM +0200, Markus Armbruster wrote:
[...]
Quoted 3 lines
since 7.1, unless you're planning for really tortuous review :)
Ok, updated :)
Quoted 2 lines
Quoted 2 lines
[...]
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Please rephrase the documentation of @zero-copy-copied in terms of @dirty-sync-count. Here's my attempt.
# @zero-copy-copied: Number of times dirty RAM synchronization could not # avoid copying zero pages. This is between 0 and # @dirty-sync-count. (since 7.1)
That's a great description! And it's almost 100% correct.
That's why we do patch review :)
Quoted 6 lines
IIUC dirty-sync-count increments on
migration_bitmap_sync()once after each full dirty-bitmap scan, and even with multifd syncing at the same point, it could potentially have a increment per multifd channel.The only change would be having:
# This is between 0 and @dirty-sync-count * @multifd-channel.
Makes sense to me.
[...]
PATCH v2 3/3 migration/multifd: Warn user when zerocopy not working
In reply to Leonardo BrasSome errors, like the lack of Scatter-Gather support by the network interface(NETIF_F_SG) may cause sendmsg(...,MSG_ZEROCOPY) to fail on using zero-copy, which causes it to fall back to the default copying mechanism.
After each full dirty-bitmap scan there should be a zero-copy flush happening, which checks for errors each of the previous calls to sendmsg(...,MSG_ZEROCOPY). If all of them failed to use zero-copy, then increment zero_copy_copied migration stat to let the user know about it.
--- migration/ram.h | 2 ++ migration/multifd.c | 2 ++ migration/ram.c | 5 +++++ 3 files changed, 9 insertions(+)
migration/ram.h +2 -0
@@ -87,4 +87,6 @@ void ram_write_tracking_prepare(void);int ram_write_tracking_start (void );void ram_write_tracking_stop (void ); +void zero_copy_copied (void ); +#endif
migration/multifd.c +2 -0
@@ -624,6 +624,8 @@ int multifd_send_sync_main(QEMUFile *f)if (ret <0 ) {error_report_err (err);return -1 ; + }else if (ret ==1 ) { +zero_copy_copied (); } } }
migration/ram.c +5 -0
@@ -407,6 +407,11 @@ static void ram_transferred_add(uint64_t bytes) ram_counters.transferred += bytes; } +void zero_copy_copied (void ) +{ + ram_counters.zero_copy_copied++; +} +/* used by the search for pages to send */ struct PageSearchStatus {/* Current block being searched */
Signature · 1 line
2.36.1