* [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-06-08 8:49 ` Zhang, Chen
2022-07-14 9:41 ` Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Juan Quintela
` (11 subsequent siblings)
12 siblings, 2 replies; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
Reorder the structures so we can know if the fields are:
- Read only
- Their own locking (i.e. sems)
- Protected by 'mutex'
- Only for the multifd channel
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/multifd.h | 90 ++++++++++++++++++++++++++-------------------
1 file changed, 53 insertions(+), 37 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index 4d8d89e5e5..345cfdb50c 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -65,7 +65,9 @@ typedef struct {
} MultiFDPages_t;
typedef struct {
- /* this fields are not changed once the thread is created */
+ /* Fiields are only written at creating/deletion time */
+ /* No lock required for them, they are read only */
+
/* channel number */
uint8_t id;
/* channel thread name */
@@ -74,39 +76,47 @@ typedef struct {
QemuThread thread;
/* communication channel */
QIOChannel *c;
- /* sem where to wait for more work */
- QemuSemaphore sem;
- /* this mutex protects the following parameters */
- QemuMutex mutex;
- /* is this channel thread running */
- bool running;
- /* should this thread finish */
- bool quit;
/* is the yank function registered */
bool registered_yank;
+ /* packet allocated len */
+ uint32_t packet_len;
+ /* multifd flags for sending ram */
+ int write_flags;
+
+ /* sem where to wait for more work */
+ QemuSemaphore sem;
+ /* syncs main thread and channels */
+ QemuSemaphore sem_sync;
+
+ /* this mutex protects the following parameters */
+ QemuMutex mutex;
+ /* is this channel thread running */
+ bool running;
+ /* should this thread finish */
+ bool quit;
+ /* multifd flags for each packet */
+ uint32_t flags;
+ /* global number of generated multifd packets */
+ uint64_t packet_num;
/* thread has work to do */
int pending_job;
- /* array of pages to sent */
+ /* array of pages to sent.
+ * The owner of 'pages' depends of 'pending_job' value:
+ * pending_job == 0 -> migration_thread can use it.
+ * pending_job != 0 -> multifd_channel can use it.
+ */
MultiFDPages_t *pages;
- /* packet allocated len */
- uint32_t packet_len;
+
+ /* thread local variables. No locking required */
+
/* pointer to the packet */
MultiFDPacket_t *packet;
- /* multifd flags for sending ram */
- int write_flags;
- /* multifd flags for each packet */
- uint32_t flags;
/* size of the next packet that contains pages */
uint32_t next_packet_size;
- /* global number of generated multifd packets */
- uint64_t packet_num;
- /* thread local variables */
/* packets sent through this channel */
uint64_t num_packets;
/* non zero pages sent through this channel */
uint64_t total_normal_pages;
- /* syncs main thread and channels */
- QemuSemaphore sem_sync;
/* buffers to send */
struct iovec *iov;
/* number of iovs used */
@@ -120,7 +130,9 @@ typedef struct {
} MultiFDSendParams;
typedef struct {
- /* this fields are not changed once the thread is created */
+ /* Fiields are only written at creating/deletion time */
+ /* No lock required for them, they are read only */
+
/* channel number */
uint8_t id;
/* channel thread name */
@@ -129,31 +141,35 @@ typedef struct {
QemuThread thread;
/* communication channel */
QIOChannel *c;
+ /* packet allocated len */
+ uint32_t packet_len;
+
+ /* syncs main thread and channels */
+ QemuSemaphore sem_sync;
+
/* this mutex protects the following parameters */
QemuMutex mutex;
/* is this channel thread running */
bool running;
/* should this thread finish */
bool quit;
+ /* multifd flags for each packet */
+ uint32_t flags;
+ /* global number of generated multifd packets */
+ uint64_t packet_num;
+
+ /* thread local variables. No locking required */
+
+ /* pointer to the packet */
+ MultiFDPacket_t *packet;
+ /* size of the next packet that contains pages */
+ uint32_t next_packet_size;
+ /* packets sent through this channel */
+ uint64_t num_packets;
/* ramblock host address */
uint8_t *host;
- /* packet allocated len */
- uint32_t packet_len;
- /* pointer to the packet */
- MultiFDPacket_t *packet;
- /* multifd flags for each packet */
- uint32_t flags;
- /* global number of generated multifd packets */
- uint64_t packet_num;
- /* thread local variables */
- /* size of the next packet that contains pages */
- uint32_t next_packet_size;
- /* packets sent through this channel */
- uint64_t num_packets;
/* non zero pages recv through this channel */
uint64_t total_normal_pages;
- /* syncs main thread and channels */
- QemuSemaphore sem_sync;
/* buffers to recv */
struct iovec *iov;
/* Pages that are not zero */
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* RE: [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params
2022-05-31 10:43 ` [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params Juan Quintela
@ 2022-06-08 8:49 ` Zhang, Chen
2022-07-19 14:31 ` Dr. David Alan Gilbert
2022-07-14 9:41 ` Dr. David Alan Gilbert
1 sibling, 1 reply; 30+ messages in thread
From: Zhang, Chen @ 2022-06-08 8:49 UTC (permalink / raw)
To: Juan Quintela, qemu-devel@nongnu.org
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Eduardo Habkost, Peter Xu, Leonardo Bras
> -----Original Message-----
> From: Qemu-devel <qemu-devel-
> bounces+chen.zhang=intel.com@nongnu.org> On Behalf Of Juan Quintela
> Sent: Tuesday, May 31, 2022 6:43 PM
> To: qemu-devel@nongnu.org
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>; Philippe Mathieu-
> Daudé <f4bug@amsat.org>; Yanan Wang <wangyanan55@huawei.com>; Dr.
> David Alan Gilbert <dgilbert@redhat.com>; Juan Quintela
> <quintela@redhat.com>; Eduardo Habkost <eduardo@habkost.net>; Peter
> Xu <peterx@redhat.com>; Leonardo Bras <leobras@redhat.com>
> Subject: [PATCH v7 01/13] multifd: Document the locking of
> MultiFD{Send/Recv}Params
>
> Reorder the structures so we can know if the fields are:
> - Read only
> - Their own locking (i.e. sems)
> - Protected by 'mutex'
> - Only for the multifd channel
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/multifd.h | 90 ++++++++++++++++++++++++++-------------------
> 1 file changed, 53 insertions(+), 37 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h index
> 4d8d89e5e5..345cfdb50c 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -65,7 +65,9 @@ typedef struct {
> } MultiFDPages_t;
>
> typedef struct {
> - /* this fields are not changed once the thread is created */
> + /* Fiields are only written at creating/deletion time */
S/Fiields/Fields
Thanks
Chen
> + /* No lock required for them, they are read only */
> +
> /* channel number */
> uint8_t id;
> /* channel thread name */
> @@ -74,39 +76,47 @@ typedef struct {
> QemuThread thread;
> /* communication channel */
> QIOChannel *c;
> - /* sem where to wait for more work */
> - QemuSemaphore sem;
> - /* this mutex protects the following parameters */
> - QemuMutex mutex;
> - /* is this channel thread running */
> - bool running;
> - /* should this thread finish */
> - bool quit;
> /* is the yank function registered */
> bool registered_yank;
> + /* packet allocated len */
> + uint32_t packet_len;
> + /* multifd flags for sending ram */
> + int write_flags;
> +
> + /* sem where to wait for more work */
> + QemuSemaphore sem;
> + /* syncs main thread and channels */
> + QemuSemaphore sem_sync;
> +
> + /* this mutex protects the following parameters */
> + QemuMutex mutex;
> + /* is this channel thread running */
> + bool running;
> + /* should this thread finish */
> + bool quit;
> + /* multifd flags for each packet */
> + uint32_t flags;
> + /* global number of generated multifd packets */
> + uint64_t packet_num;
> /* thread has work to do */
> int pending_job;
> - /* array of pages to sent */
> + /* array of pages to sent.
> + * The owner of 'pages' depends of 'pending_job' value:
> + * pending_job == 0 -> migration_thread can use it.
> + * pending_job != 0 -> multifd_channel can use it.
> + */
> MultiFDPages_t *pages;
> - /* packet allocated len */
> - uint32_t packet_len;
> +
> + /* thread local variables. No locking required */
> +
> /* pointer to the packet */
> MultiFDPacket_t *packet;
> - /* multifd flags for sending ram */
> - int write_flags;
> - /* multifd flags for each packet */
> - uint32_t flags;
> /* size of the next packet that contains pages */
> uint32_t next_packet_size;
> - /* global number of generated multifd packets */
> - uint64_t packet_num;
> - /* thread local variables */
> /* packets sent through this channel */
> uint64_t num_packets;
> /* non zero pages sent through this channel */
> uint64_t total_normal_pages;
> - /* syncs main thread and channels */
> - QemuSemaphore sem_sync;
> /* buffers to send */
> struct iovec *iov;
> /* number of iovs used */
> @@ -120,7 +130,9 @@ typedef struct {
> } MultiFDSendParams;
>
> typedef struct {
> - /* this fields are not changed once the thread is created */
> + /* Fiields are only written at creating/deletion time */
> + /* No lock required for them, they are read only */
> +
> /* channel number */
> uint8_t id;
> /* channel thread name */
> @@ -129,31 +141,35 @@ typedef struct {
> QemuThread thread;
> /* communication channel */
> QIOChannel *c;
> + /* packet allocated len */
> + uint32_t packet_len;
> +
> + /* syncs main thread and channels */
> + QemuSemaphore sem_sync;
> +
> /* this mutex protects the following parameters */
> QemuMutex mutex;
> /* is this channel thread running */
> bool running;
> /* should this thread finish */
> bool quit;
> + /* multifd flags for each packet */
> + uint32_t flags;
> + /* global number of generated multifd packets */
> + uint64_t packet_num;
> +
> + /* thread local variables. No locking required */
> +
> + /* pointer to the packet */
> + MultiFDPacket_t *packet;
> + /* size of the next packet that contains pages */
> + uint32_t next_packet_size;
> + /* packets sent through this channel */
> + uint64_t num_packets;
> /* ramblock host address */
> uint8_t *host;
> - /* packet allocated len */
> - uint32_t packet_len;
> - /* pointer to the packet */
> - MultiFDPacket_t *packet;
> - /* multifd flags for each packet */
> - uint32_t flags;
> - /* global number of generated multifd packets */
> - uint64_t packet_num;
> - /* thread local variables */
> - /* size of the next packet that contains pages */
> - uint32_t next_packet_size;
> - /* packets sent through this channel */
> - uint64_t num_packets;
> /* non zero pages recv through this channel */
> uint64_t total_normal_pages;
> - /* syncs main thread and channels */
> - QemuSemaphore sem_sync;
> /* buffers to recv */
> struct iovec *iov;
> /* Pages that are not zero */
> --
> 2.35.3
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params
2022-06-08 8:49 ` Zhang, Chen
@ 2022-07-19 14:31 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-19 14:31 UTC (permalink / raw)
To: Zhang, Chen
Cc: Juan Quintela, qemu-devel@nongnu.org, Marcel Apfelbaum,
Philippe Mathieu-Daudé, Yanan Wang, Eduardo Habkost,
Peter Xu, Leonardo Bras
* Zhang, Chen (chen.zhang@intel.com) wrote:
>
>
> > -----Original Message-----
> > From: Qemu-devel <qemu-devel-
> > bounces+chen.zhang=intel.com@nongnu.org> On Behalf Of Juan Quintela
> > Sent: Tuesday, May 31, 2022 6:43 PM
> > To: qemu-devel@nongnu.org
> > Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>; Philippe Mathieu-
> > Daudé <f4bug@amsat.org>; Yanan Wang <wangyanan55@huawei.com>; Dr.
> > David Alan Gilbert <dgilbert@redhat.com>; Juan Quintela
> > <quintela@redhat.com>; Eduardo Habkost <eduardo@habkost.net>; Peter
> > Xu <peterx@redhat.com>; Leonardo Bras <leobras@redhat.com>
> > Subject: [PATCH v7 01/13] multifd: Document the locking of
> > MultiFD{Send/Recv}Params
> >
> > Reorder the structures so we can know if the fields are:
> > - Read only
> > - Their own locking (i.e. sems)
> > - Protected by 'mutex'
> > - Only for the multifd channel
> >
> > Signed-off-by: Juan Quintela <quintela@redhat.com>
> > ---
> > migration/multifd.h | 90 ++++++++++++++++++++++++++-------------------
> > 1 file changed, 53 insertions(+), 37 deletions(-)
> >
> > diff --git a/migration/multifd.h b/migration/multifd.h index
> > 4d8d89e5e5..345cfdb50c 100644
> > --- a/migration/multifd.h
> > +++ b/migration/multifd.h
> > @@ -65,7 +65,9 @@ typedef struct {
> > } MultiFDPages_t;
> >
> > typedef struct {
> > - /* this fields are not changed once the thread is created */
> > + /* Fiields are only written at creating/deletion time */
>
> S/Fiields/Fields
Thanks, I've fixed that up.
> Thanks
> Chen
>
> > + /* No lock required for them, they are read only */
> > +
> > /* channel number */
> > uint8_t id;
> > /* channel thread name */
> > @@ -74,39 +76,47 @@ typedef struct {
> > QemuThread thread;
> > /* communication channel */
> > QIOChannel *c;
> > - /* sem where to wait for more work */
> > - QemuSemaphore sem;
> > - /* this mutex protects the following parameters */
> > - QemuMutex mutex;
> > - /* is this channel thread running */
> > - bool running;
> > - /* should this thread finish */
> > - bool quit;
> > /* is the yank function registered */
> > bool registered_yank;
> > + /* packet allocated len */
> > + uint32_t packet_len;
> > + /* multifd flags for sending ram */
> > + int write_flags;
> > +
> > + /* sem where to wait for more work */
> > + QemuSemaphore sem;
> > + /* syncs main thread and channels */
> > + QemuSemaphore sem_sync;
> > +
> > + /* this mutex protects the following parameters */
> > + QemuMutex mutex;
> > + /* is this channel thread running */
> > + bool running;
> > + /* should this thread finish */
> > + bool quit;
> > + /* multifd flags for each packet */
> > + uint32_t flags;
> > + /* global number of generated multifd packets */
> > + uint64_t packet_num;
> > /* thread has work to do */
> > int pending_job;
> > - /* array of pages to sent */
> > + /* array of pages to sent.
> > + * The owner of 'pages' depends of 'pending_job' value:
> > + * pending_job == 0 -> migration_thread can use it.
> > + * pending_job != 0 -> multifd_channel can use it.
> > + */
> > MultiFDPages_t *pages;
> > - /* packet allocated len */
> > - uint32_t packet_len;
> > +
> > + /* thread local variables. No locking required */
> > +
> > /* pointer to the packet */
> > MultiFDPacket_t *packet;
> > - /* multifd flags for sending ram */
> > - int write_flags;
> > - /* multifd flags for each packet */
> > - uint32_t flags;
> > /* size of the next packet that contains pages */
> > uint32_t next_packet_size;
> > - /* global number of generated multifd packets */
> > - uint64_t packet_num;
> > - /* thread local variables */
> > /* packets sent through this channel */
> > uint64_t num_packets;
> > /* non zero pages sent through this channel */
> > uint64_t total_normal_pages;
> > - /* syncs main thread and channels */
> > - QemuSemaphore sem_sync;
> > /* buffers to send */
> > struct iovec *iov;
> > /* number of iovs used */
> > @@ -120,7 +130,9 @@ typedef struct {
> > } MultiFDSendParams;
> >
> > typedef struct {
> > - /* this fields are not changed once the thread is created */
> > + /* Fiields are only written at creating/deletion time */
> > + /* No lock required for them, they are read only */
> > +
> > /* channel number */
> > uint8_t id;
> > /* channel thread name */
> > @@ -129,31 +141,35 @@ typedef struct {
> > QemuThread thread;
> > /* communication channel */
> > QIOChannel *c;
> > + /* packet allocated len */
> > + uint32_t packet_len;
> > +
> > + /* syncs main thread and channels */
> > + QemuSemaphore sem_sync;
> > +
> > /* this mutex protects the following parameters */
> > QemuMutex mutex;
> > /* is this channel thread running */
> > bool running;
> > /* should this thread finish */
> > bool quit;
> > + /* multifd flags for each packet */
> > + uint32_t flags;
> > + /* global number of generated multifd packets */
> > + uint64_t packet_num;
> > +
> > + /* thread local variables. No locking required */
> > +
> > + /* pointer to the packet */
> > + MultiFDPacket_t *packet;
> > + /* size of the next packet that contains pages */
> > + uint32_t next_packet_size;
> > + /* packets sent through this channel */
> > + uint64_t num_packets;
> > /* ramblock host address */
> > uint8_t *host;
> > - /* packet allocated len */
> > - uint32_t packet_len;
> > - /* pointer to the packet */
> > - MultiFDPacket_t *packet;
> > - /* multifd flags for each packet */
> > - uint32_t flags;
> > - /* global number of generated multifd packets */
> > - uint64_t packet_num;
> > - /* thread local variables */
> > - /* size of the next packet that contains pages */
> > - uint32_t next_packet_size;
> > - /* packets sent through this channel */
> > - uint64_t num_packets;
> > /* non zero pages recv through this channel */
> > uint64_t total_normal_pages;
> > - /* syncs main thread and channels */
> > - QemuSemaphore sem_sync;
> > /* buffers to recv */
> > struct iovec *iov;
> > /* Pages that are not zero */
> > --
> > 2.35.3
> >
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params
2022-05-31 10:43 ` [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params Juan Quintela
2022-06-08 8:49 ` Zhang, Chen
@ 2022-07-14 9:41 ` Dr. David Alan Gilbert
1 sibling, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-14 9:41 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> Reorder the structures so we can know if the fields are:
> - Read only
> - Their own locking (i.e. sems)
> - Protected by 'mutex'
> - Only for the multifd channel
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/multifd.h | 90 ++++++++++++++++++++++++++-------------------
> 1 file changed, 53 insertions(+), 37 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index 4d8d89e5e5..345cfdb50c 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -65,7 +65,9 @@ typedef struct {
> } MultiFDPages_t;
>
> typedef struct {
> - /* this fields are not changed once the thread is created */
> + /* Fiields are only written at creating/deletion time */
Other than the typo's that Chen spotted;
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> + /* No lock required for them, they are read only */
> +
> /* channel number */
> uint8_t id;
> /* channel thread name */
> @@ -74,39 +76,47 @@ typedef struct {
> QemuThread thread;
> /* communication channel */
> QIOChannel *c;
> - /* sem where to wait for more work */
> - QemuSemaphore sem;
> - /* this mutex protects the following parameters */
> - QemuMutex mutex;
> - /* is this channel thread running */
> - bool running;
> - /* should this thread finish */
> - bool quit;
> /* is the yank function registered */
> bool registered_yank;
> + /* packet allocated len */
> + uint32_t packet_len;
> + /* multifd flags for sending ram */
> + int write_flags;
> +
> + /* sem where to wait for more work */
> + QemuSemaphore sem;
> + /* syncs main thread and channels */
> + QemuSemaphore sem_sync;
> +
> + /* this mutex protects the following parameters */
> + QemuMutex mutex;
> + /* is this channel thread running */
> + bool running;
> + /* should this thread finish */
> + bool quit;
> + /* multifd flags for each packet */
> + uint32_t flags;
> + /* global number of generated multifd packets */
> + uint64_t packet_num;
> /* thread has work to do */
> int pending_job;
> - /* array of pages to sent */
> + /* array of pages to sent.
> + * The owner of 'pages' depends of 'pending_job' value:
> + * pending_job == 0 -> migration_thread can use it.
> + * pending_job != 0 -> multifd_channel can use it.
> + */
> MultiFDPages_t *pages;
> - /* packet allocated len */
> - uint32_t packet_len;
> +
> + /* thread local variables. No locking required */
> +
> /* pointer to the packet */
> MultiFDPacket_t *packet;
> - /* multifd flags for sending ram */
> - int write_flags;
> - /* multifd flags for each packet */
> - uint32_t flags;
> /* size of the next packet that contains pages */
> uint32_t next_packet_size;
> - /* global number of generated multifd packets */
> - uint64_t packet_num;
> - /* thread local variables */
> /* packets sent through this channel */
> uint64_t num_packets;
> /* non zero pages sent through this channel */
> uint64_t total_normal_pages;
> - /* syncs main thread and channels */
> - QemuSemaphore sem_sync;
> /* buffers to send */
> struct iovec *iov;
> /* number of iovs used */
> @@ -120,7 +130,9 @@ typedef struct {
> } MultiFDSendParams;
>
> typedef struct {
> - /* this fields are not changed once the thread is created */
> + /* Fiields are only written at creating/deletion time */
> + /* No lock required for them, they are read only */
> +
> /* channel number */
> uint8_t id;
> /* channel thread name */
> @@ -129,31 +141,35 @@ typedef struct {
> QemuThread thread;
> /* communication channel */
> QIOChannel *c;
> + /* packet allocated len */
> + uint32_t packet_len;
> +
> + /* syncs main thread and channels */
> + QemuSemaphore sem_sync;
> +
> /* this mutex protects the following parameters */
> QemuMutex mutex;
> /* is this channel thread running */
> bool running;
> /* should this thread finish */
> bool quit;
> + /* multifd flags for each packet */
> + uint32_t flags;
> + /* global number of generated multifd packets */
> + uint64_t packet_num;
> +
> + /* thread local variables. No locking required */
> +
> + /* pointer to the packet */
> + MultiFDPacket_t *packet;
> + /* size of the next packet that contains pages */
> + uint32_t next_packet_size;
> + /* packets sent through this channel */
> + uint64_t num_packets;
> /* ramblock host address */
> uint8_t *host;
> - /* packet allocated len */
> - uint32_t packet_len;
> - /* pointer to the packet */
> - MultiFDPacket_t *packet;
> - /* multifd flags for each packet */
> - uint32_t flags;
> - /* global number of generated multifd packets */
> - uint64_t packet_num;
> - /* thread local variables */
> - /* size of the next packet that contains pages */
> - uint32_t next_packet_size;
> - /* packets sent through this channel */
> - uint64_t num_packets;
> /* non zero pages recv through this channel */
> uint64_t total_normal_pages;
> - /* syncs main thread and channels */
> - QemuSemaphore sem_sync;
> /* buffers to recv */
> struct iovec *iov;
> /* Pages that are not zero */
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
2022-05-31 10:43 ` [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-14 9:58 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv,Send}Params Dr. David Alan Gilbert
2022-07-19 14:34 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 03/13] multifd: Create page_count " Juan Quintela
` (10 subsequent siblings)
12 siblings, 2 replies; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
We were calling qemu_target_page_size() left and right.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/multifd.h | 4 ++++
migration/multifd-zlib.c | 12 +++++-------
migration/multifd-zstd.c | 12 +++++-------
migration/multifd.c | 18 ++++++++----------
4 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index 345cfdb50c..9e07dd00f4 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -80,6 +80,8 @@ typedef struct {
bool registered_yank;
/* packet allocated len */
uint32_t packet_len;
+ /* guest page size */
+ uint32_t page_size;
/* multifd flags for sending ram */
int write_flags;
@@ -143,6 +145,8 @@ typedef struct {
QIOChannel *c;
/* packet allocated len */
uint32_t packet_len;
+ /* guest page size */
+ uint32_t page_size;
/* syncs main thread and channels */
QemuSemaphore sem_sync;
diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c
index 3a7ae44485..28349ff2e0 100644
--- a/migration/multifd-zlib.c
+++ b/migration/multifd-zlib.c
@@ -100,7 +100,6 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp)
static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
{
struct zlib_data *z = p->data;
- size_t page_size = qemu_target_page_size();
z_stream *zs = &z->zs;
uint32_t out_size = 0;
int ret;
@@ -114,7 +113,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
flush = Z_SYNC_FLUSH;
}
- zs->avail_in = page_size;
+ zs->avail_in = p->page_size;
zs->next_in = p->pages->block->host + p->normal[i];
zs->avail_out = available;
@@ -220,12 +219,11 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p)
static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
{
struct zlib_data *z = p->data;
- size_t page_size = qemu_target_page_size();
z_stream *zs = &z->zs;
uint32_t in_size = p->next_packet_size;
/* we measure the change of total_out */
uint32_t out_size = zs->total_out;
- uint32_t expected_size = p->normal_num * page_size;
+ uint32_t expected_size = p->normal_num * p->page_size;
uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
int ret;
int i;
@@ -252,7 +250,7 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
flush = Z_SYNC_FLUSH;
}
- zs->avail_out = page_size;
+ zs->avail_out = p->page_size;
zs->next_out = p->host + p->normal[i];
/*
@@ -266,8 +264,8 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
do {
ret = inflate(zs, flush);
} while (ret == Z_OK && zs->avail_in
- && (zs->total_out - start) < page_size);
- if (ret == Z_OK && (zs->total_out - start) < page_size) {
+ && (zs->total_out - start) < p->page_size);
+ if (ret == Z_OK && (zs->total_out - start) < p->page_size) {
error_setg(errp, "multifd %u: inflate generated too few output",
p->id);
return -1;
diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c
index d788d309f2..f4a8e1ed1f 100644
--- a/migration/multifd-zstd.c
+++ b/migration/multifd-zstd.c
@@ -113,7 +113,6 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp)
static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)
{
struct zstd_data *z = p->data;
- size_t page_size = qemu_target_page_size();
int ret;
uint32_t i;
@@ -128,7 +127,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)
flush = ZSTD_e_flush;
}
z->in.src = p->pages->block->host + p->normal[i];
- z->in.size = page_size;
+ z->in.size = p->page_size;
z->in.pos = 0;
/*
@@ -241,8 +240,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
{
uint32_t in_size = p->next_packet_size;
uint32_t out_size = 0;
- size_t page_size = qemu_target_page_size();
- uint32_t expected_size = p->normal_num * page_size;
+ uint32_t expected_size = p->normal_num * p->page_size;
uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
struct zstd_data *z = p->data;
int ret;
@@ -265,7 +263,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
for (i = 0; i < p->normal_num; i++) {
z->out.dst = p->host + p->normal[i];
- z->out.size = page_size;
+ z->out.size = p->page_size;
z->out.pos = 0;
/*
@@ -279,8 +277,8 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
do {
ret = ZSTD_decompressStream(z->zds, &z->out, &z->in);
} while (ret > 0 && (z->in.size - z->in.pos > 0)
- && (z->out.pos < page_size));
- if (ret > 0 && (z->out.pos < page_size)) {
+ && (z->out.pos < p->page_size));
+ if (ret > 0 && (z->out.pos < p->page_size)) {
error_setg(errp, "multifd %u: decompressStream buffer too small",
p->id);
return -1;
diff --git a/migration/multifd.c b/migration/multifd.c
index 9282ab6aa4..7505aa3412 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -87,15 +87,14 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp)
static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp)
{
MultiFDPages_t *pages = p->pages;
- size_t page_size = qemu_target_page_size();
for (int i = 0; i < p->normal_num; i++) {
p->iov[p->iovs_num].iov_base = pages->block->host + p->normal[i];
- p->iov[p->iovs_num].iov_len = page_size;
+ p->iov[p->iovs_num].iov_len = p->page_size;
p->iovs_num++;
}
- p->next_packet_size = p->normal_num * page_size;
+ p->next_packet_size = p->normal_num * p->page_size;
p->flags |= MULTIFD_FLAG_NOCOMP;
return 0;
}
@@ -139,7 +138,6 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p)
static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp)
{
uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
- size_t page_size = qemu_target_page_size();
if (flags != MULTIFD_FLAG_NOCOMP) {
error_setg(errp, "multifd %u: flags received %x flags expected %x",
@@ -148,7 +146,7 @@ static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp)
}
for (int i = 0; i < p->normal_num; i++) {
p->iov[i].iov_base = p->host + p->normal[i];
- p->iov[i].iov_len = page_size;
+ p->iov[i].iov_len = p->page_size;
}
return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp);
}
@@ -281,8 +279,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
{
MultiFDPacket_t *packet = p->packet;
- size_t page_size = qemu_target_page_size();
- uint32_t page_count = MULTIFD_PACKET_SIZE / page_size;
+ uint32_t page_count = MULTIFD_PACKET_SIZE / p->page_size;
RAMBlock *block;
int i;
@@ -344,7 +341,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
for (i = 0; i < p->normal_num; i++) {
uint64_t offset = be64_to_cpu(packet->offset[i]);
- if (offset > (block->used_length - page_size)) {
+ if (offset > (block->used_length - p->page_size)) {
error_setg(errp, "multifd: offset too long %" PRIu64
" (max " RAM_ADDR_FMT ")",
offset, block->used_length);
@@ -433,8 +430,7 @@ static int multifd_send_pages(QEMUFile *f)
p->packet_num = multifd_send_state->packet_num++;
multifd_send_state->pages = p->pages;
p->pages = pages;
- transferred = ((uint64_t) pages->num) * qemu_target_page_size()
- + p->packet_len;
+ transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
qemu_file_update_transfer(f, transferred);
ram_counters.multifd_bytes += transferred;
ram_counters.transferred += transferred;
@@ -939,6 +935,7 @@ int multifd_save_setup(Error **errp)
/* We need one extra place for the packet header */
p->iov = g_new0(struct iovec, page_count + 1);
p->normal = g_new0(ram_addr_t, page_count);
+ p->page_size = qemu_target_page_size();
if (migrate_use_zero_copy_send()) {
p->write_flags = QIO_CHANNEL_WRITE_FLAG_ZERO_COPY;
@@ -1186,6 +1183,7 @@ int multifd_load_setup(Error **errp)
p->name = g_strdup_printf("multifdrecv_%d", i);
p->iov = g_new0(struct iovec, page_count);
p->normal = g_new0(ram_addr_t, page_count);
+ p->page_size = qemu_target_page_size();
}
for (i = 0; i < thread_count; i++) {
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv,Send}Params
2022-05-31 10:43 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Juan Quintela
@ 2022-07-14 9:58 ` Dr. David Alan Gilbert
2022-07-19 14:34 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Dr. David Alan Gilbert
1 sibling, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-14 9:58 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> We were calling qemu_target_page_size() left and right.
Yeh, I still suspect the right answer is to make qemu_target_page_size()
trivially fast, but for now;
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/multifd.h | 4 ++++
> migration/multifd-zlib.c | 12 +++++-------
> migration/multifd-zstd.c | 12 +++++-------
> migration/multifd.c | 18 ++++++++----------
> 4 files changed, 22 insertions(+), 24 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index 345cfdb50c..9e07dd00f4 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -80,6 +80,8 @@ typedef struct {
> bool registered_yank;
> /* packet allocated len */
> uint32_t packet_len;
> + /* guest page size */
> + uint32_t page_size;
> /* multifd flags for sending ram */
> int write_flags;
>
> @@ -143,6 +145,8 @@ typedef struct {
> QIOChannel *c;
> /* packet allocated len */
> uint32_t packet_len;
> + /* guest page size */
> + uint32_t page_size;
>
> /* syncs main thread and channels */
> QemuSemaphore sem_sync;
> diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c
> index 3a7ae44485..28349ff2e0 100644
> --- a/migration/multifd-zlib.c
> +++ b/migration/multifd-zlib.c
> @@ -100,7 +100,6 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp)
> static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
> {
> struct zlib_data *z = p->data;
> - size_t page_size = qemu_target_page_size();
> z_stream *zs = &z->zs;
> uint32_t out_size = 0;
> int ret;
> @@ -114,7 +113,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
> flush = Z_SYNC_FLUSH;
> }
>
> - zs->avail_in = page_size;
> + zs->avail_in = p->page_size;
> zs->next_in = p->pages->block->host + p->normal[i];
>
> zs->avail_out = available;
> @@ -220,12 +219,11 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p)
> static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
> {
> struct zlib_data *z = p->data;
> - size_t page_size = qemu_target_page_size();
> z_stream *zs = &z->zs;
> uint32_t in_size = p->next_packet_size;
> /* we measure the change of total_out */
> uint32_t out_size = zs->total_out;
> - uint32_t expected_size = p->normal_num * page_size;
> + uint32_t expected_size = p->normal_num * p->page_size;
> uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> int ret;
> int i;
> @@ -252,7 +250,7 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
> flush = Z_SYNC_FLUSH;
> }
>
> - zs->avail_out = page_size;
> + zs->avail_out = p->page_size;
> zs->next_out = p->host + p->normal[i];
>
> /*
> @@ -266,8 +264,8 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
> do {
> ret = inflate(zs, flush);
> } while (ret == Z_OK && zs->avail_in
> - && (zs->total_out - start) < page_size);
> - if (ret == Z_OK && (zs->total_out - start) < page_size) {
> + && (zs->total_out - start) < p->page_size);
> + if (ret == Z_OK && (zs->total_out - start) < p->page_size) {
> error_setg(errp, "multifd %u: inflate generated too few output",
> p->id);
> return -1;
> diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c
> index d788d309f2..f4a8e1ed1f 100644
> --- a/migration/multifd-zstd.c
> +++ b/migration/multifd-zstd.c
> @@ -113,7 +113,6 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp)
> static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)
> {
> struct zstd_data *z = p->data;
> - size_t page_size = qemu_target_page_size();
> int ret;
> uint32_t i;
>
> @@ -128,7 +127,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)
> flush = ZSTD_e_flush;
> }
> z->in.src = p->pages->block->host + p->normal[i];
> - z->in.size = page_size;
> + z->in.size = p->page_size;
> z->in.pos = 0;
>
> /*
> @@ -241,8 +240,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
> {
> uint32_t in_size = p->next_packet_size;
> uint32_t out_size = 0;
> - size_t page_size = qemu_target_page_size();
> - uint32_t expected_size = p->normal_num * page_size;
> + uint32_t expected_size = p->normal_num * p->page_size;
> uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> struct zstd_data *z = p->data;
> int ret;
> @@ -265,7 +263,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
>
> for (i = 0; i < p->normal_num; i++) {
> z->out.dst = p->host + p->normal[i];
> - z->out.size = page_size;
> + z->out.size = p->page_size;
> z->out.pos = 0;
>
> /*
> @@ -279,8 +277,8 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
> do {
> ret = ZSTD_decompressStream(z->zds, &z->out, &z->in);
> } while (ret > 0 && (z->in.size - z->in.pos > 0)
> - && (z->out.pos < page_size));
> - if (ret > 0 && (z->out.pos < page_size)) {
> + && (z->out.pos < p->page_size));
> + if (ret > 0 && (z->out.pos < p->page_size)) {
> error_setg(errp, "multifd %u: decompressStream buffer too small",
> p->id);
> return -1;
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 9282ab6aa4..7505aa3412 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -87,15 +87,14 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp)
> static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp)
> {
> MultiFDPages_t *pages = p->pages;
> - size_t page_size = qemu_target_page_size();
>
> for (int i = 0; i < p->normal_num; i++) {
> p->iov[p->iovs_num].iov_base = pages->block->host + p->normal[i];
> - p->iov[p->iovs_num].iov_len = page_size;
> + p->iov[p->iovs_num].iov_len = p->page_size;
> p->iovs_num++;
> }
>
> - p->next_packet_size = p->normal_num * page_size;
> + p->next_packet_size = p->normal_num * p->page_size;
> p->flags |= MULTIFD_FLAG_NOCOMP;
> return 0;
> }
> @@ -139,7 +138,6 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p)
> static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp)
> {
> uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> - size_t page_size = qemu_target_page_size();
>
> if (flags != MULTIFD_FLAG_NOCOMP) {
> error_setg(errp, "multifd %u: flags received %x flags expected %x",
> @@ -148,7 +146,7 @@ static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp)
> }
> for (int i = 0; i < p->normal_num; i++) {
> p->iov[i].iov_base = p->host + p->normal[i];
> - p->iov[i].iov_len = page_size;
> + p->iov[i].iov_len = p->page_size;
> }
> return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp);
> }
> @@ -281,8 +279,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
> static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> {
> MultiFDPacket_t *packet = p->packet;
> - size_t page_size = qemu_target_page_size();
> - uint32_t page_count = MULTIFD_PACKET_SIZE / page_size;
> + uint32_t page_count = MULTIFD_PACKET_SIZE / p->page_size;
> RAMBlock *block;
> int i;
>
> @@ -344,7 +341,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> for (i = 0; i < p->normal_num; i++) {
> uint64_t offset = be64_to_cpu(packet->offset[i]);
>
> - if (offset > (block->used_length - page_size)) {
> + if (offset > (block->used_length - p->page_size)) {
> error_setg(errp, "multifd: offset too long %" PRIu64
> " (max " RAM_ADDR_FMT ")",
> offset, block->used_length);
> @@ -433,8 +430,7 @@ static int multifd_send_pages(QEMUFile *f)
> p->packet_num = multifd_send_state->packet_num++;
> multifd_send_state->pages = p->pages;
> p->pages = pages;
> - transferred = ((uint64_t) pages->num) * qemu_target_page_size()
> - + p->packet_len;
> + transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
> qemu_file_update_transfer(f, transferred);
> ram_counters.multifd_bytes += transferred;
> ram_counters.transferred += transferred;
> @@ -939,6 +935,7 @@ int multifd_save_setup(Error **errp)
> /* We need one extra place for the packet header */
> p->iov = g_new0(struct iovec, page_count + 1);
> p->normal = g_new0(ram_addr_t, page_count);
> + p->page_size = qemu_target_page_size();
>
> if (migrate_use_zero_copy_send()) {
> p->write_flags = QIO_CHANNEL_WRITE_FLAG_ZERO_COPY;
> @@ -1186,6 +1183,7 @@ int multifd_load_setup(Error **errp)
> p->name = g_strdup_printf("multifdrecv_%d", i);
> p->iov = g_new0(struct iovec, page_count);
> p->normal = g_new0(ram_addr_t, page_count);
> + p->page_size = qemu_target_page_size();
> }
>
> for (i = 0; i < thread_count; i++) {
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params
2022-05-31 10:43 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Juan Quintela
2022-07-14 9:58 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv,Send}Params Dr. David Alan Gilbert
@ 2022-07-19 14:34 ` Dr. David Alan Gilbert
1 sibling, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-19 14:34 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> We were calling qemu_target_page_size() left and right.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
This needs rebasing.
Dave
> ---
> migration/multifd.h | 4 ++++
> migration/multifd-zlib.c | 12 +++++-------
> migration/multifd-zstd.c | 12 +++++-------
> migration/multifd.c | 18 ++++++++----------
> 4 files changed, 22 insertions(+), 24 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index 345cfdb50c..9e07dd00f4 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -80,6 +80,8 @@ typedef struct {
> bool registered_yank;
> /* packet allocated len */
> uint32_t packet_len;
> + /* guest page size */
> + uint32_t page_size;
> /* multifd flags for sending ram */
> int write_flags;
>
> @@ -143,6 +145,8 @@ typedef struct {
> QIOChannel *c;
> /* packet allocated len */
> uint32_t packet_len;
> + /* guest page size */
> + uint32_t page_size;
>
> /* syncs main thread and channels */
> QemuSemaphore sem_sync;
> diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c
> index 3a7ae44485..28349ff2e0 100644
> --- a/migration/multifd-zlib.c
> +++ b/migration/multifd-zlib.c
> @@ -100,7 +100,6 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp)
> static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
> {
> struct zlib_data *z = p->data;
> - size_t page_size = qemu_target_page_size();
> z_stream *zs = &z->zs;
> uint32_t out_size = 0;
> int ret;
> @@ -114,7 +113,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
> flush = Z_SYNC_FLUSH;
> }
>
> - zs->avail_in = page_size;
> + zs->avail_in = p->page_size;
> zs->next_in = p->pages->block->host + p->normal[i];
>
> zs->avail_out = available;
> @@ -220,12 +219,11 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p)
> static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
> {
> struct zlib_data *z = p->data;
> - size_t page_size = qemu_target_page_size();
> z_stream *zs = &z->zs;
> uint32_t in_size = p->next_packet_size;
> /* we measure the change of total_out */
> uint32_t out_size = zs->total_out;
> - uint32_t expected_size = p->normal_num * page_size;
> + uint32_t expected_size = p->normal_num * p->page_size;
> uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> int ret;
> int i;
> @@ -252,7 +250,7 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
> flush = Z_SYNC_FLUSH;
> }
>
> - zs->avail_out = page_size;
> + zs->avail_out = p->page_size;
> zs->next_out = p->host + p->normal[i];
>
> /*
> @@ -266,8 +264,8 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp)
> do {
> ret = inflate(zs, flush);
> } while (ret == Z_OK && zs->avail_in
> - && (zs->total_out - start) < page_size);
> - if (ret == Z_OK && (zs->total_out - start) < page_size) {
> + && (zs->total_out - start) < p->page_size);
> + if (ret == Z_OK && (zs->total_out - start) < p->page_size) {
> error_setg(errp, "multifd %u: inflate generated too few output",
> p->id);
> return -1;
> diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c
> index d788d309f2..f4a8e1ed1f 100644
> --- a/migration/multifd-zstd.c
> +++ b/migration/multifd-zstd.c
> @@ -113,7 +113,6 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp)
> static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)
> {
> struct zstd_data *z = p->data;
> - size_t page_size = qemu_target_page_size();
> int ret;
> uint32_t i;
>
> @@ -128,7 +127,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)
> flush = ZSTD_e_flush;
> }
> z->in.src = p->pages->block->host + p->normal[i];
> - z->in.size = page_size;
> + z->in.size = p->page_size;
> z->in.pos = 0;
>
> /*
> @@ -241,8 +240,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
> {
> uint32_t in_size = p->next_packet_size;
> uint32_t out_size = 0;
> - size_t page_size = qemu_target_page_size();
> - uint32_t expected_size = p->normal_num * page_size;
> + uint32_t expected_size = p->normal_num * p->page_size;
> uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> struct zstd_data *z = p->data;
> int ret;
> @@ -265,7 +263,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
>
> for (i = 0; i < p->normal_num; i++) {
> z->out.dst = p->host + p->normal[i];
> - z->out.size = page_size;
> + z->out.size = p->page_size;
> z->out.pos = 0;
>
> /*
> @@ -279,8 +277,8 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp)
> do {
> ret = ZSTD_decompressStream(z->zds, &z->out, &z->in);
> } while (ret > 0 && (z->in.size - z->in.pos > 0)
> - && (z->out.pos < page_size));
> - if (ret > 0 && (z->out.pos < page_size)) {
> + && (z->out.pos < p->page_size));
> + if (ret > 0 && (z->out.pos < p->page_size)) {
> error_setg(errp, "multifd %u: decompressStream buffer too small",
> p->id);
> return -1;
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 9282ab6aa4..7505aa3412 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -87,15 +87,14 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp)
> static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp)
> {
> MultiFDPages_t *pages = p->pages;
> - size_t page_size = qemu_target_page_size();
>
> for (int i = 0; i < p->normal_num; i++) {
> p->iov[p->iovs_num].iov_base = pages->block->host + p->normal[i];
> - p->iov[p->iovs_num].iov_len = page_size;
> + p->iov[p->iovs_num].iov_len = p->page_size;
> p->iovs_num++;
> }
>
> - p->next_packet_size = p->normal_num * page_size;
> + p->next_packet_size = p->normal_num * p->page_size;
> p->flags |= MULTIFD_FLAG_NOCOMP;
> return 0;
> }
> @@ -139,7 +138,6 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p)
> static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp)
> {
> uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> - size_t page_size = qemu_target_page_size();
>
> if (flags != MULTIFD_FLAG_NOCOMP) {
> error_setg(errp, "multifd %u: flags received %x flags expected %x",
> @@ -148,7 +146,7 @@ static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp)
> }
> for (int i = 0; i < p->normal_num; i++) {
> p->iov[i].iov_base = p->host + p->normal[i];
> - p->iov[i].iov_len = page_size;
> + p->iov[i].iov_len = p->page_size;
> }
> return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp);
> }
> @@ -281,8 +279,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
> static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> {
> MultiFDPacket_t *packet = p->packet;
> - size_t page_size = qemu_target_page_size();
> - uint32_t page_count = MULTIFD_PACKET_SIZE / page_size;
> + uint32_t page_count = MULTIFD_PACKET_SIZE / p->page_size;
> RAMBlock *block;
> int i;
>
> @@ -344,7 +341,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> for (i = 0; i < p->normal_num; i++) {
> uint64_t offset = be64_to_cpu(packet->offset[i]);
>
> - if (offset > (block->used_length - page_size)) {
> + if (offset > (block->used_length - p->page_size)) {
> error_setg(errp, "multifd: offset too long %" PRIu64
> " (max " RAM_ADDR_FMT ")",
> offset, block->used_length);
> @@ -433,8 +430,7 @@ static int multifd_send_pages(QEMUFile *f)
> p->packet_num = multifd_send_state->packet_num++;
> multifd_send_state->pages = p->pages;
> p->pages = pages;
> - transferred = ((uint64_t) pages->num) * qemu_target_page_size()
> - + p->packet_len;
> + transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
> qemu_file_update_transfer(f, transferred);
> ram_counters.multifd_bytes += transferred;
> ram_counters.transferred += transferred;
> @@ -939,6 +935,7 @@ int multifd_save_setup(Error **errp)
> /* We need one extra place for the packet header */
> p->iov = g_new0(struct iovec, page_count + 1);
> p->normal = g_new0(ram_addr_t, page_count);
> + p->page_size = qemu_target_page_size();
>
> if (migrate_use_zero_copy_send()) {
> p->write_flags = QIO_CHANNEL_WRITE_FLAG_ZERO_COPY;
> @@ -1186,6 +1183,7 @@ int multifd_load_setup(Error **errp)
> p->name = g_strdup_printf("multifdrecv_%d", i);
> p->iov = g_new0(struct iovec, page_count);
> p->normal = g_new0(ram_addr_t, page_count);
> + p->page_size = qemu_target_page_size();
> }
>
> for (i = 0; i < thread_count; i++) {
> --
> 2.35.3
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 03/13] multifd: Create page_count fields into both MultiFD{Recv, Send}Params
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
2022-05-31 10:43 ` [PATCH v7 01/13] multifd: Document the locking of MultiFD{Send/Recv}Params Juan Quintela
2022-05-31 10:43 ` [PATCH v7 02/13] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-14 10:19 ` [PATCH v7 03/13] multifd: Create page_count fields into both MultiFD{Recv,Send}Params Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 04/13] migration: Export ram_transferred_ram() Juan Quintela
` (9 subsequent siblings)
12 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
We were recalculating it left and right. We plan to change that
values on next patches.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/multifd.h | 4 ++++
migration/multifd.c | 7 ++++---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index 9e07dd00f4..71f49b4063 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -82,6 +82,8 @@ typedef struct {
uint32_t packet_len;
/* guest page size */
uint32_t page_size;
+ /* number of pages in a full packet */
+ uint32_t page_count;
/* multifd flags for sending ram */
int write_flags;
@@ -147,6 +149,8 @@ typedef struct {
uint32_t packet_len;
/* guest page size */
uint32_t page_size;
+ /* number of pages in a full packet */
+ uint32_t page_count;
/* syncs main thread and channels */
QemuSemaphore sem_sync;
diff --git a/migration/multifd.c b/migration/multifd.c
index 7505aa3412..166246b9b7 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -279,7 +279,6 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
{
MultiFDPacket_t *packet = p->packet;
- uint32_t page_count = MULTIFD_PACKET_SIZE / p->page_size;
RAMBlock *block;
int i;
@@ -306,10 +305,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
* If we received a packet that is 100 times bigger than expected
* just stop migration. It is a magic number.
*/
- if (packet->pages_alloc > page_count) {
+ if (packet->pages_alloc > p->page_count) {
error_setg(errp, "multifd: received packet "
"with size %u and expected a size of %u",
- packet->pages_alloc, page_count) ;
+ packet->pages_alloc, p->page_count) ;
return -1;
}
@@ -936,6 +935,7 @@ int multifd_save_setup(Error **errp)
p->iov = g_new0(struct iovec, page_count + 1);
p->normal = g_new0(ram_addr_t, page_count);
p->page_size = qemu_target_page_size();
+ p->page_count = page_count;
if (migrate_use_zero_copy_send()) {
p->write_flags = QIO_CHANNEL_WRITE_FLAG_ZERO_COPY;
@@ -1183,6 +1183,7 @@ int multifd_load_setup(Error **errp)
p->name = g_strdup_printf("multifdrecv_%d", i);
p->iov = g_new0(struct iovec, page_count);
p->normal = g_new0(ram_addr_t, page_count);
+ p->page_count = page_count;
p->page_size = qemu_target_page_size();
}
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 03/13] multifd: Create page_count fields into both MultiFD{Recv,Send}Params
2022-05-31 10:43 ` [PATCH v7 03/13] multifd: Create page_count " Juan Quintela
@ 2022-07-14 10:19 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-14 10:19 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> We were recalculating it left and right. We plan to change that
> values on next patches.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> migration/multifd.h | 4 ++++
> migration/multifd.c | 7 ++++---
> 2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index 9e07dd00f4..71f49b4063 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -82,6 +82,8 @@ typedef struct {
> uint32_t packet_len;
> /* guest page size */
> uint32_t page_size;
> + /* number of pages in a full packet */
> + uint32_t page_count;
> /* multifd flags for sending ram */
> int write_flags;
>
> @@ -147,6 +149,8 @@ typedef struct {
> uint32_t packet_len;
> /* guest page size */
> uint32_t page_size;
> + /* number of pages in a full packet */
> + uint32_t page_count;
>
> /* syncs main thread and channels */
> QemuSemaphore sem_sync;
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 7505aa3412..166246b9b7 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -279,7 +279,6 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
> static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> {
> MultiFDPacket_t *packet = p->packet;
> - uint32_t page_count = MULTIFD_PACKET_SIZE / p->page_size;
> RAMBlock *block;
> int i;
>
> @@ -306,10 +305,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> * If we received a packet that is 100 times bigger than expected
> * just stop migration. It is a magic number.
> */
> - if (packet->pages_alloc > page_count) {
> + if (packet->pages_alloc > p->page_count) {
> error_setg(errp, "multifd: received packet "
> "with size %u and expected a size of %u",
> - packet->pages_alloc, page_count) ;
> + packet->pages_alloc, p->page_count) ;
> return -1;
> }
>
> @@ -936,6 +935,7 @@ int multifd_save_setup(Error **errp)
> p->iov = g_new0(struct iovec, page_count + 1);
> p->normal = g_new0(ram_addr_t, page_count);
> p->page_size = qemu_target_page_size();
> + p->page_count = page_count;
>
> if (migrate_use_zero_copy_send()) {
> p->write_flags = QIO_CHANNEL_WRITE_FLAG_ZERO_COPY;
> @@ -1183,6 +1183,7 @@ int multifd_load_setup(Error **errp)
> p->name = g_strdup_printf("multifdrecv_%d", i);
> p->iov = g_new0(struct iovec, page_count);
> p->normal = g_new0(ram_addr_t, page_count);
> + p->page_count = page_count;
> p->page_size = qemu_target_page_size();
> }
>
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 04/13] migration: Export ram_transferred_ram()
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (2 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 03/13] multifd: Create page_count " Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-06-15 16:20 ` Dr. David Alan Gilbert
2022-07-14 12:43 ` Claudio Fontana
2022-05-31 10:43 ` [PATCH v7 05/13] multifd: Count the number of bytes sent correctly Juan Quintela
` (8 subsequent siblings)
12 siblings, 2 replies; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/ram.h | 2 ++
migration/ram.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/migration/ram.h b/migration/ram.h
index ded0a3a086..7b641adc55 100644
--- a/migration/ram.h
+++ b/migration/ram.h
@@ -65,6 +65,8 @@ int ram_load_postcopy(QEMUFile *f);
void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
+void ram_transferred_add(uint64_t bytes);
+
int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr);
bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_offset);
void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);
diff --git a/migration/ram.c b/migration/ram.c
index 5f5e37f64d..30b0680942 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -394,7 +394,7 @@ uint64_t ram_bytes_remaining(void)
MigrationStats ram_counters;
-static void ram_transferred_add(uint64_t bytes)
+void ram_transferred_add(uint64_t bytes)
{
if (runstate_is_running()) {
ram_counters.precopy_bytes += bytes;
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 04/13] migration: Export ram_transferred_ram()
2022-05-31 10:43 ` [PATCH v7 04/13] migration: Export ram_transferred_ram() Juan Quintela
@ 2022-06-15 16:20 ` Dr. David Alan Gilbert
2022-07-14 12:43 ` Claudio Fontana
1 sibling, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-06-15 16:20 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> migration/ram.h | 2 ++
> migration/ram.c | 2 +-
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/migration/ram.h b/migration/ram.h
> index ded0a3a086..7b641adc55 100644
> --- a/migration/ram.h
> +++ b/migration/ram.h
> @@ -65,6 +65,8 @@ int ram_load_postcopy(QEMUFile *f);
>
> void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
>
> +void ram_transferred_add(uint64_t bytes);
> +
> int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr);
> bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_offset);
> void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);
> diff --git a/migration/ram.c b/migration/ram.c
> index 5f5e37f64d..30b0680942 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -394,7 +394,7 @@ uint64_t ram_bytes_remaining(void)
>
> MigrationStats ram_counters;
>
> -static void ram_transferred_add(uint64_t bytes)
> +void ram_transferred_add(uint64_t bytes)
> {
> if (runstate_is_running()) {
> ram_counters.precopy_bytes += bytes;
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v7 04/13] migration: Export ram_transferred_ram()
2022-05-31 10:43 ` [PATCH v7 04/13] migration: Export ram_transferred_ram() Juan Quintela
2022-06-15 16:20 ` Dr. David Alan Gilbert
@ 2022-07-14 12:43 ` Claudio Fontana
1 sibling, 0 replies; 30+ messages in thread
From: Claudio Fontana @ 2022-07-14 12:43 UTC (permalink / raw)
To: Juan Quintela, qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Eduardo Habkost, Peter Xu, Leonardo Bras
It doesn't seem like the commit subject and the content match.
Is it ram_transferred_ram() or ram_transferred_add() ?
C
On 5/31/22 12:43, Juan Quintela wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/ram.h | 2 ++
> migration/ram.c | 2 +-
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/migration/ram.h b/migration/ram.h
> index ded0a3a086..7b641adc55 100644
> --- a/migration/ram.h
> +++ b/migration/ram.h
> @@ -65,6 +65,8 @@ int ram_load_postcopy(QEMUFile *f);
>
> void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
>
> +void ram_transferred_add(uint64_t bytes);
> +
> int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr);
> bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_offset);
> void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);
> diff --git a/migration/ram.c b/migration/ram.c
> index 5f5e37f64d..30b0680942 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -394,7 +394,7 @@ uint64_t ram_bytes_remaining(void)
>
> MigrationStats ram_counters;
>
> -static void ram_transferred_add(uint64_t bytes)
> +void ram_transferred_add(uint64_t bytes)
> {
> if (runstate_is_running()) {
> ram_counters.precopy_bytes += bytes;
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 05/13] multifd: Count the number of bytes sent correctly
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (3 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 04/13] migration: Export ram_transferred_ram() Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-06-08 8:50 ` Zhang, Chen
2022-07-14 12:33 ` Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 06/13] migration: Make ram_save_target_page() a pointer Juan Quintela
` (7 subsequent siblings)
12 siblings, 2 replies; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
Current code asumes that all pages are whole. That is not true for
example for compression already. Fix it for creating a new field
->sent_bytes that includes it.
All ram_counters are used only from the migration thread, so we have
two options:
- put a mutex and fill everything when we sent it (not only
ram_counters, also qemu_file->xfer_bytes).
- Create a local variable that implements how much has been sent
through each channel. And when we push another packet, we "add" the
previous stats.
I choose two due to less changes overall. On the previous code we
increase transferred and then we sent. Current code goes the other
way around. It sents the data, and after the fact, it updates the
counters. Notice that each channel can have a maximum of half a
megabyte of data without counting, so it is not very important.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/multifd.h | 2 ++
migration/multifd.c | 14 ++++++--------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index 71f49b4063..8a45dda58c 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -102,6 +102,8 @@ typedef struct {
uint32_t flags;
/* global number of generated multifd packets */
uint64_t packet_num;
+ /* How many bytes have we sent on the last packet */
+ uint64_t sent_bytes;
/* thread has work to do */
int pending_job;
/* array of pages to sent.
diff --git a/migration/multifd.c b/migration/multifd.c
index 166246b9b7..eef47c274f 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -394,7 +394,6 @@ static int multifd_send_pages(QEMUFile *f)
static int next_channel;
MultiFDSendParams *p = NULL; /* make happy gcc */
MultiFDPages_t *pages = multifd_send_state->pages;
- uint64_t transferred;
if (qatomic_read(&multifd_send_state->exiting)) {
return -1;
@@ -429,10 +428,10 @@ static int multifd_send_pages(QEMUFile *f)
p->packet_num = multifd_send_state->packet_num++;
multifd_send_state->pages = p->pages;
p->pages = pages;
- transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
- qemu_file_update_transfer(f, transferred);
- ram_counters.multifd_bytes += transferred;
- ram_counters.transferred += transferred;
+ ram_transferred_add(p->sent_bytes);
+ ram_counters.multifd_bytes += p->sent_bytes;
+ qemu_file_update_transfer(f, p->sent_bytes);
+ p->sent_bytes = 0;
qemu_mutex_unlock(&p->mutex);
qemu_sem_post(&p->sem);
@@ -605,9 +604,6 @@ int multifd_send_sync_main(QEMUFile *f)
p->packet_num = multifd_send_state->packet_num++;
p->flags |= MULTIFD_FLAG_SYNC;
p->pending_job++;
- qemu_file_update_transfer(f, p->packet_len);
- ram_counters.multifd_bytes += p->packet_len;
- ram_counters.transferred += p->packet_len;
qemu_mutex_unlock(&p->mutex);
qemu_sem_post(&p->sem);
@@ -712,6 +708,8 @@ static void *multifd_send_thread(void *opaque)
}
qemu_mutex_lock(&p->mutex);
+ p->sent_bytes += p->packet_len;;
+ p->sent_bytes += p->next_packet_size;
p->pending_job--;
qemu_mutex_unlock(&p->mutex);
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* RE: [PATCH v7 05/13] multifd: Count the number of bytes sent correctly
2022-05-31 10:43 ` [PATCH v7 05/13] multifd: Count the number of bytes sent correctly Juan Quintela
@ 2022-06-08 8:50 ` Zhang, Chen
2022-07-14 12:33 ` Dr. David Alan Gilbert
1 sibling, 0 replies; 30+ messages in thread
From: Zhang, Chen @ 2022-06-08 8:50 UTC (permalink / raw)
To: Juan Quintela, qemu-devel@nongnu.org
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Eduardo Habkost, Peter Xu, Leonardo Bras
> -----Original Message-----
> From: Qemu-devel <qemu-devel-
> bounces+chen.zhang=intel.com@nongnu.org> On Behalf Of Juan Quintela
> Sent: Tuesday, May 31, 2022 6:43 PM
> To: qemu-devel@nongnu.org
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>; Philippe Mathieu-
> Daudé <f4bug@amsat.org>; Yanan Wang <wangyanan55@huawei.com>; Dr.
> David Alan Gilbert <dgilbert@redhat.com>; Juan Quintela
> <quintela@redhat.com>; Eduardo Habkost <eduardo@habkost.net>; Peter
> Xu <peterx@redhat.com>; Leonardo Bras <leobras@redhat.com>
> Subject: [PATCH v7 05/13] multifd: Count the number of bytes sent correctly
>
> Current code asumes that all pages are whole. That is not true for example
> for compression already. Fix it for creating a new field
> ->sent_bytes that includes it.
>
> All ram_counters are used only from the migration thread, so we have two
> options:
> - put a mutex and fill everything when we sent it (not only ram_counters,
> also qemu_file->xfer_bytes).
> - Create a local variable that implements how much has been sent through
> each channel. And when we push another packet, we "add" the previous
> stats.
>
> I choose two due to less changes overall. On the previous code we increase
> transferred and then we sent. Current code goes the other way around. It
> sents the data, and after the fact, it updates the counters. Notice that each
> channel can have a maximum of half a megabyte of data without counting, so
> it is not very important.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/multifd.h | 2 ++
> migration/multifd.c | 14 ++++++--------
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h index
> 71f49b4063..8a45dda58c 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -102,6 +102,8 @@ typedef struct {
> uint32_t flags;
> /* global number of generated multifd packets */
> uint64_t packet_num;
> + /* How many bytes have we sent on the last packet */
> + uint64_t sent_bytes;
> /* thread has work to do */
> int pending_job;
> /* array of pages to sent.
> diff --git a/migration/multifd.c b/migration/multifd.c index
> 166246b9b7..eef47c274f 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -394,7 +394,6 @@ static int multifd_send_pages(QEMUFile *f)
> static int next_channel;
> MultiFDSendParams *p = NULL; /* make happy gcc */
> MultiFDPages_t *pages = multifd_send_state->pages;
> - uint64_t transferred;
>
> if (qatomic_read(&multifd_send_state->exiting)) {
> return -1;
> @@ -429,10 +428,10 @@ static int multifd_send_pages(QEMUFile *f)
> p->packet_num = multifd_send_state->packet_num++;
> multifd_send_state->pages = p->pages;
> p->pages = pages;
> - transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
> - qemu_file_update_transfer(f, transferred);
> - ram_counters.multifd_bytes += transferred;
> - ram_counters.transferred += transferred;
> + ram_transferred_add(p->sent_bytes);
> + ram_counters.multifd_bytes += p->sent_bytes;
> + qemu_file_update_transfer(f, p->sent_bytes);
> + p->sent_bytes = 0;
> qemu_mutex_unlock(&p->mutex);
> qemu_sem_post(&p->sem);
>
> @@ -605,9 +604,6 @@ int multifd_send_sync_main(QEMUFile *f)
> p->packet_num = multifd_send_state->packet_num++;
> p->flags |= MULTIFD_FLAG_SYNC;
> p->pending_job++;
> - qemu_file_update_transfer(f, p->packet_len);
> - ram_counters.multifd_bytes += p->packet_len;
> - ram_counters.transferred += p->packet_len;
> qemu_mutex_unlock(&p->mutex);
> qemu_sem_post(&p->sem);
>
> @@ -712,6 +708,8 @@ static void *multifd_send_thread(void *opaque)
> }
>
> qemu_mutex_lock(&p->mutex);
> + p->sent_bytes += p->packet_len;;
Typo here about ";;" ?
Thanks
Chen
> + p->sent_bytes += p->next_packet_size;
> p->pending_job--;
> qemu_mutex_unlock(&p->mutex);
>
> --
> 2.35.3
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v7 05/13] multifd: Count the number of bytes sent correctly
2022-05-31 10:43 ` [PATCH v7 05/13] multifd: Count the number of bytes sent correctly Juan Quintela
2022-06-08 8:50 ` Zhang, Chen
@ 2022-07-14 12:33 ` Dr. David Alan Gilbert
1 sibling, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-14 12:33 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> Current code asumes that all pages are whole. That is not true for
> example for compression already. Fix it for creating a new field
> ->sent_bytes that includes it.
>
> All ram_counters are used only from the migration thread, so we have
> two options:
> - put a mutex and fill everything when we sent it (not only
> ram_counters, also qemu_file->xfer_bytes).
> - Create a local variable that implements how much has been sent
> through each channel. And when we push another packet, we "add" the
> previous stats.
>
> I choose two due to less changes overall. On the previous code we
> increase transferred and then we sent. Current code goes the other
> way around. It sents the data, and after the fact, it updates the
> counters. Notice that each channel can have a maximum of half a
> megabyte of data without counting, so it is not very important.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/multifd.h | 2 ++
> migration/multifd.c | 14 ++++++--------
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index 71f49b4063..8a45dda58c 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -102,6 +102,8 @@ typedef struct {
> uint32_t flags;
> /* global number of generated multifd packets */
> uint64_t packet_num;
> + /* How many bytes have we sent on the last packet */
> + uint64_t sent_bytes;
> /* thread has work to do */
> int pending_job;
> /* array of pages to sent.
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 166246b9b7..eef47c274f 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -394,7 +394,6 @@ static int multifd_send_pages(QEMUFile *f)
> static int next_channel;
> MultiFDSendParams *p = NULL; /* make happy gcc */
> MultiFDPages_t *pages = multifd_send_state->pages;
> - uint64_t transferred;
>
> if (qatomic_read(&multifd_send_state->exiting)) {
> return -1;
> @@ -429,10 +428,10 @@ static int multifd_send_pages(QEMUFile *f)
> p->packet_num = multifd_send_state->packet_num++;
> multifd_send_state->pages = p->pages;
> p->pages = pages;
> - transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
> - qemu_file_update_transfer(f, transferred);
> - ram_counters.multifd_bytes += transferred;
> - ram_counters.transferred += transferred;
> + ram_transferred_add(p->sent_bytes);
> + ram_counters.multifd_bytes += p->sent_bytes;
> + qemu_file_update_transfer(f, p->sent_bytes);
Note that got renamed in bc698c367d6fac15454ee3ff6bb168e43c151465
but other than that
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> + p->sent_bytes = 0;
> qemu_mutex_unlock(&p->mutex);
> qemu_sem_post(&p->sem);
>
> @@ -605,9 +604,6 @@ int multifd_send_sync_main(QEMUFile *f)
> p->packet_num = multifd_send_state->packet_num++;
> p->flags |= MULTIFD_FLAG_SYNC;
> p->pending_job++;
> - qemu_file_update_transfer(f, p->packet_len);
> - ram_counters.multifd_bytes += p->packet_len;
> - ram_counters.transferred += p->packet_len;
> qemu_mutex_unlock(&p->mutex);
> qemu_sem_post(&p->sem);
>
> @@ -712,6 +708,8 @@ static void *multifd_send_thread(void *opaque)
> }
>
> qemu_mutex_lock(&p->mutex);
> + p->sent_bytes += p->packet_len;;
> + p->sent_bytes += p->next_packet_size;
> p->pending_job--;
> qemu_mutex_unlock(&p->mutex);
>
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 06/13] migration: Make ram_save_target_page() a pointer
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (4 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 05/13] multifd: Count the number of bytes sent correctly Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-05-31 10:43 ` [PATCH v7 07/13] multifd: Make flags field thread local Juan Quintela
` (6 subsequent siblings)
12 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
We are going to create a new function for multifd latest in the series.
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
migration/ram.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 30b0680942..71506b1b20 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -295,6 +295,9 @@ struct RAMSrcPageRequest {
QSIMPLEQ_ENTRY(RAMSrcPageRequest) next_req;
};
+typedef struct RAMState RAMState;
+typedef struct PageSearchStatus PageSearchStatus;
+
/* State of RAM for migration */
struct RAMState {
/* QEMUFile used for this migration */
@@ -349,8 +352,8 @@ struct RAMState {
/* Queue of outstanding page requests from the destination */
QemuMutex src_page_req_mutex;
QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests;
+ int (*ram_save_target_page)(RAMState *rs, PageSearchStatus *pss);
};
-typedef struct RAMState RAMState;
static RAMState *ram_state;
@@ -2132,14 +2135,14 @@ static bool save_compress_page(RAMState *rs, RAMBlock *block, ram_addr_t offset)
}
/**
- * ram_save_target_page: save one target page
+ * ram_save_target_page_legacy: save one target page
*
* Returns the number of pages written
*
* @rs: current RAM state
* @pss: data about the page we want to send
*/
-static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss)
+static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
{
RAMBlock *block = pss->block;
ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS;
@@ -2214,7 +2217,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss)
do {
/* Check the pages is dirty and if it is send it */
if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) {
- tmppages = ram_save_target_page(rs, pss);
+ tmppages = rs->ram_save_target_page(rs, pss);
if (tmppages < 0) {
return tmppages;
}
@@ -2944,6 +2947,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
ram_control_before_iterate(f, RAM_CONTROL_SETUP);
ram_control_after_iterate(f, RAM_CONTROL_SETUP);
+ (*rsp)->ram_save_target_page = ram_save_target_page_legacy;
ret = multifd_send_sync_main(f);
if (ret < 0) {
return ret;
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v7 07/13] multifd: Make flags field thread local
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (5 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 06/13] migration: Make ram_save_target_page() a pointer Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-18 11:59 ` Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 08/13] multifd: Prepare to send a packet without the mutex held Juan Quintela
` (5 subsequent siblings)
12 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
Use of flags with respect to locking was incensistant. For the
sending side:
- it was set to 0 with mutex held on the multifd channel.
- MULTIFD_FLAG_SYNC was set with mutex held on the migration thread.
- Everything else was done without the mutex held on the multifd channel.
On the reception side, it is not used on the migration thread, only on
the multifd channels threads.
So we move it to the multifd channels thread only variables, and we
introduce a new bool sync_needed on the send side to pass that information.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/multifd.h | 10 ++++++----
migration/multifd.c | 23 +++++++++++++----------
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index 8a45dda58c..af8ce8921d 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -98,12 +98,12 @@ typedef struct {
bool running;
/* should this thread finish */
bool quit;
- /* multifd flags for each packet */
- uint32_t flags;
/* global number of generated multifd packets */
uint64_t packet_num;
/* How many bytes have we sent on the last packet */
uint64_t sent_bytes;
+ /* Do we need to do an iteration sync */
+ bool sync_needed;
/* thread has work to do */
int pending_job;
/* array of pages to sent.
@@ -117,6 +117,8 @@ typedef struct {
/* pointer to the packet */
MultiFDPacket_t *packet;
+ /* multifd flags for each packet */
+ uint32_t flags;
/* size of the next packet that contains pages */
uint32_t next_packet_size;
/* packets sent through this channel */
@@ -163,8 +165,6 @@ typedef struct {
bool running;
/* should this thread finish */
bool quit;
- /* multifd flags for each packet */
- uint32_t flags;
/* global number of generated multifd packets */
uint64_t packet_num;
@@ -172,6 +172,8 @@ typedef struct {
/* pointer to the packet */
MultiFDPacket_t *packet;
+ /* multifd flags for each packet */
+ uint32_t flags;
/* size of the next packet that contains pages */
uint32_t next_packet_size;
/* packets sent through this channel */
diff --git a/migration/multifd.c b/migration/multifd.c
index eef47c274f..69b9d7cf98 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -602,7 +602,7 @@ int multifd_send_sync_main(QEMUFile *f)
}
p->packet_num = multifd_send_state->packet_num++;
- p->flags |= MULTIFD_FLAG_SYNC;
+ p->sync_needed = true;
p->pending_job++;
qemu_mutex_unlock(&p->mutex);
qemu_sem_post(&p->sem);
@@ -656,7 +656,11 @@ static void *multifd_send_thread(void *opaque)
if (p->pending_job) {
uint64_t packet_num = p->packet_num;
- uint32_t flags = p->flags;
+ p->flags = 0;
+ if (p->sync_needed) {
+ p->flags |= MULTIFD_FLAG_SYNC;
+ p->sync_needed = false;
+ }
p->normal_num = 0;
if (use_zero_copy_send) {
@@ -678,14 +682,13 @@ static void *multifd_send_thread(void *opaque)
}
}
multifd_send_fill_packet(p);
- p->flags = 0;
p->num_packets++;
p->total_normal_pages += p->normal_num;
p->pages->num = 0;
p->pages->block = NULL;
qemu_mutex_unlock(&p->mutex);
- trace_multifd_send(p->id, packet_num, p->normal_num, flags,
+ trace_multifd_send(p->id, packet_num, p->normal_num, p->flags,
p->next_packet_size);
if (use_zero_copy_send) {
@@ -713,7 +716,7 @@ static void *multifd_send_thread(void *opaque)
p->pending_job--;
qemu_mutex_unlock(&p->mutex);
- if (flags & MULTIFD_FLAG_SYNC) {
+ if (p->flags & MULTIFD_FLAG_SYNC) {
qemu_sem_post(&p->sem_sync);
}
qemu_sem_post(&multifd_send_state->channels_ready);
@@ -1090,7 +1093,7 @@ static void *multifd_recv_thread(void *opaque)
rcu_register_thread();
while (true) {
- uint32_t flags;
+ bool sync_needed = false;
if (p->quit) {
break;
@@ -1112,11 +1115,11 @@ static void *multifd_recv_thread(void *opaque)
break;
}
- flags = p->flags;
+ trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags,
+ p->next_packet_size);
+ sync_needed = p->flags & MULTIFD_FLAG_SYNC;
/* recv methods don't know how to handle the SYNC flag */
p->flags &= ~MULTIFD_FLAG_SYNC;
- trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags,
- p->next_packet_size);
p->num_packets++;
p->total_normal_pages += p->normal_num;
qemu_mutex_unlock(&p->mutex);
@@ -1128,7 +1131,7 @@ static void *multifd_recv_thread(void *opaque)
}
}
- if (flags & MULTIFD_FLAG_SYNC) {
+ if (sync_needed) {
qemu_sem_post(&multifd_recv_state->sem_sync);
qemu_sem_wait(&p->sem_sync);
}
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 07/13] multifd: Make flags field thread local
2022-05-31 10:43 ` [PATCH v7 07/13] multifd: Make flags field thread local Juan Quintela
@ 2022-07-18 11:59 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-18 11:59 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> Use of flags with respect to locking was incensistant. For the
> sending side:
> - it was set to 0 with mutex held on the multifd channel.
> - MULTIFD_FLAG_SYNC was set with mutex held on the migration thread.
> - Everything else was done without the mutex held on the multifd channel.
>
> On the reception side, it is not used on the migration thread, only on
> the multifd channels threads.
>
> So we move it to the multifd channels thread only variables, and we
> introduce a new bool sync_needed on the send side to pass that information.
Does this need rework after Leo's recent changes?
Dave
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/multifd.h | 10 ++++++----
> migration/multifd.c | 23 +++++++++++++----------
> 2 files changed, 19 insertions(+), 14 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index 8a45dda58c..af8ce8921d 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -98,12 +98,12 @@ typedef struct {
> bool running;
> /* should this thread finish */
> bool quit;
> - /* multifd flags for each packet */
> - uint32_t flags;
> /* global number of generated multifd packets */
> uint64_t packet_num;
> /* How many bytes have we sent on the last packet */
> uint64_t sent_bytes;
> + /* Do we need to do an iteration sync */
> + bool sync_needed;
> /* thread has work to do */
> int pending_job;
> /* array of pages to sent.
> @@ -117,6 +117,8 @@ typedef struct {
>
> /* pointer to the packet */
> MultiFDPacket_t *packet;
> + /* multifd flags for each packet */
> + uint32_t flags;
> /* size of the next packet that contains pages */
> uint32_t next_packet_size;
> /* packets sent through this channel */
> @@ -163,8 +165,6 @@ typedef struct {
> bool running;
> /* should this thread finish */
> bool quit;
> - /* multifd flags for each packet */
> - uint32_t flags;
> /* global number of generated multifd packets */
> uint64_t packet_num;
>
> @@ -172,6 +172,8 @@ typedef struct {
>
> /* pointer to the packet */
> MultiFDPacket_t *packet;
> + /* multifd flags for each packet */
> + uint32_t flags;
> /* size of the next packet that contains pages */
> uint32_t next_packet_size;
> /* packets sent through this channel */
> diff --git a/migration/multifd.c b/migration/multifd.c
> index eef47c274f..69b9d7cf98 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -602,7 +602,7 @@ int multifd_send_sync_main(QEMUFile *f)
> }
>
> p->packet_num = multifd_send_state->packet_num++;
> - p->flags |= MULTIFD_FLAG_SYNC;
> + p->sync_needed = true;
> p->pending_job++;
> qemu_mutex_unlock(&p->mutex);
> qemu_sem_post(&p->sem);
> @@ -656,7 +656,11 @@ static void *multifd_send_thread(void *opaque)
>
> if (p->pending_job) {
> uint64_t packet_num = p->packet_num;
> - uint32_t flags = p->flags;
> + p->flags = 0;
> + if (p->sync_needed) {
> + p->flags |= MULTIFD_FLAG_SYNC;
> + p->sync_needed = false;
> + }
> p->normal_num = 0;
>
> if (use_zero_copy_send) {
> @@ -678,14 +682,13 @@ static void *multifd_send_thread(void *opaque)
> }
> }
> multifd_send_fill_packet(p);
> - p->flags = 0;
> p->num_packets++;
> p->total_normal_pages += p->normal_num;
> p->pages->num = 0;
> p->pages->block = NULL;
> qemu_mutex_unlock(&p->mutex);
>
> - trace_multifd_send(p->id, packet_num, p->normal_num, flags,
> + trace_multifd_send(p->id, packet_num, p->normal_num, p->flags,
> p->next_packet_size);
>
> if (use_zero_copy_send) {
> @@ -713,7 +716,7 @@ static void *multifd_send_thread(void *opaque)
> p->pending_job--;
> qemu_mutex_unlock(&p->mutex);
>
> - if (flags & MULTIFD_FLAG_SYNC) {
> + if (p->flags & MULTIFD_FLAG_SYNC) {
> qemu_sem_post(&p->sem_sync);
> }
> qemu_sem_post(&multifd_send_state->channels_ready);
> @@ -1090,7 +1093,7 @@ static void *multifd_recv_thread(void *opaque)
> rcu_register_thread();
>
> while (true) {
> - uint32_t flags;
> + bool sync_needed = false;
>
> if (p->quit) {
> break;
> @@ -1112,11 +1115,11 @@ static void *multifd_recv_thread(void *opaque)
> break;
> }
>
> - flags = p->flags;
> + trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags,
> + p->next_packet_size);
> + sync_needed = p->flags & MULTIFD_FLAG_SYNC;
> /* recv methods don't know how to handle the SYNC flag */
> p->flags &= ~MULTIFD_FLAG_SYNC;
> - trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags,
> - p->next_packet_size);
> p->num_packets++;
> p->total_normal_pages += p->normal_num;
> qemu_mutex_unlock(&p->mutex);
> @@ -1128,7 +1131,7 @@ static void *multifd_recv_thread(void *opaque)
> }
> }
>
> - if (flags & MULTIFD_FLAG_SYNC) {
> + if (sync_needed) {
> qemu_sem_post(&multifd_recv_state->sem_sync);
> qemu_sem_wait(&p->sem_sync);
> }
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 08/13] multifd: Prepare to send a packet without the mutex held
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (6 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 07/13] multifd: Make flags field thread local Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-18 12:30 ` Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 09/13] multifd: Add property to enable/disable zero_page Juan Quintela
` (4 subsequent siblings)
12 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
We do the send_prepare() and the fill of the head packet without the
mutex held. It will help a lot for compression and later in the
series for zero pages.
Notice that we can use p->pages without holding p->mutex because
p->pending_job == 1.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/multifd.h | 2 ++
migration/multifd.c | 11 ++++++-----
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index af8ce8921d..d48597a1ea 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -109,7 +109,9 @@ typedef struct {
/* array of pages to sent.
* The owner of 'pages' depends of 'pending_job' value:
* pending_job == 0 -> migration_thread can use it.
+ * No need for mutex lock.
* pending_job != 0 -> multifd_channel can use it.
+ * No need for mutex lock.
*/
MultiFDPages_t *pages;
diff --git a/migration/multifd.c b/migration/multifd.c
index 69b9d7cf98..056599cbaf 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -661,6 +661,8 @@ static void *multifd_send_thread(void *opaque)
p->flags |= MULTIFD_FLAG_SYNC;
p->sync_needed = false;
}
+ qemu_mutex_unlock(&p->mutex);
+
p->normal_num = 0;
if (use_zero_copy_send) {
@@ -682,11 +684,6 @@ static void *multifd_send_thread(void *opaque)
}
}
multifd_send_fill_packet(p);
- p->num_packets++;
- p->total_normal_pages += p->normal_num;
- p->pages->num = 0;
- p->pages->block = NULL;
- qemu_mutex_unlock(&p->mutex);
trace_multifd_send(p->id, packet_num, p->normal_num, p->flags,
p->next_packet_size);
@@ -711,6 +708,10 @@ static void *multifd_send_thread(void *opaque)
}
qemu_mutex_lock(&p->mutex);
+ p->num_packets++;
+ p->total_normal_pages += p->normal_num;
+ p->pages->num = 0;
+ p->pages->block = NULL;
p->sent_bytes += p->packet_len;;
p->sent_bytes += p->next_packet_size;
p->pending_job--;
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 08/13] multifd: Prepare to send a packet without the mutex held
2022-05-31 10:43 ` [PATCH v7 08/13] multifd: Prepare to send a packet without the mutex held Juan Quintela
@ 2022-07-18 12:30 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-18 12:30 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> We do the send_prepare() and the fill of the head packet without the
> mutex held. It will help a lot for compression and later in the
> series for zero pages.
>
> Notice that we can use p->pages without holding p->mutex because
> p->pending_job == 1.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
> migration/multifd.h | 2 ++
> migration/multifd.c | 11 ++++++-----
> 2 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index af8ce8921d..d48597a1ea 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -109,7 +109,9 @@ typedef struct {
> /* array of pages to sent.
> * The owner of 'pages' depends of 'pending_job' value:
> * pending_job == 0 -> migration_thread can use it.
> + * No need for mutex lock.
> * pending_job != 0 -> multifd_channel can use it.
> + * No need for mutex lock.
> */
> MultiFDPages_t *pages;
>
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 69b9d7cf98..056599cbaf 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -661,6 +661,8 @@ static void *multifd_send_thread(void *opaque)
> p->flags |= MULTIFD_FLAG_SYNC;
> p->sync_needed = false;
> }
> + qemu_mutex_unlock(&p->mutex);
> +
> p->normal_num = 0;
>
> if (use_zero_copy_send) {
> @@ -682,11 +684,6 @@ static void *multifd_send_thread(void *opaque)
Looking at my source tree, without the rest of your series, I see an
unlock just before this pair of }'s; doesn't that need to go?
Dave
> }
> }
> multifd_send_fill_packet(p);
> - p->num_packets++;
> - p->total_normal_pages += p->normal_num;
> - p->pages->num = 0;
> - p->pages->block = NULL;
> - qemu_mutex_unlock(&p->mutex);
>
> trace_multifd_send(p->id, packet_num, p->normal_num, p->flags,
> p->next_packet_size);
> @@ -711,6 +708,10 @@ static void *multifd_send_thread(void *opaque)
> }
>
> qemu_mutex_lock(&p->mutex);
> + p->num_packets++;
> + p->total_normal_pages += p->normal_num;
> + p->pages->num = 0;
> + p->pages->block = NULL;
> p->sent_bytes += p->packet_len;;
> p->sent_bytes += p->next_packet_size;
> p->pending_job--;
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 09/13] multifd: Add property to enable/disable zero_page
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (7 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 08/13] multifd: Prepare to send a packet without the mutex held Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-05-31 10:43 ` [PATCH v7 10/13] migration: Export ram_release_page() Juan Quintela
` (3 subsequent siblings)
12 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
migration/migration.h | 3 +++
hw/core/machine.c | 1 +
migration/migration.c | 11 +++++++++++
3 files changed, 15 insertions(+)
diff --git a/migration/migration.h b/migration/migration.h
index 485d58b95f..1017c1bf4a 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -332,6 +332,8 @@ struct MigrationState {
* This save hostname when out-going migration starts
*/
char *hostname;
+ /* Use multifd channel to send zero pages */
+ bool multifd_zero_pages;
};
void migrate_set_state(int *state, int old_state, int new_state);
@@ -374,6 +376,7 @@ int migrate_multifd_channels(void);
MultiFDCompression migrate_multifd_compression(void);
int migrate_multifd_zlib_level(void);
int migrate_multifd_zstd_level(void);
+bool migrate_use_multifd_zero_page(void);
#ifdef CONFIG_LINUX
bool migrate_use_zero_copy_send(void);
diff --git a/hw/core/machine.c b/hw/core/machine.c
index bb0dc8f6a9..a5b5f87329 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -43,6 +43,7 @@
GlobalProperty hw_compat_7_0[] = {
{ "arm-gicv3-common", "force-8-bit-prio", "on" },
+ { "migration", "multifd-zero-pages", "false" },
};
const size_t hw_compat_7_0_len = G_N_ELEMENTS(hw_compat_7_0);
diff --git a/migration/migration.c b/migration/migration.c
index 31739b2af9..224abe2555 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2540,6 +2540,15 @@ bool migrate_use_multifd(void)
return s->enabled_capabilities[MIGRATION_CAPABILITY_MULTIFD];
}
+bool migrate_use_multifd_zero_page(void)
+{
+ MigrationState *s;
+
+ s = migrate_get_current();
+
+ return s->multifd_zero_pages;
+}
+
bool migrate_pause_before_switchover(void)
{
MigrationState *s;
@@ -4207,6 +4216,8 @@ static Property migration_properties[] = {
clear_bitmap_shift, CLEAR_BITMAP_SHIFT_DEFAULT),
/* Migration parameters */
+ DEFINE_PROP_BOOL("multifd-zero-pages", MigrationState,
+ multifd_zero_pages, true),
DEFINE_PROP_UINT8("x-compress-level", MigrationState,
parameters.compress_level,
DEFAULT_MIGRATE_COMPRESS_LEVEL),
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v7 10/13] migration: Export ram_release_page()
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (8 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 09/13] multifd: Add property to enable/disable zero_page Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-13 17:57 ` Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 11/13] multifd: Support for zero pages transmission Juan Quintela
` (2 subsequent siblings)
12 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/ram.h | 1 +
migration/ram.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/migration/ram.h b/migration/ram.h
index 7b641adc55..aee08de2a5 100644
--- a/migration/ram.h
+++ b/migration/ram.h
@@ -66,6 +66,7 @@ int ram_load_postcopy(QEMUFile *f);
void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
void ram_transferred_add(uint64_t bytes);
+void ram_release_page(const char *rbname, uint64_t offset);
int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr);
bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_offset);
diff --git a/migration/ram.c b/migration/ram.c
index 71506b1b20..3b2af07341 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1182,7 +1182,7 @@ static void migration_bitmap_sync_precopy(RAMState *rs)
}
}
-static void ram_release_page(const char *rbname, uint64_t offset)
+void ram_release_page(const char *rbname, uint64_t offset)
{
if (!migrate_release_ram() || !migration_in_postcopy()) {
return;
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 10/13] migration: Export ram_release_page()
2022-05-31 10:43 ` [PATCH v7 10/13] migration: Export ram_release_page() Juan Quintela
@ 2022-07-13 17:57 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-13 17:57 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> migration/ram.h | 1 +
> migration/ram.c | 2 +-
> 2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/migration/ram.h b/migration/ram.h
> index 7b641adc55..aee08de2a5 100644
> --- a/migration/ram.h
> +++ b/migration/ram.h
> @@ -66,6 +66,7 @@ int ram_load_postcopy(QEMUFile *f);
> void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
>
> void ram_transferred_add(uint64_t bytes);
> +void ram_release_page(const char *rbname, uint64_t offset);
>
> int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr);
> bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_offset);
> diff --git a/migration/ram.c b/migration/ram.c
> index 71506b1b20..3b2af07341 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -1182,7 +1182,7 @@ static void migration_bitmap_sync_precopy(RAMState *rs)
> }
> }
>
> -static void ram_release_page(const char *rbname, uint64_t offset)
> +void ram_release_page(const char *rbname, uint64_t offset)
> {
> if (!migrate_release_ram() || !migration_in_postcopy()) {
> return;
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 11/13] multifd: Support for zero pages transmission
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (9 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 10/13] migration: Export ram_release_page() Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-18 17:03 ` Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 12/13] multifd: Zero " Juan Quintela
2022-05-31 10:43 ` [PATCH v7 13/13] migration: Use multifd before we check for the zero page Juan Quintela
12 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
This patch adds counters and similar. Logic will be added on the
following patch.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
Added counters for duplicated/non duplicated pages.
Removed reviewed by from David.
Add total_zero_pages
---
migration/multifd.h | 17 ++++++++++++++++-
migration/multifd.c | 36 +++++++++++++++++++++++++++++-------
migration/ram.c | 2 --
migration/trace-events | 8 ++++----
4 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index d48597a1ea..c36d7ff876 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -47,7 +47,10 @@ typedef struct {
/* size of the next packet that contains pages */
uint32_t next_packet_size;
uint64_t packet_num;
- uint64_t unused[4]; /* Reserved for future use */
+ /* zero pages */
+ uint32_t zero_pages;
+ uint32_t unused32[1]; /* Reserved for future use */
+ uint64_t unused64[3]; /* Reserved for future use */
char ramblock[256];
uint64_t offset[];
} __attribute__((packed)) MultiFDPacket_t;
@@ -127,6 +130,8 @@ typedef struct {
uint64_t num_packets;
/* non zero pages sent through this channel */
uint64_t total_normal_pages;
+ /* zero pages sent through this channel */
+ uint64_t total_zero_pages;
/* buffers to send */
struct iovec *iov;
/* number of iovs used */
@@ -135,6 +140,10 @@ typedef struct {
ram_addr_t *normal;
/* num of non zero pages */
uint32_t normal_num;
+ /* Pages that are zero */
+ ram_addr_t *zero;
+ /* num of zero pages */
+ uint32_t zero_num;
/* used for compression methods */
void *data;
} MultiFDSendParams;
@@ -184,12 +193,18 @@ typedef struct {
uint8_t *host;
/* non zero pages recv through this channel */
uint64_t total_normal_pages;
+ /* zero pages recv through this channel */
+ uint64_t total_zero_pages;
/* buffers to recv */
struct iovec *iov;
/* Pages that are not zero */
ram_addr_t *normal;
/* num of non zero pages */
uint32_t normal_num;
+ /* Pages that are zero */
+ ram_addr_t *zero;
+ /* num of zero pages */
+ uint32_t zero_num;
/* used for de-compression methods */
void *data;
} MultiFDRecvParams;
diff --git a/migration/multifd.c b/migration/multifd.c
index 056599cbaf..0f7c27c08e 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -263,6 +263,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
packet->normal_pages = cpu_to_be32(p->normal_num);
packet->next_packet_size = cpu_to_be32(p->next_packet_size);
packet->packet_num = cpu_to_be64(p->packet_num);
+ packet->zero_pages = cpu_to_be32(p->zero_num);
if (p->pages->block) {
strncpy(packet->ramblock, p->pages->block->idstr, 256);
@@ -323,7 +324,15 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
p->next_packet_size = be32_to_cpu(packet->next_packet_size);
p->packet_num = be64_to_cpu(packet->packet_num);
- if (p->normal_num == 0) {
+ p->zero_num = be32_to_cpu(packet->zero_pages);
+ if (p->zero_num > packet->pages_alloc - p->normal_num) {
+ error_setg(errp, "multifd: received packet "
+ "with %u zero pages and expected maximum pages are %u",
+ p->zero_num, packet->pages_alloc - p->normal_num) ;
+ return -1;
+ }
+
+ if (p->normal_num == 0 && p->zero_num == 0) {
return 0;
}
@@ -432,6 +441,8 @@ static int multifd_send_pages(QEMUFile *f)
ram_counters.multifd_bytes += p->sent_bytes;
qemu_file_update_transfer(f, p->sent_bytes);
p->sent_bytes = 0;
+ ram_counters.normal += p->normal_num;
+ ram_counters.duplicate += p->zero_num;
qemu_mutex_unlock(&p->mutex);
qemu_sem_post(&p->sem);
@@ -545,6 +556,8 @@ void multifd_save_cleanup(void)
p->iov = NULL;
g_free(p->normal);
p->normal = NULL;
+ g_free(p->zero);
+ p->zero = NULL;
multifd_send_state->ops->send_cleanup(p, &local_err);
if (local_err) {
migrate_set_error(migrate_get_current(), local_err);
@@ -664,6 +677,7 @@ static void *multifd_send_thread(void *opaque)
qemu_mutex_unlock(&p->mutex);
p->normal_num = 0;
+ p->zero_num = 0;
if (use_zero_copy_send) {
p->iovs_num = 0;
@@ -685,8 +699,8 @@ static void *multifd_send_thread(void *opaque)
}
multifd_send_fill_packet(p);
- trace_multifd_send(p->id, packet_num, p->normal_num, p->flags,
- p->next_packet_size);
+ trace_multifd_send(p->id, packet_num, p->normal_num, p->zero_num,
+ p->flags, p->next_packet_size);
if (use_zero_copy_send) {
/* Send header first, without zerocopy */
@@ -710,6 +724,7 @@ static void *multifd_send_thread(void *opaque)
qemu_mutex_lock(&p->mutex);
p->num_packets++;
p->total_normal_pages += p->normal_num;
+ p->total_zero_pages += p->zero_num;
p->pages->num = 0;
p->pages->block = NULL;
p->sent_bytes += p->packet_len;;
@@ -751,7 +766,8 @@ out:
qemu_mutex_unlock(&p->mutex);
rcu_unregister_thread();
- trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_pages);
+ trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_pages,
+ p->total_zero_pages);
return NULL;
}
@@ -938,6 +954,7 @@ int multifd_save_setup(Error **errp)
p->normal = g_new0(ram_addr_t, page_count);
p->page_size = qemu_target_page_size();
p->page_count = page_count;
+ p->zero = g_new0(ram_addr_t, page_count);
if (migrate_use_zero_copy_send()) {
p->write_flags = QIO_CHANNEL_WRITE_FLAG_ZERO_COPY;
@@ -1046,6 +1063,8 @@ int multifd_load_cleanup(Error **errp)
p->iov = NULL;
g_free(p->normal);
p->normal = NULL;
+ g_free(p->zero);
+ p->zero = NULL;
multifd_recv_state->ops->recv_cleanup(p);
}
qemu_sem_destroy(&multifd_recv_state->sem_sync);
@@ -1116,13 +1135,14 @@ static void *multifd_recv_thread(void *opaque)
break;
}
- trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags,
- p->next_packet_size);
+ trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->zero_num,
+ p->flags, p->next_packet_size);
sync_needed = p->flags & MULTIFD_FLAG_SYNC;
/* recv methods don't know how to handle the SYNC flag */
p->flags &= ~MULTIFD_FLAG_SYNC;
p->num_packets++;
p->total_normal_pages += p->normal_num;
+ p->total_normal_pages += p->zero_num;
qemu_mutex_unlock(&p->mutex);
if (p->normal_num) {
@@ -1147,7 +1167,8 @@ static void *multifd_recv_thread(void *opaque)
qemu_mutex_unlock(&p->mutex);
rcu_unregister_thread();
- trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_pages);
+ trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_pages,
+ p->total_zero_pages);
return NULL;
}
@@ -1187,6 +1208,7 @@ int multifd_load_setup(Error **errp)
p->normal = g_new0(ram_addr_t, page_count);
p->page_count = page_count;
p->page_size = qemu_target_page_size();
+ p->zero = g_new0(ram_addr_t, page_count);
}
for (i = 0; i < thread_count; i++) {
diff --git a/migration/ram.c b/migration/ram.c
index 3b2af07341..7ceef7976b 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1356,8 +1356,6 @@ static int ram_save_multifd_page(RAMState *rs, RAMBlock *block,
if (multifd_queue_page(rs->f, block, offset) < 0) {
return -1;
}
- ram_counters.normal++;
-
return 1;
}
diff --git a/migration/trace-events b/migration/trace-events
index 1aec580e92..d70e89dbb9 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -114,21 +114,21 @@ unqueue_page(char *block, uint64_t offset, bool dirty) "ramblock '%s' offset 0x%
# multifd.c
multifd_new_send_channel_async(uint8_t id) "channel %u"
-multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " pages %u flags 0x%x next packet size %u"
+multifd_recv(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t zero, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet size %u"
multifd_recv_new_channel(uint8_t id) "channel %u"
multifd_recv_sync_main(long packet_num) "packet num %ld"
multifd_recv_sync_main_signal(uint8_t id) "channel %u"
multifd_recv_sync_main_wait(uint8_t id) "channel %u"
multifd_recv_terminate_threads(bool error) "error %d"
-multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "channel %u packets %" PRIu64 " pages %" PRIu64
+multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64 " zero pages %" PRIu64
multifd_recv_thread_start(uint8_t id) "%u"
-multifd_send(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u flags 0x%x next packet size %u"
+multifd_send(uint8_t id, uint64_t packet_num, uint32_t normalpages, uint32_t zero_pages, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet size %u"
multifd_send_error(uint8_t id) "channel %u"
multifd_send_sync_main(long packet_num) "packet num %ld"
multifd_send_sync_main_signal(uint8_t id) "channel %u"
multifd_send_sync_main_wait(uint8_t id) "channel %u"
multifd_send_terminate_threads(bool error) "error %d"
-multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64
+multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64 " zero pages %" PRIu64
multifd_send_thread_start(uint8_t id) "%u"
multifd_tls_outgoing_handshake_start(void *ioc, void *tioc, const char *hostname) "ioc=%p tioc=%p hostname=%s"
multifd_tls_outgoing_handshake_error(void *ioc, const char *err) "ioc=%p err=%s"
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 11/13] multifd: Support for zero pages transmission
2022-05-31 10:43 ` [PATCH v7 11/13] multifd: Support for zero pages transmission Juan Quintela
@ 2022-07-18 17:03 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-18 17:03 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> This patch adds counters and similar. Logic will be added on the
> following patch.
Yeh, I think so; the duplicate becing the counter for zero pages still
throws me.
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
>
> ---
>
> Added counters for duplicated/non duplicated pages.
> Removed reviewed by from David.
> Add total_zero_pages
> ---
> migration/multifd.h | 17 ++++++++++++++++-
> migration/multifd.c | 36 +++++++++++++++++++++++++++++-------
> migration/ram.c | 2 --
> migration/trace-events | 8 ++++----
> 4 files changed, 49 insertions(+), 14 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index d48597a1ea..c36d7ff876 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -47,7 +47,10 @@ typedef struct {
> /* size of the next packet that contains pages */
> uint32_t next_packet_size;
> uint64_t packet_num;
> - uint64_t unused[4]; /* Reserved for future use */
> + /* zero pages */
> + uint32_t zero_pages;
> + uint32_t unused32[1]; /* Reserved for future use */
> + uint64_t unused64[3]; /* Reserved for future use */
> char ramblock[256];
> uint64_t offset[];
> } __attribute__((packed)) MultiFDPacket_t;
> @@ -127,6 +130,8 @@ typedef struct {
> uint64_t num_packets;
> /* non zero pages sent through this channel */
> uint64_t total_normal_pages;
> + /* zero pages sent through this channel */
> + uint64_t total_zero_pages;
> /* buffers to send */
> struct iovec *iov;
> /* number of iovs used */
> @@ -135,6 +140,10 @@ typedef struct {
> ram_addr_t *normal;
> /* num of non zero pages */
> uint32_t normal_num;
> + /* Pages that are zero */
> + ram_addr_t *zero;
> + /* num of zero pages */
> + uint32_t zero_num;
> /* used for compression methods */
> void *data;
> } MultiFDSendParams;
> @@ -184,12 +193,18 @@ typedef struct {
> uint8_t *host;
> /* non zero pages recv through this channel */
> uint64_t total_normal_pages;
> + /* zero pages recv through this channel */
> + uint64_t total_zero_pages;
> /* buffers to recv */
> struct iovec *iov;
> /* Pages that are not zero */
> ram_addr_t *normal;
> /* num of non zero pages */
> uint32_t normal_num;
> + /* Pages that are zero */
> + ram_addr_t *zero;
> + /* num of zero pages */
> + uint32_t zero_num;
> /* used for de-compression methods */
> void *data;
> } MultiFDRecvParams;
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 056599cbaf..0f7c27c08e 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -263,6 +263,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
> packet->normal_pages = cpu_to_be32(p->normal_num);
> packet->next_packet_size = cpu_to_be32(p->next_packet_size);
> packet->packet_num = cpu_to_be64(p->packet_num);
> + packet->zero_pages = cpu_to_be32(p->zero_num);
>
> if (p->pages->block) {
> strncpy(packet->ramblock, p->pages->block->idstr, 256);
> @@ -323,7 +324,15 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> p->next_packet_size = be32_to_cpu(packet->next_packet_size);
> p->packet_num = be64_to_cpu(packet->packet_num);
>
> - if (p->normal_num == 0) {
> + p->zero_num = be32_to_cpu(packet->zero_pages);
> + if (p->zero_num > packet->pages_alloc - p->normal_num) {
> + error_setg(errp, "multifd: received packet "
> + "with %u zero pages and expected maximum pages are %u",
> + p->zero_num, packet->pages_alloc - p->normal_num) ;
> + return -1;
> + }
> +
> + if (p->normal_num == 0 && p->zero_num == 0) {
> return 0;
> }
>
> @@ -432,6 +441,8 @@ static int multifd_send_pages(QEMUFile *f)
> ram_counters.multifd_bytes += p->sent_bytes;
> qemu_file_update_transfer(f, p->sent_bytes);
> p->sent_bytes = 0;
> + ram_counters.normal += p->normal_num;
> + ram_counters.duplicate += p->zero_num;
> qemu_mutex_unlock(&p->mutex);
> qemu_sem_post(&p->sem);
>
> @@ -545,6 +556,8 @@ void multifd_save_cleanup(void)
> p->iov = NULL;
> g_free(p->normal);
> p->normal = NULL;
> + g_free(p->zero);
> + p->zero = NULL;
> multifd_send_state->ops->send_cleanup(p, &local_err);
> if (local_err) {
> migrate_set_error(migrate_get_current(), local_err);
> @@ -664,6 +677,7 @@ static void *multifd_send_thread(void *opaque)
> qemu_mutex_unlock(&p->mutex);
>
> p->normal_num = 0;
> + p->zero_num = 0;
>
> if (use_zero_copy_send) {
> p->iovs_num = 0;
> @@ -685,8 +699,8 @@ static void *multifd_send_thread(void *opaque)
> }
> multifd_send_fill_packet(p);
>
> - trace_multifd_send(p->id, packet_num, p->normal_num, p->flags,
> - p->next_packet_size);
> + trace_multifd_send(p->id, packet_num, p->normal_num, p->zero_num,
> + p->flags, p->next_packet_size);
>
> if (use_zero_copy_send) {
> /* Send header first, without zerocopy */
> @@ -710,6 +724,7 @@ static void *multifd_send_thread(void *opaque)
> qemu_mutex_lock(&p->mutex);
> p->num_packets++;
> p->total_normal_pages += p->normal_num;
> + p->total_zero_pages += p->zero_num;
> p->pages->num = 0;
> p->pages->block = NULL;
> p->sent_bytes += p->packet_len;;
> @@ -751,7 +766,8 @@ out:
> qemu_mutex_unlock(&p->mutex);
>
> rcu_unregister_thread();
> - trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_pages);
> + trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_pages,
> + p->total_zero_pages);
>
> return NULL;
> }
> @@ -938,6 +954,7 @@ int multifd_save_setup(Error **errp)
> p->normal = g_new0(ram_addr_t, page_count);
> p->page_size = qemu_target_page_size();
> p->page_count = page_count;
> + p->zero = g_new0(ram_addr_t, page_count);
>
> if (migrate_use_zero_copy_send()) {
> p->write_flags = QIO_CHANNEL_WRITE_FLAG_ZERO_COPY;
> @@ -1046,6 +1063,8 @@ int multifd_load_cleanup(Error **errp)
> p->iov = NULL;
> g_free(p->normal);
> p->normal = NULL;
> + g_free(p->zero);
> + p->zero = NULL;
> multifd_recv_state->ops->recv_cleanup(p);
> }
> qemu_sem_destroy(&multifd_recv_state->sem_sync);
> @@ -1116,13 +1135,14 @@ static void *multifd_recv_thread(void *opaque)
> break;
> }
>
> - trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags,
> - p->next_packet_size);
> + trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->zero_num,
> + p->flags, p->next_packet_size);
> sync_needed = p->flags & MULTIFD_FLAG_SYNC;
> /* recv methods don't know how to handle the SYNC flag */
> p->flags &= ~MULTIFD_FLAG_SYNC;
> p->num_packets++;
> p->total_normal_pages += p->normal_num;
> + p->total_normal_pages += p->zero_num;
> qemu_mutex_unlock(&p->mutex);
>
> if (p->normal_num) {
> @@ -1147,7 +1167,8 @@ static void *multifd_recv_thread(void *opaque)
> qemu_mutex_unlock(&p->mutex);
>
> rcu_unregister_thread();
> - trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_pages);
> + trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_pages,
> + p->total_zero_pages);
>
> return NULL;
> }
> @@ -1187,6 +1208,7 @@ int multifd_load_setup(Error **errp)
> p->normal = g_new0(ram_addr_t, page_count);
> p->page_count = page_count;
> p->page_size = qemu_target_page_size();
> + p->zero = g_new0(ram_addr_t, page_count);
> }
>
> for (i = 0; i < thread_count; i++) {
> diff --git a/migration/ram.c b/migration/ram.c
> index 3b2af07341..7ceef7976b 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -1356,8 +1356,6 @@ static int ram_save_multifd_page(RAMState *rs, RAMBlock *block,
> if (multifd_queue_page(rs->f, block, offset) < 0) {
> return -1;
> }
> - ram_counters.normal++;
> -
> return 1;
> }
>
> diff --git a/migration/trace-events b/migration/trace-events
> index 1aec580e92..d70e89dbb9 100644
> --- a/migration/trace-events
> +++ b/migration/trace-events
> @@ -114,21 +114,21 @@ unqueue_page(char *block, uint64_t offset, bool dirty) "ramblock '%s' offset 0x%
>
> # multifd.c
> multifd_new_send_channel_async(uint8_t id) "channel %u"
> -multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " pages %u flags 0x%x next packet size %u"
> +multifd_recv(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t zero, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet size %u"
> multifd_recv_new_channel(uint8_t id) "channel %u"
> multifd_recv_sync_main(long packet_num) "packet num %ld"
> multifd_recv_sync_main_signal(uint8_t id) "channel %u"
> multifd_recv_sync_main_wait(uint8_t id) "channel %u"
> multifd_recv_terminate_threads(bool error) "error %d"
> -multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "channel %u packets %" PRIu64 " pages %" PRIu64
> +multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64 " zero pages %" PRIu64
> multifd_recv_thread_start(uint8_t id) "%u"
> -multifd_send(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u flags 0x%x next packet size %u"
> +multifd_send(uint8_t id, uint64_t packet_num, uint32_t normalpages, uint32_t zero_pages, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet size %u"
> multifd_send_error(uint8_t id) "channel %u"
> multifd_send_sync_main(long packet_num) "packet num %ld"
> multifd_send_sync_main_signal(uint8_t id) "channel %u"
> multifd_send_sync_main_wait(uint8_t id) "channel %u"
> multifd_send_terminate_threads(bool error) "error %d"
> -multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64
> +multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64 " zero pages %" PRIu64
> multifd_send_thread_start(uint8_t id) "%u"
> multifd_tls_outgoing_handshake_start(void *ioc, void *tioc, const char *hostname) "ioc=%p tioc=%p hostname=%s"
> multifd_tls_outgoing_handshake_error(void *ioc, const char *err) "ioc=%p err=%s"
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 12/13] multifd: Zero pages transmission
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (10 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 11/13] multifd: Support for zero pages transmission Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-18 13:19 ` Dr. David Alan Gilbert
2022-05-31 10:43 ` [PATCH v7 13/13] migration: Use multifd before we check for the zero page Juan Quintela
12 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
This implements the zero page dection and handling.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
Add comment for offset (dave)
Use local variables for offset/block to have shorter lines
---
migration/multifd.h | 5 +++++
migration/multifd.c | 41 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index c36d7ff876..209e3a9756 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -52,6 +52,11 @@ typedef struct {
uint32_t unused32[1]; /* Reserved for future use */
uint64_t unused64[3]; /* Reserved for future use */
char ramblock[256];
+ /*
+ * 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;
diff --git a/migration/multifd.c b/migration/multifd.c
index 0f7c27c08e..fcdd241c5c 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -11,6 +11,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/cutils.h"
#include "qemu/rcu.h"
#include "exec/target_page.h"
#include "sysemu/sysemu.h"
@@ -275,6 +276,12 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
packet->offset[i] = cpu_to_be64(temp);
}
+ for (i = 0; i < p->zero_num; i++) {
+ /* there are architectures where ram_addr_t is 32 bit */
+ uint64_t temp = p->zero[i];
+
+ packet->offset[p->normal_num + i] = cpu_to_be64(temp);
+ }
}
static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
@@ -358,6 +365,18 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
p->normal[i] = offset;
}
+ for (i = 0; i < p->zero_num; i++) {
+ uint64_t offset = be64_to_cpu(packet->offset[p->normal_num + i]);
+
+ if (offset > (block->used_length - p->page_size)) {
+ error_setg(errp, "multifd: offset too long %" PRIu64
+ " (max " RAM_ADDR_FMT ")",
+ offset, block->used_length);
+ return -1;
+ }
+ p->zero[i] = offset;
+ }
+
return 0;
}
@@ -646,6 +665,8 @@ static void *multifd_send_thread(void *opaque)
{
MultiFDSendParams *p = opaque;
Error *local_err = NULL;
+ /* qemu older than 7.0 don't understand zero page on multifd channel */
+ bool use_zero_page = migrate_use_multifd_zero_page();
int ret = 0;
bool use_zero_copy_send = migrate_use_zero_copy_send();
@@ -668,6 +689,7 @@ static void *multifd_send_thread(void *opaque)
qemu_mutex_lock(&p->mutex);
if (p->pending_job) {
+ RAMBlock *rb = p->pages->block;
uint64_t packet_num = p->packet_num;
p->flags = 0;
if (p->sync_needed) {
@@ -686,8 +708,16 @@ static void *multifd_send_thread(void *opaque)
}
for (int i = 0; i < p->pages->num; i++) {
- p->normal[p->normal_num] = p->pages->offset[i];
- p->normal_num++;
+ uint64_t offset = p->pages->offset[i];
+ if (use_zero_page &&
+ buffer_is_zero(rb->host + offset, p->page_size)) {
+ p->zero[p->zero_num] = offset;
+ p->zero_num++;
+ ram_release_page(rb->idstr, offset);
+ } else {
+ p->normal[p->normal_num] = offset;
+ p->normal_num++;
+ }
}
if (p->normal_num) {
@@ -1152,6 +1182,13 @@ static void *multifd_recv_thread(void *opaque)
}
}
+ for (int i = 0; i < p->zero_num; i++) {
+ void *page = p->host + p->zero[i];
+ if (!buffer_is_zero(page, p->page_size)) {
+ memset(page, 0, p->page_size);
+ }
+ }
+
if (sync_needed) {
qemu_sem_post(&multifd_recv_state->sem_sync);
qemu_sem_wait(&p->sem_sync);
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 12/13] multifd: Zero pages transmission
2022-05-31 10:43 ` [PATCH v7 12/13] multifd: Zero " Juan Quintela
@ 2022-07-18 13:19 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-18 13:19 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> This implements the zero page dection and handling.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>
> ---
>
> Add comment for offset (dave)
> Use local variables for offset/block to have shorter lines
> ---
> migration/multifd.h | 5 +++++
> migration/multifd.c | 41 +++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/migration/multifd.h b/migration/multifd.h
> index c36d7ff876..209e3a9756 100644
> --- a/migration/multifd.h
> +++ b/migration/multifd.h
> @@ -52,6 +52,11 @@ typedef struct {
> uint32_t unused32[1]; /* Reserved for future use */
> uint64_t unused64[3]; /* Reserved for future use */
> char ramblock[256];
> + /*
> + * 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;
>
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 0f7c27c08e..fcdd241c5c 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -11,6 +11,7 @@
> */
>
> #include "qemu/osdep.h"
> +#include "qemu/cutils.h"
> #include "qemu/rcu.h"
> #include "exec/target_page.h"
> #include "sysemu/sysemu.h"
> @@ -275,6 +276,12 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
>
> packet->offset[i] = cpu_to_be64(temp);
> }
> + for (i = 0; i < p->zero_num; i++) {
> + /* there are architectures where ram_addr_t is 32 bit */
> + uint64_t temp = p->zero[i];
> +
> + packet->offset[p->normal_num + i] = cpu_to_be64(temp);
> + }
> }
>
> static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> @@ -358,6 +365,18 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
> p->normal[i] = offset;
> }
>
> + for (i = 0; i < p->zero_num; i++) {
> + uint64_t offset = be64_to_cpu(packet->offset[p->normal_num + i]);
> +
> + if (offset > (block->used_length - p->page_size)) {
> + error_setg(errp, "multifd: offset too long %" PRIu64
> + " (max " RAM_ADDR_FMT ")",
> + offset, block->used_length);
> + return -1;
> + }
> + p->zero[i] = offset;
> + }
> +
> return 0;
> }
>
> @@ -646,6 +665,8 @@ static void *multifd_send_thread(void *opaque)
> {
> MultiFDSendParams *p = opaque;
> Error *local_err = NULL;
> + /* qemu older than 7.0 don't understand zero page on multifd channel */
> + bool use_zero_page = migrate_use_multifd_zero_page();
> int ret = 0;
> bool use_zero_copy_send = migrate_use_zero_copy_send();
>
> @@ -668,6 +689,7 @@ static void *multifd_send_thread(void *opaque)
> qemu_mutex_lock(&p->mutex);
>
> if (p->pending_job) {
> + RAMBlock *rb = p->pages->block;
> uint64_t packet_num = p->packet_num;
> p->flags = 0;
> if (p->sync_needed) {
> @@ -686,8 +708,16 @@ static void *multifd_send_thread(void *opaque)
> }
>
> for (int i = 0; i < p->pages->num; i++) {
> - p->normal[p->normal_num] = p->pages->offset[i];
> - p->normal_num++;
> + uint64_t offset = p->pages->offset[i];
> + if (use_zero_page &&
> + buffer_is_zero(rb->host + offset, p->page_size)) {
> + p->zero[p->zero_num] = offset;
> + p->zero_num++;
> + ram_release_page(rb->idstr, offset);
> + } else {
> + p->normal[p->normal_num] = offset;
> + p->normal_num++;
> + }
> }
>
> if (p->normal_num) {
> @@ -1152,6 +1182,13 @@ static void *multifd_recv_thread(void *opaque)
> }
> }
>
> + for (int i = 0; i < p->zero_num; i++) {
> + void *page = p->host + p->zero[i];
> + if (!buffer_is_zero(page, p->page_size)) {
> + memset(page, 0, p->page_size);
> + }
> + }
> +
> if (sync_needed) {
> qemu_sem_post(&multifd_recv_state->sem_sync);
> qemu_sem_wait(&p->sem_sync);
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v7 13/13] migration: Use multifd before we check for the zero page
2022-05-31 10:43 [PATCH v7 00/13] Migration: Transmit and detect zero pages in the multifd threads Juan Quintela
` (11 preceding siblings ...)
2022-05-31 10:43 ` [PATCH v7 12/13] multifd: Zero " Juan Quintela
@ 2022-05-31 10:43 ` Juan Quintela
2022-07-18 13:34 ` Dr. David Alan Gilbert
12 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2022-05-31 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
Dr. David Alan Gilbert, Juan Quintela, Eduardo Habkost, Peter Xu,
Leonardo Bras
So we use multifd to transmit zero pages.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
- Check zero_page property before using new code (Dave)
---
migration/ram.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/migration/ram.c b/migration/ram.c
index 7ceef7976b..f9959262fa 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2181,6 +2181,32 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
return ram_save_page(rs, pss);
}
+/**
+ * ram_save_target_page_multifd: save one target page
+ *
+ * Returns the number of pages written
+ *
+ * @rs: current RAM state
+ * @pss: data about the page we want to send
+ */
+static int ram_save_target_page_multifd(RAMState *rs, PageSearchStatus *pss)
+{
+ RAMBlock *block = pss->block;
+ ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS;
+ int res;
+
+ if (!migration_in_postcopy()) {
+ return ram_save_multifd_page(rs, block, offset);
+ }
+
+ res = save_zero_page(rs, block, offset);
+ if (res > 0) {
+ return res;
+ }
+
+ return ram_save_page(rs, pss);
+}
+
/**
* ram_save_host_page: save a whole host page
*
@@ -2945,7 +2971,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
ram_control_before_iterate(f, RAM_CONTROL_SETUP);
ram_control_after_iterate(f, RAM_CONTROL_SETUP);
- (*rsp)->ram_save_target_page = ram_save_target_page_legacy;
+ if (migrate_use_multifd() && migrate_use_multifd_zero_page()) {
+ (*rsp)->ram_save_target_page = ram_save_target_page_multifd;
+ } else {
+ (*rsp)->ram_save_target_page = ram_save_target_page_legacy;
+ }
+
ret = multifd_send_sync_main(f);
if (ret < 0) {
return ret;
--
2.35.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v7 13/13] migration: Use multifd before we check for the zero page
2022-05-31 10:43 ` [PATCH v7 13/13] migration: Use multifd before we check for the zero page Juan Quintela
@ 2022-07-18 13:34 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 30+ messages in thread
From: Dr. David Alan Gilbert @ 2022-07-18 13:34 UTC (permalink / raw)
To: Juan Quintela
Cc: qemu-devel, Marcel Apfelbaum, Philippe Mathieu-Daudé,
Yanan Wang, Eduardo Habkost, Peter Xu, Leonardo Bras
* Juan Quintela (quintela@redhat.com) wrote:
> So we use multifd to transmit zero pages.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>
> ---
>
> - Check zero_page property before using new code (Dave)
> ---
> migration/ram.c | 33 ++++++++++++++++++++++++++++++++-
> 1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index 7ceef7976b..f9959262fa 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -2181,6 +2181,32 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
> return ram_save_page(rs, pss);
> }
>
> +/**
> + * ram_save_target_page_multifd: save one target page
> + *
> + * Returns the number of pages written
> + *
> + * @rs: current RAM state
> + * @pss: data about the page we want to send
> + */
> +static int ram_save_target_page_multifd(RAMState *rs, PageSearchStatus *pss)
> +{
> + RAMBlock *block = pss->block;
> + ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS;
> + int res;
> +
> + if (!migration_in_postcopy()) {
> + return ram_save_multifd_page(rs, block, offset);
> + }
> +
> + res = save_zero_page(rs, block, offset);
> + if (res > 0) {
> + return res;
> + }
> +
> + return ram_save_page(rs, pss);
> +}
> +
> /**
> * ram_save_host_page: save a whole host page
> *
> @@ -2945,7 +2971,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
> ram_control_before_iterate(f, RAM_CONTROL_SETUP);
> ram_control_after_iterate(f, RAM_CONTROL_SETUP);
>
> - (*rsp)->ram_save_target_page = ram_save_target_page_legacy;
> + if (migrate_use_multifd() && migrate_use_multifd_zero_page()) {
> + (*rsp)->ram_save_target_page = ram_save_target_page_multifd;
> + } else {
> + (*rsp)->ram_save_target_page = ram_save_target_page_legacy;
> + }
> +
> ret = multifd_send_sync_main(f);
> if (ret < 0) {
> return ret;
> --
> 2.35.3
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 30+ messages in thread