Migration: Transmit and detect zero pages in the multifd threads
cover Migration: Transmit and detect zero pages in the multifd threads
Hi
Since Friday version:
- More cleanups on the code
- Remove repeated calls to qemu_target_page_size()
- Establish normal pages and zero pages
- detect zero pages on the multifd threads
- send zero pages through the multifd channels.
- reviews by Richard addressed.
It pases migration-test, so it should be perfect O:+)
ToDo for next version:
- check the version changes
I need that 6.2 is out to check for 7.0. This code don't exist at all due to that reason.
- Send measurements of the differences
Please, review.
[
Friday version that just created a single writev instead of write+writev.
]
Right now, multifd does a write() for the header and a writev() for each group of pages. Simplify it so we send the header as another member of the IOV.
Once there, I got several simplifications:
* is_zero_range() was used only once, just use its body.
* same with is_zero_page().
* Be consintent and use offset insed the ramblock everywhere.
* Now that we have the offsets of the ramblock, we can drop the iov.
* Now that nothing uses iov's except NOCOMP method, move the iovs from pages to methods.
* Now we can use iov's with a single field for zlib/zstd.
* send_write() method is the same in all the implementaitons, so use it directly.
* Now, we can use a single writev() to write everything.
ToDo: Move zero page detection to the multifd thrteads.
With RAM in the Terabytes size, the detection of the zero page takes too much time on the main thread.
Last patch on the series removes the detection of zero pages in the main thread for multifd. In the next series post, I will add how to detect the zero pages and send them on multifd channels.
Please review.
Later, Juan.
Juan Quintela (23):
multifd: Delete useless operation
migration: Never call twice qemu_target_page_size()
multifd: Rename used field to num
multifd: Add missing documention
multifd: The variable is only used inside the loop
multifd: remove used parameter from send_prepare() method
multifd: remove used parameter from send_recv_pages() method
multifd: Fill offset and block for reception
multifd: Make zstd compression method not use iovs
multifd: Make zlib compression method not use iovs
multifd: Move iov from pages to params
multifd: Make zlib use iov's
multifd: Make zstd use iov's
multifd: Remove send_write() method
multifd: Use a single writev on the send side
multifd: Unfold "used" variable by its value
multifd: Use normal pages array on the send side
multifd: Use normal pages array on the recv side
multifd: recv side only needs the RAMBlock host address
multifd: Rename pages_used to normal_pages
multifd: Support for zero pages transmission
multifd: Zero pages transmission
migration: Use multifd before we check for the zero page
migration/multifd.h | 52 +++++++--- migration/migration.c | 7 +- migration/multifd-zlib.c | 71 +++++-------- migration/multifd-zstd.c | 70 +++++-------- migration/multifd.c | 214 +++++++++++++++++++++++---------------- migration/ram.c | 22 ++-- migration/savevm.c | 5 +- migration/trace-events | 4 +- 8 files changed, 231 insertions(+), 214 deletions(-)
Signature · 1 line
2.33.1
PATCH 1/23 multifd: Delete useless operation
We are divining by page_size to multiply again in the only use. Once there, impreve the comments.
--- migration/multifd-zlib.c | 13 ++++--------- migration/multifd-zstd.c | 13 ++++--------- 2 files changed, 8 insertions(+), 18 deletions(-)
migration/multifd-zlib.c +4 -9
@@ -42,7 +42,6 @@ struct zlib_data {*/ static int zlib_send_setup (MultiFDSendParams *p,Error **errp) { -uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size ();struct zlib_data *z =g_malloc0 (sizeof (struct zlib_data ));z_stream *zs = &z->zs;
@@ -54,9 +53,8 @@ static int zlib_send_setup(MultiFDSendParams *p, Error **errp)error_setg (errp,"multifd %d: deflate init failed" , p->id);return -1 ; } -/* We will never have more than page_count pages */ - z->zbuff_len = page_count *qemu_target_page_size (); - z->zbuff_len *=2 ; +/* To be safe, we reserve twice the size of the packet */ + z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {deflateEnd (&z->zs);
@@ -180,7 +178,6 @@ static int zlib_send_write(MultiFDSendParams *p, uint32_t used, Error **errp)*/ static int zlib_recv_setup (MultiFDRecvParams *p,Error **errp) { -uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size ();struct zlib_data *z =g_malloc0 (sizeof (struct zlib_data ));z_stream *zs = &z->zs;
@@ -194,10 +191,8 @@ static int zlib_recv_setup(MultiFDRecvParams *p, Error **errp)error_setg (errp,"multifd %d: inflate init failed" , p->id);return -1 ; } -/* We will never have more than page_count pages */ - z->zbuff_len = page_count *qemu_target_page_size (); -/* We know compression "could" use more space */ - z->zbuff_len *=2 ; +/* To be safe, we reserve twice the size of the packet */ + z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {inflateEnd (zs);
migration/multifd-zstd.c +4 -9
@@ -47,7 +47,6 @@ struct zstd_data {*/ static int zstd_send_setup (MultiFDSendParams *p,Error **errp) { -uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size (); struct zstd_data *z = g_new0(struct zstd_data, 1);int res;
@@ -67,9 +66,8 @@ static int zstd_send_setup(MultiFDSendParams *p, Error **errp) p->id, ZSTD_getErrorName(res));return -1 ; } -/* We will never have more than page_count pages */ - z->zbuff_len = page_count *qemu_target_page_size (); - z->zbuff_len *=2 ; +/* To be safe, we reserve twice the size of the packet */ + z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {ZSTD_freeCStream (z->zcs);
@@ -191,7 +189,6 @@ static int zstd_send_write(MultiFDSendParams *p, uint32_t used, Error **errp)*/ static int zstd_recv_setup (MultiFDRecvParams *p,Error **errp) { -uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size (); struct zstd_data *z = g_new0(struct zstd_data, 1);int ret;
@@ -212,10 +209,8 @@ static int zstd_recv_setup(MultiFDRecvParams *p, Error **errp)return -1 ; } -/* We will never have more than page_count pages */ - z->zbuff_len = page_count *qemu_target_page_size (); -/* We know compression "could" use more space */ - z->zbuff_len *=2 ; +/* To be safe, we reserve twice the size of the packet */ + z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {ZSTD_freeDStream (z->zds);
Signature · 1 line
2.33.1
PATCH 2/23 migration: Never call twice qemu_target_page_size()
In reply to Juan Quintela--- migration/migration.c | 7 ++++--- migration/multifd.c | 7 ++++--- migration/savevm.c | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-)
migration/migration.c +4 -3
@@ -996,6 +996,8 @@ static void populate_time_info(MigrationInfo *info, MigrationState *s)static void populate_ram_info (MigrationInfo *info,MigrationState *s) { +size_t page_size =qemu_target_page_size (); + info->has_ram = true; info->ram =g_malloc0 (sizeof (*info->ram)); info->ram->transferred = ram_counters.transferred;
@@ -1004,12 +1006,11 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s)/* legacy value. It is not used anymore */ info->ram->skipped =0 ; info->ram->normal = ram_counters.normal; - info->ram->normal_bytes = ram_counters.normal * -qemu_target_page_size (); + info->ram->normal_bytes = ram_counters.normal * page_size; info->ram->mbps = s->mbps; info->ram->dirty_sync_count = ram_counters.dirty_sync_count; info->ram->postcopy_requests = ram_counters.postcopy_requests; - info->ram->page_size =qemu_target_page_size (); + info->ram->page_size = page_size; info->ram->multifd_bytes = ram_counters.multifd_bytes; info->ram->pages_per_second = s->pages_per_second;
migration/multifd.c +4 -3
@@ -289,7 +289,8 @@ 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 pages_max =MULTIFD_PACKET_SIZE /qemu_target_page_size (); +size_t page_size =qemu_target_page_size (); +uint32_t pages_max =MULTIFD_PACKET_SIZE / page_size;RAMBlock *block;int i;
@@ -358,14 +359,14 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)for (i =0 ; i < p->pages->used; i++) {uint64_t offset =be64_to_cpu (packet->offset[i]); -if (offset > (block->used_length -qemu_target_page_size ())) { +if (offset > (block->used_length - page_size)) {error_setg (errp,"multifd: offset too long %" PRIu64" (max " RAM_ADDR_FMT ")" , offset, block->used_length);return -1 ; } p->pages->iov[i].iov_base = block->host + offset; - p->pages->iov[i].iov_len =qemu_target_page_size (); + p->pages->iov[i].iov_len = page_size; }return 0 ;
migration/savevm.c +3 -2
@@ -1685,6 +1685,7 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis, {PostcopyState ps =postcopy_state_set (POSTCOPY_INCOMING_ADVISE );uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps; +size_t page_size =qemu_target_page_size ();Error *local_err =NULL ;trace_loadvm_postcopy_handle_advise ();
@@ -1741,13 +1742,13 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis, } remote_tps =qemu_get_be64 (mis->from_src_file); -if (remote_tps !=qemu_target_page_size ()) { +if (remote_tps != page_size) {/* * Again, some differences could be dealt with, but for now keep it * simple. */ error_report ("Postcopy needs matching target page sizes (s=%d d=%zd)" , - (int )remote_tps,qemu_target_page_size ()); + (int )remote_tps, page_size);return -1 ; }
Signature · 1 line
2.33.1
PATCH 3/23 multifd: Rename used field to num
In reply to Juan QuintelaWe will need to split it later in zero_num (number of zero pages) and normal_num (number of normal pages). This name is better.
--- migration/multifd.h | 2 +- migration/multifd.c | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-)
migration/multifd.h +1 -1
@@ -55,7 +55,7 @@ typedef struct { typedef struct { /* number of used pages */ - uint32_t used; + uint32_t num; /* number of allocated pages */ uint32_t allocated; /* global number of generated multifd packets */
migration/multifd.c +19 -19
@@ -252,7 +252,7 @@ static MultiFDPages_t *multifd_pages_init(size_t size)static void multifd_pages_clear (MultiFDPages_t *pages) { - pages->used =0 ; + pages->num =0 ; pages->allocated =0 ; pages->packet_num =0 ; pages->block =NULL ;
@@ -270,7 +270,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p) packet->flags =cpu_to_be32 (p->flags); packet->pages_alloc =cpu_to_be32 (p->pages->allocated); - packet->pages_used =cpu_to_be32 (p->pages->used); + packet->pages_used =cpu_to_be32 (p->pages->num); packet->next_packet_size =cpu_to_be32 (p->next_packet_size); packet->packet_num =cpu_to_be64 (p->packet_num);
@@ -278,7 +278,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)strncpy (packet->ramblock, p->pages->block->idstr,256 ); } -for (i =0 ; i < p->pages->used; i++) { +for (i =0 ; i < p->pages->num; i++) {/* there are architectures where ram_addr_t is 32 bit */ uint64_t temp = p->pages->offset[i];
@@ -332,18 +332,18 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) p->pages =multifd_pages_init (packet->pages_alloc); } - p->pages->used =be32_to_cpu (packet->pages_used); -if (p->pages->used > packet->pages_alloc) { + p->pages->num =be32_to_cpu (packet->pages_used); +if (p->pages->num > packet->pages_alloc) {error_setg (errp,"multifd: received packet " "with %d pages and expected maximum pages are %d" , - p->pages->used, packet->pages_alloc) ; + p->pages->num, packet->pages_alloc) ;return -1 ; } p->next_packet_size =be32_to_cpu (packet->next_packet_size); p->packet_num =be64_to_cpu (packet->packet_num); -if (p->pages->used ==0 ) { +if (p->pages->num ==0 ) {return 0 ; }
@@ -356,7 +356,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)return -1 ; } -for (i =0 ; i < p->pages->used; i++) { +for (i =0 ; i < p->pages->num; i++) {uint64_t offset =be64_to_cpu (packet->offset[i]);if (offset > (block->used_length - page_size)) {
@@ -443,13 +443,13 @@ static int multifd_send_pages(QEMUFile *f) }qemu_mutex_unlock (&p->mutex); } -assert (!p->pages->used); +assert (!p->pages->num);assert (!p->pages->block); p->packet_num = multifd_send_state->packet_num++; multifd_send_state->pages = p->pages; p->pages = pages; - transferred = ((uint64_t ) pages->used) *qemu_target_page_size () + transferred = ((uint64_t ) pages->num) *qemu_target_page_size () + p->packet_len;qemu_file_update_transfer (f, transferred); ram_counters.multifd_bytes += transferred;
@@ -469,12 +469,12 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset) }if (pages->block == block) { - pages->offset[pages->used] = offset; - pages->iov[pages->used].iov_base = block->host + offset; - pages->iov[pages->used].iov_len =qemu_target_page_size (); - pages->used++; + pages->offset[pages->num] = offset; + pages->iov[pages->num].iov_base = block->host + offset; + pages->iov[pages->num].iov_len =qemu_target_page_size (); + pages->num++; -if (pages->used < pages->allocated) { +if (pages->num < pages->allocated) {return 1 ; } }
@@ -586,7 +586,7 @@ void multifd_send_sync_main(QEMUFile *f)if (!migrate_use_multifd ()) {return ; } -if (multifd_send_state->pages->used) { +if (multifd_send_state->pages->num) {if (multifd_send_pages (f) <0 ) {error_report ("%s: multifd_send_pages fail" , __func__);return ;
@@ -649,7 +649,7 @@ static void *multifd_send_thread(void *opaque)qemu_mutex_lock (&p->mutex);if (p->pending_job) { -uint32_t used = p->pages->used; +uint32_t used = p->pages->num;uint64_t packet_num = p->packet_num; flags = p->flags;
@@ -665,7 +665,7 @@ static void *multifd_send_thread(void *opaque) p->flags =0 ; p->num_packets++; p->num_pages += used; - p->pages->used =0 ; + p->pages->num =0 ; p->pages->block =NULL ;qemu_mutex_unlock (&p->mutex);
@@ -1091,7 +1091,7 @@ static void *multifd_recv_thread(void *opaque)break ; } - used = p->pages->used; + used = p->pages->num; flags = p->flags;/* recv methods don't know how to handle the SYNC flag */ p->flags &= ~MULTIFD_FLAG_SYNC ;
Signature · 1 line
2.33.1
PATCH 4/23 multifd: Add missing documention
In reply to Juan Quintela--- migration/multifd-zlib.c | 2 ++ migration/multifd-zstd.c | 2 ++ migration/multifd.c | 1 + 3 files changed, 5 insertions(+)
migration/multifd-zlib.c +2 -0
@@ -72,6 +72,7 @@ static int zlib_send_setup(MultiFDSendParams *p, Error **errp)* Close the channel and return memory. * * @p: Params for the channel that we are using +* @errp: pointer to an error */ static void zlib_send_cleanup (MultiFDSendParams *p,Error **errp) {
@@ -94,6 +95,7 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp)* * @p: Params for the channel that we are using * @used: number of pages used +* @errp: pointer to an error */ static int zlib_send_prepare (MultiFDSendParams *p,uint32_t used,Error **errp) {
migration/multifd-zstd.c +2 -0
@@ -84,6 +84,7 @@ static int zstd_send_setup(MultiFDSendParams *p, Error **errp)* Close the channel and return memory. * * @p: Params for the channel that we are using +* @errp: pointer to an error */ static void zstd_send_cleanup (MultiFDSendParams *p,Error **errp) {
@@ -107,6 +108,7 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp)* * @p: Params for the channel that we are using * @used: number of pages used +* @errp: pointer to an error */ static int zstd_send_prepare (MultiFDSendParams *p,uint32_t used,Error **errp) {
migration/multifd.c +1 -0
@@ -66,6 +66,7 @@ static int nocomp_send_setup(MultiFDSendParams *p, Error **errp)* For no compression this function does nothing. * * @p: Params for the channel that we are using +* @errp: pointer to an error */ static void nocomp_send_cleanup (MultiFDSendParams *p,Error **errp) {
Signature · 1 line
2.33.1
PATCH 5/23 multifd: The variable is only used inside the loop
In reply to Juan Quintela--- migration/multifd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
migration/multifd.c +1 -2
@@ -629,7 +629,6 @@ static void *multifd_send_thread(void *opaque)MultiFDSendParams *p = opaque;Error *local_err =NULL ;int ret =0 ; -uint32_t flags =0 ;trace_multifd_send_thread_start (p->id);rcu_register_thread ();
@@ -652,7 +651,7 @@ static void *multifd_send_thread(void *opaque)if (p->pending_job) {uint32_t used = p->pages->num;uint64_t packet_num = p->packet_num; - flags = p->flags; +uint32_t flags = p->flags;if (used) { ret = multifd_send_state->ops->send_prepare(p, used,
Signature · 1 line
2.33.1
PATCH 6/23 multifd: remove used parameter from send_prepare() method
In reply to Juan QuintelaIt is already there as p->pages->num.
--- migration/multifd.h | 2 +- migration/multifd-zlib.c | 7 +++---- migration/multifd-zstd.c | 7 +++---- migration/multifd.c | 9 +++------ 4 files changed, 10 insertions(+), 15 deletions(-)
migration/multifd.h +1 -1
@@ -159,7 +159,7 @@ typedef struct {/* Cleanup for sending side */ void (*send_cleanup)(MultiFDSendParams *p,Error **errp);/* Prepare the send packet */ -int (*send_prepare)(MultiFDSendParams *p,uint32_t used,Error **errp); +int (*send_prepare)(MultiFDSendParams *p,Error **errp);/* Write the send packet */ int (*send_write)(MultiFDSendParams *p,uint32_t used,Error **errp);/* Setup for receiving side */
migration/multifd-zlib.c +3 -4
@@ -94,10 +94,9 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp)* Returns 0 for success or -1 for error * * @p: Params for the channel that we are using -* @used: number of pages used * @errp: pointer to an error */ -static int zlib_send_prepare (MultiFDSendParams *p,uint32_t used,Error **errp) +static int zlib_send_prepare (MultiFDSendParams *p,Error **errp) {struct iovec *iov = p->pages->iov;struct zlib_data *z = p->data;
@@ -106,11 +105,11 @@ static int zlib_send_prepare(MultiFDSendParams *p, uint32_t used, Error **errp)int ret;uint32_t i; -for (i =0 ; i < used; i++) { +for (i =0 ; i < p->pages->num; i++) {uint32_t available = z->zbuff_len - out_size;int flush =Z_NO_FLUSH ; -if (i == used -1 ) { +if (i == p->pages->num -1 ) { flush =Z_SYNC_FLUSH ; }
migration/multifd-zstd.c +3 -4
@@ -107,10 +107,9 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp)* Returns 0 for success or -1 for error * * @p: Params for the channel that we are using -* @used: number of pages used * @errp: pointer to an error */ -static int zstd_send_prepare (MultiFDSendParams *p,uint32_t used,Error **errp) +static int zstd_send_prepare (MultiFDSendParams *p,Error **errp) {struct iovec *iov = p->pages->iov;struct zstd_data *z = p->data;
@@ -121,10 +120,10 @@ static int zstd_send_prepare(MultiFDSendParams *p, uint32_t used, Error **errp) z->out.size = z->zbuff_len; z->out.pos =0 ; -for (i =0 ; i < used; i++) { +for (i =0 ; i < p->pages->num; i++) {ZSTD_EndDirective flush = ZSTD_e_continue; -if (i == used -1 ) { +if (i == p->pages->num -1 ) { flush = ZSTD_e_flush; } z->in.src = iov[i].iov_base;
migration/multifd.c +3 -6
@@ -82,13 +82,11 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp)* Returns 0 for success or -1 for error * * @p: Params for the channel that we are using -* @used: number of pages used * @errp: pointer to an error */ -static int nocomp_send_prepare (MultiFDSendParams *p,uint32_t used, -Error **errp) +static int nocomp_send_prepare (MultiFDSendParams *p,Error **errp) { - p->next_packet_size = used *qemu_target_page_size (); + p->next_packet_size = p->pages->num *qemu_target_page_size (); p->flags |=MULTIFD_FLAG_NOCOMP ;return 0 ; }
@@ -654,8 +652,7 @@ static void *multifd_send_thread(void *opaque)uint32_t flags = p->flags;if (used) { - ret = multifd_send_state->ops->send_prepare (p, used, - &local_err); + ret = multifd_send_state->ops->send_prepare (p, &local_err);if (ret !=0 ) {qemu_mutex_unlock (&p->mutex);break ;
Signature · 1 line
2.33.1
PATCH 7/23 multifd: remove used parameter from send_recv_pages() method
In reply to Juan QuintelaIt is already there as p->pages->num.
--- migration/multifd.h | 2 +- migration/multifd-zlib.c | 9 ++++----- migration/multifd-zstd.c | 7 +++---- migration/multifd.c | 7 +++---- 4 files changed, 11 insertions(+), 14 deletions(-)
migration/multifd.h +1 -1
@@ -167,7 +167,7 @@ typedef struct {/* Cleanup for receiving side */ void (*recv_cleanup)(MultiFDRecvParams *p);/* Read all pages */ -int (*recv_pages)(MultiFDRecvParams *p,uint32_t used,Error **errp); +int (*recv_pages)(MultiFDRecvParams *p,Error **errp); } MultiFDMethods;void multifd_register_ops (int method,MultiFDMethods *ops);
migration/multifd-zlib.c +4 -5
@@ -230,17 +230,16 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p)* Returns 0 for success or -1 for error * * @p: Params for the channel that we are using -* @used: number of pages used * @errp: pointer to an error */ -static int zlib_recv_pages (MultiFDRecvParams *p,uint32_t used,Error **errp) +static int zlib_recv_pages (MultiFDRecvParams *p,Error **errp) {struct zlib_data *z = p->data;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 = used *qemu_target_page_size (); +uint32_t expected_size = p->pages->num *qemu_target_page_size ();uint32_t flags = p->flags &MULTIFD_FLAG_COMPRESSION_MASK ;int ret;int i;
@@ -259,12 +258,12 @@ static int zlib_recv_pages(MultiFDRecvParams *p, uint32_t used, Error **errp) zs->avail_in = in_size; zs->next_in = z->zbuff; -for (i =0 ; i < used; i++) { +for (i =0 ; i < p->pages->num; i++) {struct iovec *iov = &p->pages->iov[i];int flush =Z_NO_FLUSH ;unsigned long start = zs->total_out; -if (i == used -1 ) { +if (i == p->pages->num -1 ) { flush =Z_SYNC_FLUSH ; }
migration/multifd-zstd.c +3 -4
@@ -250,14 +250,13 @@ static void zstd_recv_cleanup(MultiFDRecvParams *p)* Returns 0 for success or -1 for error * * @p: Params for the channel that we are using -* @used: number of pages used * @errp: pointer to an error */ -static int zstd_recv_pages (MultiFDRecvParams *p,uint32_t used,Error **errp) +static int zstd_recv_pages (MultiFDRecvParams *p,Error **errp) {uint32_t in_size = p->next_packet_size;uint32_t out_size =0 ; -uint32_t expected_size = used *qemu_target_page_size (); +uint32_t expected_size = p->pages->num *qemu_target_page_size ();uint32_t flags = p->flags &MULTIFD_FLAG_COMPRESSION_MASK ;struct zstd_data *z = p->data;int ret;
@@ -278,7 +277,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, uint32_t used, Error **errp) z->in.size = in_size; z->in.pos =0 ; -for (i =0 ; i < used; i++) { +for (i =0 ; i < p->pages->num; i++) {struct iovec *iov = &p->pages->iov[i]; z->out.dst = iov->iov_base;
migration/multifd.c +3 -4
@@ -141,10 +141,9 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p)* Returns 0 for success or -1 for error * * @p: Params for the channel that we are using -* @used: number of pages used * @errp: pointer to an error */ -static int nocomp_recv_pages (MultiFDRecvParams *p,uint32_t used,Error **errp) +static int nocomp_recv_pages (MultiFDRecvParams *p,Error **errp) {uint32_t flags = p->flags &MULTIFD_FLAG_COMPRESSION_MASK ;
@@ -153,7 +152,7 @@ static int nocomp_recv_pages(MultiFDRecvParams *p, uint32_t used, Error **errp) p->id, flags, MULTIFD_FLAG_NOCOMP);return -1 ; } -return qio_channel_readv_all (p->c, p->pages->iov, used, errp); +return qio_channel_readv_all (p->c, p->pages->iov, p->pages->num, errp); }static MultiFDMethods multifd_nocomp_ops = {
@@ -1099,7 +1098,7 @@ static void *multifd_recv_thread(void *opaque)qemu_mutex_unlock (&p->mutex);if (used) { - ret = multifd_recv_state->ops->recv_pages (p, used, &local_err); + ret = multifd_recv_state->ops->recv_pages (p, &local_err);if (ret !=0 ) {break ; }
Signature · 1 line
2.33.1
PATCH 8/23 multifd: Fill offset and block for reception
In reply to Juan QuintelaWe were using the iov directly, but we will need this info on the following patch.
--- migration/multifd.c | 2 ++ 1 file changed, 2 insertions(+)
migration/multifd.c +2 -0
@@ -354,6 +354,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)return -1 ; } + p->pages->block = block;for (i =0 ; i < p->pages->num; i++) {uint64_t offset =be64_to_cpu (packet->offset[i]);
@@ -363,6 +364,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) offset, block->used_length);return -1 ; } + p->pages->offset[i] = offset; p->pages->iov[i].iov_base = block->host + offset; p->pages->iov[i].iov_len = page_size; }
Signature · 1 line
2.33.1
PATCH 9/23 multifd: Make zstd compression method not use iovs
In reply to Juan Quintela--- migration/multifd-zstd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
migration/multifd-zstd.c +10 -10
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include <zstd.h> #include "qemu/rcu.h" +#include "exec/ramblock.h" #include "exec/target_page.h" #include "qapi/error.h" #include "migration.h"
@@ -111,8 +112,8 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp)*/ static int zstd_send_prepare (MultiFDSendParams *p,Error **errp) { -struct iovec *iov = p->pages->iov;struct zstd_data *z = p->data; +size_t page_size =qemu_target_page_size ();int ret;uint32_t i;
@@ -126,8 +127,8 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)if (i == p->pages->num -1 ) { flush = ZSTD_e_flush; } - z->in.src = iov[i].iov_base; - z->in.size = iov[i].iov_len; + z->in.src = p->pages->block->host + p->pages->offset[i]; + z->in.size = page_size; z->in.pos =0 ;/*
@@ -256,7 +257,8 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp) {uint32_t in_size = p->next_packet_size;uint32_t out_size =0 ; -uint32_t expected_size = p->pages->num *qemu_target_page_size (); +size_t page_size =qemu_target_page_size (); +uint32_t expected_size = p->pages->num * page_size;uint32_t flags = p->flags &MULTIFD_FLAG_COMPRESSION_MASK ;struct zstd_data *z = p->data;int ret;
@@ -278,10 +280,8 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp) z->in.pos =0 ;for (i =0 ; i < p->pages->num; i++) { -struct iovec *iov = &p->pages->iov[i]; - - z->out.dst = iov->iov_base; - z->out.size = iov->iov_len; + z->out.dst = p->pages->block->host + p->pages->offset[i]; + z->out.size = page_size; z->out.pos =0 ;/*
@@ -295,8 +295,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 < iov->iov_len)); -if (ret >0 && (z->out.pos < iov->iov_len)) { + && (z->out.pos < page_size)); +if (ret >0 && (z->out.pos < page_size)) {error_setg (errp,"multifd %d: decompressStream buffer too small" , p->id);return -1 ;
Signature · 1 line
2.33.1
PATCH 10/23 multifd: Make zlib compression method not use iovs
In reply to Juan Quintela--- migration/multifd-zlib.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
migration/multifd-zlib.c +9 -8
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include <zlib.h> #include "qemu/rcu.h" +#include "exec/ramblock.h" #include "exec/target_page.h" #include "qapi/error.h" #include "migration.h"
@@ -98,8 +99,8 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp)*/ static int zlib_send_prepare (MultiFDSendParams *p,Error **errp) { -struct iovec *iov = p->pages->iov;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;
@@ -113,8 +114,8 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) flush =Z_SYNC_FLUSH ; } - zs->avail_in = iov[i].iov_len; - zs->next_in = iov[i].iov_base; + zs->avail_in = page_size; + zs->next_in = p->pages->block->host + p->pages->offset[i]; zs->avail_out = available; zs->next_out = z->zbuff + out_size;
@@ -235,6 +236,7 @@ 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 */
@@ -259,7 +261,6 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp) zs->next_in = z->zbuff;for (i =0 ; i < p->pages->num; i++) { -struct iovec *iov = &p->pages->iov[i];int flush =Z_NO_FLUSH ;unsigned long start = zs->total_out;
@@ -267,8 +268,8 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp) flush =Z_SYNC_FLUSH ; } - zs->avail_out = iov->iov_len; - zs->next_out = iov->iov_base; + zs->avail_out = page_size; + zs->next_out = p->pages->block->host + p->pages->offset[i];/* * Welcome to inflate semantics
@@ -281,8 +282,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) < iov->iov_len); -if (ret ==Z_OK && (zs->total_out - start) < iov->iov_len) { + && (zs->total_out - start) < page_size); +if (ret ==Z_OK && (zs->total_out - start) < page_size) {error_setg (errp,"multifd %d: inflate generated too few output" , p->id);return -1 ;
Signature · 1 line
2.33.1
PATCH 11/23 multifd: Move iov from pages to params
In reply to Juan QuintelaThis will allow us to reduce the number of system calls on the next patch.
--- migration/multifd.h | 8 ++++++-- migration/multifd.c | 34 ++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-)
migration/multifd.h +6 -2
@@ -62,8 +62,6 @@ typedef struct {uint64_t packet_num;/* offset of each page */ ram_addr_t *offset; -/* pointer to each page */ -struct iovec *iov;RAMBlock *block; } MultiFDPages_t;
@@ -110,6 +108,10 @@ typedef struct {uint64_t num_pages;/* syncs main thread and channels */ QemuSemaphore sem_sync; +/* buffers to send */ +struct iovec *iov; +/* number of iovs used */ +uint32_t iovs_num;/* used for compression methods */ void *data; } MultiFDSendParams;
@@ -149,6 +151,8 @@ typedef struct {uint64_t num_pages;/* syncs main thread and channels */ QemuSemaphore sem_sync; +/* buffers to recv */ +struct iovec *iov;/* used for de-compression methods */ void *data; } MultiFDRecvParams;
migration/multifd.c +24 -10
@@ -86,7 +86,16 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp)*/ static int nocomp_send_prepare (MultiFDSendParams *p,Error **errp) { - p->next_packet_size = p->pages->num *qemu_target_page_size (); +MultiFDPages_t *pages = p->pages; +size_t page_size =qemu_target_page_size (); + +for (int i =0 ; i < p->pages->num; i++) { + p->iov[p->iovs_num].iov_base = pages->block->host + pages->offset[i]; + p->iov[p->iovs_num].iov_len = page_size; + p->iovs_num++; + } + + p->next_packet_size = p->pages->num * page_size; p->flags |=MULTIFD_FLAG_NOCOMP ;return 0 ; }
@@ -104,7 +113,7 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp)*/ static int nocomp_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) { -return qio_channel_writev_all (p->c, p->pages->iov, used, errp); +return qio_channel_writev_all (p->c, p->iov, p->iovs_num, errp); }/**
@@ -146,13 +155,18 @@ 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 %d: flags received %x flags expected %x" , p->id, flags,MULTIFD_FLAG_NOCOMP );return -1 ; } -return qio_channel_readv_all (p->c, p->pages->iov, p->pages->num, errp); +for (int i =0 ; i < p->pages->num; i++) { + p->iov[i].iov_base = p->pages->block->host + p->pages->offset[i]; + p->iov[i].iov_len = page_size; + } +return qio_channel_readv_all (p->c, p->iov, p->pages->num, errp); }static MultiFDMethods multifd_nocomp_ops = {
@@ -242,7 +256,6 @@ static MultiFDPages_t *multifd_pages_init(size_t size)MultiFDPages_t *pages =g_new0 (MultiFDPages_t,1 ); pages->allocated = size; - pages->iov = g_new0(struct iovec, size); pages->offset =g_new0 (ram_addr_t, size);return pages;
@@ -254,8 +267,6 @@ static void multifd_pages_clear(MultiFDPages_t *pages) pages->allocated =0 ; pages->packet_num =0 ; pages->block =NULL ; -g_free (pages->iov); - pages->iov =NULL ;g_free (pages->offset); pages->offset =NULL ;g_free (pages);
@@ -365,8 +376,6 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)return -1 ; } p->pages->offset[i] = offset; - p->pages->iov[i].iov_base = block->host + offset; - p->pages->iov[i].iov_len = page_size; }return 0 ;
@@ -470,8 +479,6 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset)if (pages->block == block) { pages->offset[pages->num] = offset; - pages->iov[pages->num].iov_base = block->host + offset; - pages->iov[pages->num].iov_len =qemu_target_page_size (); pages->num++;if (pages->num < pages->allocated) {
@@ -564,6 +571,8 @@ void multifd_save_cleanup(void) p->packet_len =0 ;g_free (p->packet); p->packet =NULL ; +g_free (p->iov); + p->iov =NULL ; multifd_send_state->ops->send_cleanup (p, &local_err);if (local_err) {migrate_set_error (migrate_get_current (), local_err);
@@ -651,6 +660,7 @@ static void *multifd_send_thread(void *opaque)uint32_t used = p->pages->num;uint64_t packet_num = p->packet_num;uint32_t flags = p->flags; + p->iovs_num =0 ;if (used) { ret = multifd_send_state->ops->send_prepare (p, &local_err);
@@ -919,6 +929,7 @@ int multifd_save_setup(Error **errp) p->packet->version =cpu_to_be32 (MULTIFD_VERSION ); p->name =g_strdup_printf ("multifdsend_%d" , i); p->tls_hostname =g_strdup (s->hostname); + p->iov = g_new0(struct iovec, page_count);socket_send_channel_create (multifd_new_send_channel_async, p); }
@@ -1018,6 +1029,8 @@ int multifd_load_cleanup(Error **errp) p->packet_len =0 ;g_free (p->packet); p->packet =NULL ; +g_free (p->iov); + p->iov =NULL ; multifd_recv_state->ops->recv_cleanup (p); }qemu_sem_destroy (&multifd_recv_state->sem_sync);
@@ -1158,6 +1171,7 @@ int multifd_load_setup(Error **errp) +sizeof (uint64_t ) * page_count; p->packet =g_malloc0 (p->packet_len); p->name =g_strdup_printf ("multifdrecv_%d" , i); + p->iov = g_new0(struct iovec, page_count); }for (i =0 ; i < thread_count; i++) {
Signature · 1 line
2.33.1
PATCH 12/23 multifd: Make zlib use iov's
In reply to Juan Quintela--- migration/multifd-zlib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
migration/multifd-zlib.c +4 -4
@@ -143,6 +143,9 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) } out_size += available - zs->avail_out; } + p->iov[p->iovs_num].iov_base = z->zbuff; + p->iov[p->iovs_num].iov_len = out_size; + p->iovs_num++; p->next_packet_size = out_size; p->flags |=MULTIFD_FLAG_ZLIB ;
@@ -162,10 +165,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)*/ static int zlib_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) { -struct zlib_data *z = p->data; - -return qio_channel_write_all (p->c, (void *)z->zbuff, p->next_packet_size, - errp); +return qio_channel_writev_all (p->c, p->iov, p->iovs_num, errp); }/**
Signature · 1 line
2.33.1
PATCH 13/23 multifd: Make zstd use iov's
In reply to Juan Quintela--- migration/multifd-zstd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
migration/multifd-zstd.c +4 -4
@@ -154,6 +154,9 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)return -1 ; } } + p->iov[p->iovs_num].iov_base = z->zbuff; + p->iov[p->iovs_num].iov_len = z->out.pos; + p->iovs_num++; p->next_packet_size = z->out.pos; p->flags |=MULTIFD_FLAG_ZSTD ;
@@ -173,10 +176,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)*/ static int zstd_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) { -struct zstd_data *z = p->data; - -return qio_channel_write_all (p->c, (void *)z->zbuff, p->next_packet_size, - errp); +return qio_channel_writev_all (p->c, p->iov, p->iovs_num, errp); }/**
Signature · 1 line
2.33.1
PATCH 14/23 multifd: Remove send_write() method
In reply to Juan QuintelaEverything use now iov's.
--- migration/multifd.h | 2 -- migration/multifd-zlib.c | 17 ----------------- migration/multifd-zstd.c | 17 ----------------- migration/multifd.c | 20 ++------------------ 4 files changed, 2 insertions(+), 54 deletions(-)
migration/multifd.h +0 -2
@@ -164,8 +164,6 @@ typedef struct {void (*send_cleanup)(MultiFDSendParams *p,Error **errp);/* Prepare the send packet */ int (*send_prepare)(MultiFDSendParams *p,Error **errp); -/* Write the send packet */ -int (*send_write)(MultiFDSendParams *p,uint32_t used,Error **errp);/* Setup for receiving side */ int (*recv_setup)(MultiFDRecvParams *p,Error **errp);/* Cleanup for receiving side */
migration/multifd-zlib.c +0 -17
@@ -152,22 +152,6 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)return 0 ; } -/** -* zlib_send_write: do the actual write of the data -* -* Do the actual write of the comprresed buffer. -* -* Returns 0 for success or -1 for error -* -* @p: Params for the channel that we are using -* @used: number of pages used -* @errp: pointer to an error -*/ -static int zlib_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) -{ -return qio_channel_writev_all (p->c, p->iov, p->iovs_num, errp); -} -/** * zlib_recv_setup: setup receive side *
@@ -307,7 +291,6 @@ static MultiFDMethods multifd_zlib_ops = { .send_setup = zlib_send_setup, .send_cleanup = zlib_send_cleanup, .send_prepare = zlib_send_prepare, - .send_write = zlib_send_write, .recv_setup = zlib_recv_setup, .recv_cleanup = zlib_recv_cleanup, .recv_pages = zlib_recv_pages
migration/multifd-zstd.c +0 -17
@@ -163,22 +163,6 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)return 0 ; } -/** -* zstd_send_write: do the actual write of the data -* -* Do the actual write of the comprresed buffer. -* -* Returns 0 for success or -1 for error -* -* @p: Params for the channel that we are using -* @used: number of pages used -* @errp: pointer to an error -*/ -static int zstd_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) -{ -return qio_channel_writev_all (p->c, p->iov, p->iovs_num, errp); -} -/** * zstd_recv_setup: setup receive side *
@@ -320,7 +304,6 @@ static MultiFDMethods multifd_zstd_ops = { .send_setup = zstd_send_setup, .send_cleanup = zstd_send_cleanup, .send_prepare = zstd_send_prepare, - .send_write = zstd_send_write, .recv_setup = zstd_recv_setup, .recv_cleanup = zstd_recv_cleanup, .recv_pages = zstd_recv_pages
migration/multifd.c +2 -18
@@ -100,22 +100,6 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp)return 0 ; } -/** -* nocomp_send_write: do the actual write of the data -* -* For no compression we just have to write the data. -* -* Returns 0 for success or -1 for error -* -* @p: Params for the channel that we are using -* @used: number of pages used -* @errp: pointer to an error -*/ -static int nocomp_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) -{ -return qio_channel_writev_all (p->c, p->iov, p->iovs_num, errp); -} -/** * nocomp_recv_setup: setup receive side *
@@ -173,7 +157,6 @@ static MultiFDMethods multifd_nocomp_ops = { .send_setup = nocomp_send_setup, .send_cleanup = nocomp_send_cleanup, .send_prepare = nocomp_send_prepare, - .send_write = nocomp_send_write, .recv_setup = nocomp_recv_setup, .recv_cleanup = nocomp_recv_cleanup, .recv_pages = nocomp_recv_pages
@@ -687,7 +670,8 @@ static void *multifd_send_thread(void *opaque) }if (used) { - ret = multifd_send_state->ops->send_write (p, used, &local_err); + ret =qio_channel_writev_all (p->c, p->iov, p->iovs_num, + &local_err);if (ret !=0 ) {break ; }
Signature · 1 line
2.33.1
PATCH 15/23 multifd: Use a single writev on the send side
In reply to Juan QuintelaUntil now, we wrote the packet header with write(), and the rest of the pages with writev(). Just increase the size of the iovec and do a single writev().
--- migration/multifd.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
migration/multifd.c +8 -12
@@ -643,7 +643,7 @@ static void *multifd_send_thread(void *opaque)uint32_t used = p->pages->num;uint64_t packet_num = p->packet_num;uint32_t flags = p->flags; - p->iovs_num =0 ; + p->iovs_num =1 ;if (used) { ret = multifd_send_state->ops->send_prepare (p, &local_err);
@@ -663,20 +663,15 @@ static void *multifd_send_thread(void *opaque)trace_multifd_send (p->id, packet_num, used, flags, p->next_packet_size); - ret =qio_channel_write_all (p->c, (void *)p->packet, - p->packet_len, &local_err); + p->iov[0 ].iov_len = p->packet_len; + p->iov[0 ].iov_base = p->packet; + + ret =qio_channel_writev_all (p->c, p->iov, p->iovs_num, + &local_err);if (ret !=0 ) {break ; } -if (used) { - ret =qio_channel_writev_all (p->c, p->iov, p->iovs_num, - &local_err); -if (ret !=0 ) { -break ; - } - } -qemu_mutex_lock (&p->mutex); p->pending_job--;qemu_mutex_unlock (&p->mutex);
@@ -913,7 +908,8 @@ int multifd_save_setup(Error **errp) p->packet->version =cpu_to_be32 (MULTIFD_VERSION ); p->name =g_strdup_printf ("multifdsend_%d" , i); p->tls_hostname =g_strdup (s->hostname); - p->iov = g_new0(struct iovec, page_count); +/* We need one extra place for the packet header */ + p->iov = g_new0(struct iovec, page_count + 1);socket_send_channel_create (multifd_new_send_channel_async, p); }
Signature · 1 line
2.33.1
PATCH 16/23 multifd: Unfold "used" variable by its value
In reply to Juan Quintela--- migration/multifd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
migration/multifd.c +3 -5
@@ -1059,7 +1059,6 @@ static void *multifd_recv_thread(void *opaque)rcu_register_thread ();while (true) { -uint32_t used;uint32_t flags;if (p->quit) {
@@ -1082,17 +1081,16 @@ static void *multifd_recv_thread(void *opaque)break ; } - used = p->pages->num; flags = p->flags;/* recv methods don't know how to handle the SYNC flag */ p->flags &= ~MULTIFD_FLAG_SYNC ; -trace_multifd_recv (p->id, p->packet_num, used, flags, +trace_multifd_recv (p->id, p->packet_num, p->pages->num, flags, p->next_packet_size); p->num_packets++; - p->num_pages += used; + p->num_pages += p->pages->num;qemu_mutex_unlock (&p->mutex); -if (used) { +if (p->pages->num) { ret = multifd_recv_state->ops->recv_pages (p, &local_err);if (ret !=0 ) {break ;
Signature · 1 line
2.33.1
PATCH 17/23 multifd: Use normal pages array on the send side
In reply to Juan Quintela--- migration/multifd.h | 8 ++++++-- migration/multifd-zlib.c | 6 +++--- migration/multifd-zstd.c | 6 +++--- migration/multifd.c | 30 +++++++++++++++++++----------- migration/trace-events | 4 ++-- 5 files changed, 33 insertions(+), 21 deletions(-)
migration/multifd.h +6 -2
@@ -104,14 +104,18 @@ typedef struct {/* thread local variables */ /* packets sent through this channel */ uint64_t num_packets; -/* pages sent through this channel */ -uint64_t num_pages; +/* non zero pages sent through this channel */ +uint64_t num_normal_pages;/* syncs main thread and channels */ QemuSemaphore sem_sync;/* buffers to send */ struct iovec *iov;/* number of iovs used */ uint32_t iovs_num; +/* Pages that are not zero */ +ram_addr_t *normal; +/* num of non zero pages */ +uint32_t normal_num;/* used for compression methods */ void *data; } MultiFDSendParams;
migration/multifd-zlib.c +3 -3
@@ -106,16 +106,16 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)int ret;uint32_t i; -for (i =0 ; i < p->pages->num; i++) { +for (i =0 ; i < p->normal_num; i++) {uint32_t available = z->zbuff_len - out_size;int flush =Z_NO_FLUSH ; -if (i == p->pages->num -1 ) { +if (i == p->normal_num -1 ) { flush =Z_SYNC_FLUSH ; } zs->avail_in = page_size; - zs->next_in = p->pages->block->host + p->pages->offset[i]; + zs->next_in = p->pages->block->host + p->normal[i]; zs->avail_out = available; zs->next_out = z->zbuff + out_size;
migration/multifd-zstd.c +3 -3
@@ -121,13 +121,13 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) z->out.size = z->zbuff_len; z->out.pos =0 ; -for (i =0 ; i < p->pages->num; i++) { +for (i =0 ; i < p->normal_num; i++) {ZSTD_EndDirective flush = ZSTD_e_continue; -if (i == p->pages->num -1 ) { +if (i == p->normal_num -1 ) { flush = ZSTD_e_flush; } - z->in.src = p->pages->block->host + p->pages->offset[i]; + z->in.src = p->pages->block->host + p->normal[i]; z->in.size = page_size; z->in.pos =0 ;
migration/multifd.c +19 -11
@@ -89,13 +89,13 @@ 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->pages->num; i++) { - p->iov[p->iovs_num].iov_base = pages->block->host + pages->offset[i]; +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->iovs_num++; } - p->next_packet_size = p->pages->num * page_size; + p->next_packet_size = p->normal_num * page_size; p->flags |=MULTIFD_FLAG_NOCOMP ;return 0 ; }
@@ -262,7 +262,7 @@ static void multifd_send_fill_packet(MultiFDSendParams *p) packet->flags =cpu_to_be32 (p->flags); packet->pages_alloc =cpu_to_be32 (p->pages->allocated); - packet->pages_used =cpu_to_be32 (p->pages->num); + packet->pages_used =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);
@@ -270,9 +270,9 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)strncpy (packet->ramblock, p->pages->block->idstr,256 ); } -for (i =0 ; i < p->pages->num; i++) { +for (i =0 ; i < p->normal_num; i++) {/* there are architectures where ram_addr_t is 32 bit */ -uint64_t temp = p->pages->offset[i]; +uint64_t temp = p->normal[i]; packet->offset[i] =cpu_to_be64 (temp); }
@@ -556,6 +556,8 @@ void multifd_save_cleanup(void) p->packet =NULL ;g_free (p->iov); p->iov =NULL ; +g_free (p->normal); + p->normal =NULL ; multifd_send_state->ops->send_cleanup (p, &local_err);if (local_err) {migrate_set_error (migrate_get_current (), local_err);
@@ -640,12 +642,17 @@ static void *multifd_send_thread(void *opaque)qemu_mutex_lock (&p->mutex);if (p->pending_job) { -uint32_t used = p->pages->num;uint64_t packet_num = p->packet_num;uint32_t flags = p->flags; p->iovs_num =1 ; + p->normal_num =0 ; -if (used) { +for (int i =0 ; i < p->pages->num; i++) { + p->normal[p->normal_num] = p->pages->offset[i]; + p->normal_num++; + } + +if (p->normal_num) { ret = multifd_send_state->ops->send_prepare (p, &local_err);if (ret !=0 ) {qemu_mutex_unlock (&p->mutex);
@@ -655,12 +662,12 @@ static void *multifd_send_thread(void *opaque)multifd_send_fill_packet (p); p->flags =0 ; p->num_packets++; - p->num_pages += used; + p->num_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, used, flags, +trace_multifd_send (p->id, packet_num, p->normal_num, flags, p->next_packet_size); p->iov[0 ].iov_len = p->packet_len;
@@ -710,7 +717,7 @@ out:qemu_mutex_unlock (&p->mutex);rcu_unregister_thread (); -trace_multifd_send_thread_end (p->id, p->num_packets, p->num_pages); +trace_multifd_send_thread_end (p->id, p->num_packets, p->num_normal_pages);return NULL ; }
@@ -910,6 +917,7 @@ int multifd_save_setup(Error **errp) p->tls_hostname =g_strdup (s->hostname);/* 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);socket_send_channel_create (multifd_new_send_channel_async, p); }
migration/trace-events +2 -2
@@ -124,13 +124,13 @@ multifd_recv_sync_main_wait(uint8_t id) "channel %d" multifd_recv_terminate_threads(bool error) "error %d" multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "channel %d packets %" PRIu64 " pages %" PRIu64 multifd_recv_thread_start(uint8_t id) "%d" -multifd_send(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flags, uint32_t next_packet_size) "channel %d packet_num %" PRIu64 " pages %d flags 0x%x next packet size %d" +multifd_send(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t flags, uint32_t next_packet_size) "channel %d packet_num %" PRIu64 " normal pages %d flags 0x%x next packet size %d" multifd_send_error(uint8_t id) "channel %d" multifd_send_sync_main(long packet_num) "packet num %ld" multifd_send_sync_main_signal(uint8_t id) "channel %d" multifd_send_sync_main_wait(uint8_t id) "channel %d" multifd_send_terminate_threads(bool error) "error %d" -multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "channel %d packets %" PRIu64 " pages %" PRIu64 +multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages) "channel %d packets %" PRIu64 " normal pages %" PRIu64 multifd_send_thread_start(uint8_t id) "%d" 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"
Signature · 1 line
2.33.1
Quoted 1 line · Juan Quintela
Hi
Nack myself.
For some reasons my mail server decided to only sent part of the series.
Sorry, Juan.
Quoted 89 lines
Since Friday version:
- More cleanups on the code
- Remove repeated calls toqemu_target_page_size()
- Establish normal pages and zero pages
- detect zero pages on the multifd threads
- send zero pages through the multifd channels.
- reviews by Richard addressed.It pases migration-test, so it should be perfect O:+)
ToDo for next version:
- check the version changes
I need that 6.2 is out to check for 7.0. This code don't exist at all due to that reason.
- Send measurements of the differencesPlease, review.
[
Friday version that just created a single writev instead of write+writev.
]
Right now, multifd does a
write()for the header and awritev()for each group of pages. Simplify it so we send the header as another member of the IOV.Once there, I got several simplifications:
*is_zero_range()was used only once, just use its body.
* same withis_zero_page().
* Be consintent and use offset insed the ramblock everywhere.
* Now that we have the offsets of the ramblock, we can drop the iov.
* Now that nothing uses iov's except NOCOMP method, move the iovs from pages to methods.
* Now we can use iov's with a single field for zlib/zstd.
*send_write()method is the same in all the implementaitons, so use it directly.
* Now, we can use a singlewritev()to write everything.ToDo: Move zero page detection to the multifd thrteads.
With RAM in the Terabytes size, the detection of the zero page takes too much time on the main thread.
Last patch on the series removes the detection of zero pages in the main thread for multifd. In the next series post, I will add how to detect the zero pages and send them on multifd channels.
Please review.
Later, Juan.
Juan Quintela (23):
multifd: Delete useless operation
migration: Never call twiceqemu_target_page_size()
multifd: Rename used field to num
multifd: Add missing documention
multifd: The variable is only used inside the loop
multifd: remove used parameter fromsend_prepare()method
multifd: remove used parameter fromsend_recv_pages()method
multifd: Fill offset and block for reception
multifd: Make zstd compression method not use iovs
multifd: Make zlib compression method not use iovs
multifd: Move iov from pages to params
multifd: Make zlib use iov's
multifd: Make zstd use iov's
multifd: Removesend_write()method
multifd: Use a single writev on the send side
multifd: Unfold "used" variable by its value
multifd: Use normal pages array on the send side
multifd: Use normal pages array on the recv side
multifd: recv side only needs the RAMBlock host address
multifd: Renamepages_usedtonormal_pages
multifd: Support for zero pages transmission
multifd: Zero pages transmission
migration: Use multifd before we check for the zero pagemigration/multifd.h | 52 +++++++--- migration/migration.c | 7 +- migration/multifd-zlib.c | 71 +++++-------- migration/multifd-zstd.c | 70 +++++-------- migration/multifd.c | 214 +++++++++++++++++++++++---------------- migration/ram.c | 22 ++-- migration/savevm.c | 5 +- migration/trace-events | 4 +- 8 files changed, 231 insertions(+), 214 deletions(-)