* [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy
@ 2026-11-20 16:20 Jie Song
2026-11-26 12:52 ` Fabiano Rosas
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jie Song @ 2026-11-20 16:20 UTC (permalink / raw)
To: qemu-devel; +Cc: alex, clg, peterx, farosas, avihaih, Jie Song
From: Jie Song <songjie_yewu@cmss.chinamobile.com>
Replace qemu_put_buffer with qemu_put_buffer_async + qemu_fflush in
vfio_save_block to avoid an unnecessary memcpy of device state data
through QEMUFile's 32 KiB internal buffer.
With qemu_put_buffer_async, the data_buffer pointer is added directly
to the iov array. Since the next read overwrites the same buffer,
flush immediately so that the channel has consumed the data before
the buffer is reused.
Signed-off-by: Jie Song <songjie_yewu@cmss.chinamobile.com>
---
hw/vfio/migration.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 69d50cebdd..e363250b79 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -476,7 +476,8 @@ static ssize_t vfio_save_block(QEMUFile *f, VFIOMigration *migration)
qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE);
qemu_put_be64(f, data_size);
- qemu_put_buffer(f, migration->data_buffer, data_size);
+ qemu_put_buffer_async(f, migration->data_buffer, data_size, false);
+ qemu_fflush(f);
vfio_migration_add_bytes_transferred(data_size);
trace_vfio_save_block(migration->vbasedev->name, data_size);
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy
2026-11-20 16:20 [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy Jie Song
@ 2026-11-26 12:52 ` Fabiano Rosas
2026-11-27 12:49 ` Peter Xu
2026-11-30 7:56 ` Cédric Le Goater
2 siblings, 0 replies; 4+ messages in thread
From: Fabiano Rosas @ 2026-11-26 12:52 UTC (permalink / raw)
To: Jie Song, qemu-devel; +Cc: alex, clg, peterx, avihaih, Jie Song
Jie Song <mail@jiesong.me> writes:
> From: Jie Song <songjie_yewu@cmss.chinamobile.com>
>
> Replace qemu_put_buffer with qemu_put_buffer_async + qemu_fflush in
> vfio_save_block to avoid an unnecessary memcpy of device state data
> through QEMUFile's 32 KiB internal buffer.
>
> With qemu_put_buffer_async, the data_buffer pointer is added directly
> to the iov array. Since the next read overwrites the same buffer,
> flush immediately so that the channel has consumed the data before
> the buffer is reused.
>
> Signed-off-by: Jie Song <songjie_yewu@cmss.chinamobile.com>
> ---
> hw/vfio/migration.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 69d50cebdd..e363250b79 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -476,7 +476,8 @@ static ssize_t vfio_save_block(QEMUFile *f, VFIOMigration *migration)
>
> qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE);
> qemu_put_be64(f, data_size);
> - qemu_put_buffer(f, migration->data_buffer, data_size);
> + qemu_put_buffer_async(f, migration->data_buffer, data_size, false);
> + qemu_fflush(f);
> vfio_migration_add_bytes_transferred(data_size);
>
> trace_vfio_save_block(migration->vbasedev->name, data_size);
Acked-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy
2026-11-20 16:20 [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy Jie Song
2026-11-26 12:52 ` Fabiano Rosas
@ 2026-11-27 12:49 ` Peter Xu
2026-11-30 7:56 ` Cédric Le Goater
2 siblings, 0 replies; 4+ messages in thread
From: Peter Xu @ 2026-11-27 12:49 UTC (permalink / raw)
To: Jie Song; +Cc: qemu-devel, alex, clg, farosas, avihaih, Jie Song
On Sat, Nov 21, 2026 at 12:20:26AM +0800, Jie Song wrote:
> From: Jie Song <songjie_yewu@cmss.chinamobile.com>
>
> Replace qemu_put_buffer with qemu_put_buffer_async + qemu_fflush in
> vfio_save_block to avoid an unnecessary memcpy of device state data
> through QEMUFile's 32 KiB internal buffer.
>
> With qemu_put_buffer_async, the data_buffer pointer is added directly
> to the iov array. Since the next read overwrites the same buffer,
> flush immediately so that the channel has consumed the data before
> the buffer is reused.
>
> Signed-off-by: Jie Song <songjie_yewu@cmss.chinamobile.com>
Showing some number would always be nicer, but in this case it seems we
have two buffer sizes almost constant (32K for qemufile, 1MB for vfio), so
it seems always a win,
Reviewed-by: Peter Xu <peterx@redhat.com>
Thanks,
--
Peter Xu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy
2026-11-20 16:20 [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy Jie Song
2026-11-26 12:52 ` Fabiano Rosas
2026-11-27 12:49 ` Peter Xu
@ 2026-11-30 7:56 ` Cédric Le Goater
2 siblings, 0 replies; 4+ messages in thread
From: Cédric Le Goater @ 2026-11-30 7:56 UTC (permalink / raw)
To: Jie Song, qemu-devel; +Cc: alex, peterx, farosas, avihaih, Jie Song
On 11/20/26 17:20, Jie Song wrote:
> From: Jie Song <songjie_yewu@cmss.chinamobile.com>
>
> Replace qemu_put_buffer with qemu_put_buffer_async + qemu_fflush in
> vfio_save_block to avoid an unnecessary memcpy of device state data
> through QEMUFile's 32 KiB internal buffer.
>
> With qemu_put_buffer_async, the data_buffer pointer is added directly
> to the iov array. Since the next read overwrites the same buffer,
> flush immediately so that the channel has consumed the data before
> the buffer is reused.
>
> Signed-off-by: Jie Song <songjie_yewu@cmss.chinamobile.com>
> ---
> hw/vfio/migration.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 69d50cebdd..e363250b79 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -476,7 +476,8 @@ static ssize_t vfio_save_block(QEMUFile *f, VFIOMigration *migration)
>
> qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE);
> qemu_put_be64(f, data_size);
> - qemu_put_buffer(f, migration->data_buffer, data_size);
> + qemu_put_buffer_async(f, migration->data_buffer, data_size, false);
> + qemu_fflush(f);
> vfio_migration_add_bytes_transferred(data_size);
>
> trace_vfio_save_block(migration->vbasedev->name, data_size);
I will queue this change for QEMU 12.0.
Thanks,
C.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-30 7:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 16:20 [PATCH] vfio/migration: Use qemu_put_buffer_async to avoid an extra copy Jie Song
2026-11-26 12:52 ` Fabiano Rosas
2026-11-27 12:49 ` Peter Xu
2026-11-30 7:56 ` Cédric Le Goater
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.