From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659422585454521.2712673279912; Mon, 1 Aug 2022 23:43:05 -0700 (PDT) Received: from localhost ([::1]:37590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlcO-0006RN-3O for importer@patchew.org; Tue, 02 Aug 2022 02:43:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYk-0003Zk-7Q for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59181) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYh-00068f-Da for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:17 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-_OKQg6mBMx2KxbMdLRXgpg-1; Tue, 02 Aug 2022 02:39:13 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B4228185A7A4; Tue, 2 Aug 2022 06:39:12 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0361A492C3B; Tue, 2 Aug 2022 06:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=22zCNyKw3QF8S97P4hVv9FBXKE9uVV+FAMAJ2OhDf7s=; b=bbytHoA4WaEbW4dPtooQp0Ra7Sy8tJuB58R1XzhHY/PBUU90I7pM6DOpEdLKiR1gvzHoNj slA+WcEsTkwrLcntmgDZwBRUBLMc1MgJI7NOFiXXH+N399uSwXeGzdF+chqD41CoFOYiHB 5YeT3pXHFGyN1iLTWJGkyM+jhePCyBc= X-MC-Unique: _OKQg6mBMx2KxbMdLRXgpg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 01/12] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Date: Tue, 2 Aug 2022 08:38:56 +0200 Message-Id: <20220802063907.18882-2-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1659422587916100001 Content-Type: text/plain; charset="utf-8" We were calling qemu_target_page_size() left and right. Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- migration/multifd.h | 4 ++++ migration/multifd-zlib.c | 14 ++++++-------- migration/multifd-zstd.c | 12 +++++------- migration/multifd.c | 18 ++++++++---------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 519f498643..86fb9982b3 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; =20 @@ -143,6 +145,8 @@ typedef struct { QIOChannel *c; /* packet allocated len */ uint32_t packet_len; + /* guest page size */ + uint32_t page_size; =20 /* syncs main thread and channels */ QemuSemaphore sem_sync; diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 18213a9513..37770248e1 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -116,7 +116,6 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Err= or **errp) static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) { struct zlib_data *z =3D p->data; - size_t page_size =3D qemu_target_page_size(); z_stream *zs =3D &z->zs; uint32_t out_size =3D 0; int ret; @@ -135,8 +134,8 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) * with compression. zlib does not guarantee that this is safe, * therefore copy the page before calling deflate(). */ - memcpy(z->buf, p->pages->block->host + p->normal[i], page_size); - zs->avail_in =3D page_size; + memcpy(z->buf, p->pages->block->host + p->normal[i], p->page_size); + zs->avail_in =3D p->page_size; zs->next_in =3D z->buf; =20 zs->avail_out =3D available; @@ -242,12 +241,11 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p) static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp) { struct zlib_data *z =3D p->data; - size_t page_size =3D qemu_target_page_size(); z_stream *zs =3D &z->zs; uint32_t in_size =3D p->next_packet_size; /* we measure the change of total_out */ uint32_t out_size =3D zs->total_out; - uint32_t expected_size =3D p->normal_num * page_size; + uint32_t expected_size =3D p->normal_num * p->page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; int ret; int i; @@ -274,7 +272,7 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error = **errp) flush =3D Z_SYNC_FLUSH; } =20 - zs->avail_out =3D page_size; + zs->avail_out =3D p->page_size; zs->next_out =3D p->host + p->normal[i]; =20 /* @@ -288,8 +286,8 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error = **errp) do { ret =3D inflate(zs, flush); } while (ret =3D=3D Z_OK && zs->avail_in - && (zs->total_out - start) < page_size); - if (ret =3D=3D Z_OK && (zs->total_out - start) < page_size) { + && (zs->total_out - start) < p->page_size); + if (ret =3D=3D 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, Err= or **errp) static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) { struct zstd_data *z =3D p->data; - size_t page_size =3D qemu_target_page_size(); int ret; uint32_t i; =20 @@ -128,7 +127,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Erro= r **errp) flush =3D ZSTD_e_flush; } z->in.src =3D p->pages->block->host + p->normal[i]; - z->in.size =3D page_size; + z->in.size =3D p->page_size; z->in.pos =3D 0; =20 /* @@ -241,8 +240,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) { uint32_t in_size =3D p->next_packet_size; uint32_t out_size =3D 0; - size_t page_size =3D qemu_target_page_size(); - uint32_t expected_size =3D p->normal_num * page_size; + uint32_t expected_size =3D p->normal_num * p->page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; struct zstd_data *z =3D p->data; int ret; @@ -265,7 +263,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) =20 for (i =3D 0; i < p->normal_num; i++) { z->out.dst =3D p->host + p->normal[i]; - z->out.size =3D page_size; + z->out.size =3D p->page_size; z->out.pos =3D 0; =20 /* @@ -279,8 +277,8 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) do { ret =3D 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 smal= l", p->id); return -1; diff --git a/migration/multifd.c b/migration/multifd.c index 586ddc9d65..d2070c9cee 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -87,15 +87,14 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, E= rror **errp) static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) { MultiFDPages_t *pages =3D p->pages; - size_t page_size =3D qemu_target_page_size(); =20 for (int i =3D 0; i < p->normal_num; i++) { p->iov[p->iovs_num].iov_base =3D pages->block->host + p->normal[i]; - p->iov[p->iovs_num].iov_len =3D page_size; + p->iov[p->iovs_num].iov_len =3D p->page_size; p->iovs_num++; } =20 - p->next_packet_size =3D p->normal_num * page_size; + p->next_packet_size =3D p->normal_num * p->page_size; p->flags |=3D 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 =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; - size_t page_size =3D qemu_target_page_size(); =20 if (flags !=3D 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, Erro= r **errp) } for (int i =3D 0; i < p->normal_num; i++) { p->iov[i].iov_base =3D p->host + p->normal[i]; - p->iov[i].iov_len =3D page_size; + p->iov[i].iov_len =3D 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 =3D p->packet; - size_t page_size =3D qemu_target_page_size(); - uint32_t page_count =3D MULTIFD_PACKET_SIZE / page_size; + uint32_t page_count =3D MULTIFD_PACKET_SIZE / p->page_size; RAMBlock *block; int i; =20 @@ -344,7 +341,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) for (i =3D 0; i < p->normal_num; i++) { uint64_t offset =3D be64_to_cpu(packet->offset[i]); =20 - 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 =3D multifd_send_state->packet_num++; multifd_send_state->pages =3D p->pages; p->pages =3D pages; - transferred =3D ((uint64_t) pages->num) * qemu_target_page_size() - + p->packet_len; + transferred =3D ((uint64_t) pages->num) * p->page_size + p->packet_len; qemu_file_acct_rate_limit(f, transferred); ram_counters.multifd_bytes +=3D transferred; ram_counters.transferred +=3D transferred; @@ -939,6 +935,7 @@ int multifd_save_setup(Error **errp) /* We need one extra place for the packet header */ p->iov =3D g_new0(struct iovec, page_count + 1); p->normal =3D g_new0(ram_addr_t, page_count); + p->page_size =3D qemu_target_page_size(); =20 if (migrate_use_zero_copy_send()) { p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; @@ -1186,6 +1183,7 @@ int multifd_load_setup(Error **errp) p->name =3D g_strdup_printf("multifdrecv_%d", i); p->iov =3D g_new0(struct iovec, page_count); p->normal =3D g_new0(ram_addr_t, page_count); + p->page_size =3D qemu_target_page_size(); } =20 for (i =3D 0; i < thread_count; i++) { --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659422587539279.90157418534557; Mon, 1 Aug 2022 23:43:07 -0700 (PDT) Received: from localhost ([::1]:37662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlcO-0006Tz-Td for importer@patchew.org; Tue, 02 Aug 2022 02:43:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYn-0003aX-20 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57607) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYl-000693-EX for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:20 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-318-GQSacfmwO2-Hvn_7-e6xPQ-1; Tue, 02 Aug 2022 02:39:15 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B68B98032F1; Tue, 2 Aug 2022 06:39:14 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 057D1492C3B; Tue, 2 Aug 2022 06:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qh87vvu5VwRii76fa69oHvnB4mcPle+GsD9B6Tb14Ek=; b=J3GJUzi+pM7dOr1Io4/jRMKI79ujaIk3sXSIKWDIsaWD36wkBRX0JWgsoa7EiqnWOrlXaS cBEGAqhZeWWhvJpHZGBWsTUI7+rxPa8QsLEHn7OpfxsAFCGKZpj4tcv3OcEJ7RUzsgA+wV u+t3ka5gr8Ul9u4qNbGkCx66rZ+kA7w= X-MC-Unique: GQSacfmwO2-Hvn_7-e6xPQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 02/12] multifd: Create page_count fields into both MultiFD{Recv, Send}Params Date: Tue, 2 Aug 2022 08:38:57 +0200 Message-Id: <20220802063907.18882-3-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1659422589645100003 Content-Type: text/plain; charset="utf-8" We were recalculating it left and right. We plan to change that values on next patches. Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- 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 86fb9982b3..e2802a9ce2 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; =20 @@ -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; =20 /* syncs main thread and channels */ QemuSemaphore sem_sync; diff --git a/migration/multifd.c b/migration/multifd.c index d2070c9cee..aa3808a6f4 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 =3D p->packet; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / p->page_size; RAMBlock *block; int i; =20 @@ -306,10 +305,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvPara= ms *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; } =20 @@ -936,6 +935,7 @@ int multifd_save_setup(Error **errp) p->iov =3D g_new0(struct iovec, page_count + 1); p->normal =3D g_new0(ram_addr_t, page_count); p->page_size =3D qemu_target_page_size(); + p->page_count =3D page_count; =20 if (migrate_use_zero_copy_send()) { p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; @@ -1183,6 +1183,7 @@ int multifd_load_setup(Error **errp) p->name =3D g_strdup_printf("multifdrecv_%d", i); p->iov =3D g_new0(struct iovec, page_count); p->normal =3D g_new0(ram_addr_t, page_count); + p->page_count =3D page_count; p->page_size =3D qemu_target_page_size(); } =20 --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659422589; cv=none; d=zohomail.com; s=zohoarc; b=n1qERR8UsZ7mQ33x9I9k6m9nIDqLdRLNyjOi9KAzRkwxO8L9rQKFBXG0q58Ra0MdJm63DtYajP/aRlLqw0zim99YT28tgu04i+EYYAPfZKducN46ao/mX4uKb7e8nLggu6eLyRcNKSIaogLXX0gOm1xW9agovo6odDw3z2sxzfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659422589; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uJlrmi9iVJ3erLWVIyPpluM5yM8E8sJ6ShhNGVxb2VQ=; b=O7WFiQVpicabDbU4spSC6Ci7OnanuAAr/Y8sZKD8BH3imLy27rZVWA81CsR8UPijJTsuz0rvp6gCXbqxpGWn10ACVYf8Xwa6ju+f14TGzorGZHm0NHEVEa5toHFK/3oolqcaUVXsp3/1SJGAtvg/TFY5p4174hk8uZcJq/2XxnM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659422589374128.20374542601166; Mon, 1 Aug 2022 23:43:09 -0700 (PDT) Received: from localhost ([::1]:37828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlcS-0006ar-B2 for importer@patchew.org; Tue, 02 Aug 2022 02:43:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYp-0003ac-I5 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYo-00069V-4R for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:23 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-ihlI0P0zMUG0c-qkCD2ClA-1; Tue, 02 Aug 2022 02:39:17 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DB00B2813D2A; Tue, 2 Aug 2022 06:39:16 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A1BF492C3B; Tue, 2 Aug 2022 06:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uJlrmi9iVJ3erLWVIyPpluM5yM8E8sJ6ShhNGVxb2VQ=; b=b60fhCipjZ2infX0MBok6rac5vWqZBsWBUD5ku78jdHN/iZWMV02mJs76cInk0XcPb64RI lsx1KhWC93JCBsMCv+SH0FWYJg/NF6gQRFb6HM01hTMOkLmn+Kxy8+29yleX6Xrwrq9FmX uHku6CfYoJ6V4QDlreodAYtHBVbTQ1c= X-MC-Unique: ihlI0P0zMUG0c-qkCD2ClA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost , David Edmondson Subject: [PATCH v7 03/12] migration: Export ram_transferred_ram() Date: Tue, 2 Aug 2022 08:38:58 +0200 Message-Id: <20220802063907.18882-4-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659422589669100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- 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 c7af65ac74..e844966f69 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -65,6 +65,8 @@ int ram_load_postcopy(QEMUFile *f, int channel); =20 void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); =20 +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_off= set); void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr); diff --git a/migration/ram.c b/migration/ram.c index b94669ba5d..85d89d61ac 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -422,7 +422,7 @@ uint64_t ram_bytes_remaining(void) =20 MigrationStats ram_counters; =20 -static void ram_transferred_add(uint64_t bytes) +void ram_transferred_add(uint64_t bytes) { if (runstate_is_running()) { ram_counters.precopy_bytes +=3D bytes; --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659423922; cv=none; d=zohomail.com; s=zohoarc; b=Eip/1fdbrt6p4xLmAJvhoTSywecaG4kuQKsQAGrOqGy+n72eWULPbtzZ1fuCZsr23dK0gkTy7pv9wOSaDzcBAjOmXk/xf2OlmrSFdybukIYYWHx8DgRAKahdWEKZNZ81xqI9evCz6+Qeg6sMHX6lHiuHnLShXuNO0CDStjM4v1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659423922; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=M7DBta0IwtMjK7saNyDc3MuKfaq6iikA8gKwPoBejV0=; b=JhhM8qxZJg/e6O0r29FOzfBo/8HQCB8oqucZyR/mY2C4aP0V+Jq9GdmQkl8FUNozHvR1zpCQWsY77az2g9iuseetuk9aLJJr0+YRex75FdLwqcIDy/CGpw0pgeCRIbAHkHSybOXuvNdm3sV5jpLLTUyUeb7MQoyonJO5lt1OBpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165942392224682.48301726687123; Tue, 2 Aug 2022 00:05:22 -0700 (PDT) Received: from localhost ([::1]:34452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlxw-0007Sj-DG for importer@patchew.org; Tue, 02 Aug 2022 03:05:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYx-0003fo-Vr for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYw-0006AU-6M for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:31 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-509-4UacYAukP_q_buWKeIsdzw-1; Tue, 02 Aug 2022 02:39:19 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E18BB101A586; Tue, 2 Aug 2022 06:39:18 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B14A492C3B; Tue, 2 Aug 2022 06:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M7DBta0IwtMjK7saNyDc3MuKfaq6iikA8gKwPoBejV0=; b=BuZKvMr2jEv1OT/0PsQb0WLCrUyfE7USccC4/vg4hu0f7AARcFEj48s5XItt4gjNAQsNlp ZnvROoMFiSK27MdxiYNwTsCuvgiVcw08LesdVLDBao/Y9hZjLzcz5fBZSZ4uIwfQfI6JwI iDtOpVglONIrh+b/34Naj1XMhVK98AY= X-MC-Unique: 4UacYAukP_q_buWKeIsdzw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 04/12] multifd: Count the number of bytes sent correctly Date: Tue, 2 Aug 2022 08:38:59 +0200 Message-Id: <20220802063907.18882-5-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659423924025100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Leonardo Bras --- 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 e2802a9ce2..36f899c56f 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 aa3808a6f4..e25b529235 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 =3D NULL; /* make happy gcc */ MultiFDPages_t *pages =3D multifd_send_state->pages; - uint64_t transferred; =20 if (qatomic_read(&multifd_send_state->exiting)) { return -1; @@ -429,10 +428,10 @@ static int multifd_send_pages(QEMUFile *f) p->packet_num =3D multifd_send_state->packet_num++; multifd_send_state->pages =3D p->pages; p->pages =3D pages; - transferred =3D ((uint64_t) pages->num) * p->page_size + p->packet_len; - qemu_file_acct_rate_limit(f, transferred); - ram_counters.multifd_bytes +=3D transferred; - ram_counters.transferred +=3D transferred; + ram_transferred_add(p->sent_bytes); + ram_counters.multifd_bytes +=3D p->sent_bytes; + qemu_file_acct_rate_limit(f, p->sent_bytes); + p->sent_bytes =3D 0; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 @@ -605,9 +604,6 @@ int multifd_send_sync_main(QEMUFile *f) p->packet_num =3D multifd_send_state->packet_num++; p->flags |=3D MULTIFD_FLAG_SYNC; p->pending_job++; - qemu_file_acct_rate_limit(f, p->packet_len); - ram_counters.multifd_bytes +=3D p->packet_len; - ram_counters.transferred +=3D p->packet_len; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 @@ -714,6 +710,8 @@ static void *multifd_send_thread(void *opaque) } =20 qemu_mutex_lock(&p->mutex); + p->sent_bytes +=3D p->packet_len;; + p->sent_bytes +=3D p->next_packet_size; p->pending_job--; qemu_mutex_unlock(&p->mutex); =20 --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659423177; cv=none; d=zohomail.com; s=zohoarc; b=dWpEy3zWskWUOrbhG83rvhWyjbMg0goClwc1PNwiyY8ctq2JUfqfTF5NfTLgskdpJAoNOTW76CUtAJqCJ9aEg2x9VgN4mEpXwJW2otdAZXNZxFIQlBl9814zS/4bXhZkXi8cGN83Wv1xHqx5yRa4p2QlSFjzdjb0ZhF4omTcr4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659423177; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NiIKDNZlhx1U8gPHZmVZKg7N8xckxwlRQ/PsR1YBQck=; b=mZFS6S6JUPpCRAMLgRD2vviRfV1vJj9r/LUzGnvVYtl/lHEeOIBPgr+5qgN6TzKhNcyUlnsrwHG+EFDapT/8QpRsbK/X7Z2JhDvvXLdF8Bputqx6J3xO9pnpM41kDi1uMjOOKsUVclBURDgB64vLKjpzbXiQUmTaPFvRonLJHgg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659423177126907.7646171302639; Mon, 1 Aug 2022 23:52:57 -0700 (PDT) Received: from localhost ([::1]:48088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIllw-0005K5-4P for importer@patchew.org; Tue, 02 Aug 2022 02:52:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYu-0003cI-HZ for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYs-0006A4-AF for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-203-MiSY0jvaOYeyRJTGsTPJNg-1; Tue, 02 Aug 2022 02:39:21 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E3EB7101A58D; Tue, 2 Aug 2022 06:39:20 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31277492CA2; Tue, 2 Aug 2022 06:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NiIKDNZlhx1U8gPHZmVZKg7N8xckxwlRQ/PsR1YBQck=; b=SpF6z91+Wz8FEIiBXU1p+/0qErv22Lzk+z8uOymAu9mQTVibCouf/MVy81ltktRF+0K6Ao pHmgf9rnfWgRo43C8TaOfoyIQdLKo76eaZIDJiXJtFm0SFVXt/VX3Lp/zUlZQLQ5zbg+tb QhTBNaDs4B2sBsVum85Yj3AlavufXeI= X-MC-Unique: MiSY0jvaOYeyRJTGsTPJNg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 05/12] migration: Make ram_save_target_page() a pointer Date: Tue, 2 Aug 2022 08:39:00 +0200 Message-Id: <20220802063907.18882-6-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659423178395100001 Content-Type: text/plain; charset="utf-8" We are going to create a new function for multifd latest in the series. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 85d89d61ac..499d9b2a90 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -310,6 +310,9 @@ typedef struct { bool preempted; } PostcopyPreemptState; =20 +typedef struct RAMState RAMState; +typedef struct PageSearchStatus PageSearchStatus; + /* State of RAM for migration */ struct RAMState { /* QEMUFile used for this migration */ @@ -372,8 +375,9 @@ struct RAMState { * is enabled. */ unsigned int postcopy_channel; + + int (*ram_save_target_page)(RAMState *rs, PageSearchStatus *pss); }; -typedef struct RAMState RAMState; =20 static RAMState *ram_state; =20 @@ -2255,14 +2259,14 @@ static bool save_compress_page(RAMState *rs, RAMBlo= ck *block, ram_addr_t offset) } =20 /** - * 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 =3D pss->block; ram_addr_t offset =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; @@ -2469,7 +2473,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) =20 /* Check the pages is dirty and if it is send it */ if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { - tmppages =3D ram_save_target_page(rs, pss); + tmppages =3D rs->ram_save_target_page(rs, pss); if (tmppages < 0) { return tmppages; } @@ -3223,6 +3227,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); =20 + (*rsp)->ram_save_target_page =3D ram_save_target_page_legacy; ret =3D multifd_send_sync_main(f); if (ret < 0) { return ret; --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659422958; cv=none; d=zohomail.com; s=zohoarc; b=HDnIxA3SnRcnpBoIGc3CvJoymYFeksdlkCf2Q1agcss8Vrfs1gN/6qL+sXJuKVro3oWR92cVyCmaNcEbKttAgPy2iJrp8hh0iUML1U7kWi5QZphaX92g9IdL7gfuVkycs77jnYuaM/bMlt5zj8ZSt+xgsRzcWRCYJBW+YAw6lcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659422958; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=76gzbDxtqg+F5mUECg5pLuW2iaQHOsZmZusZF+Jsh8c=; b=fYjjD375CS7NSbdA/7VcOJMX+Fj1PzEaJ+CPVrjB1gZf3hwrZWGxc4D0eFplUNDH5jwrgumRPhX4Mj7eZps87Rc5q1f0yiANlXNM0m8LLMbU7V2AyYXY+iRd7N2lg6P5Y+mHTNV49oL2H4txdfE60rhpu73CoGGTTxHrAleB3gQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659422958114559.2690542752279; Mon, 1 Aug 2022 23:49:18 -0700 (PDT) Received: from localhost ([::1]:45112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIliN-0003DC-Uz for importer@patchew.org; Tue, 02 Aug 2022 02:49:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ0-0003kU-Tw for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47360) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYy-0006Az-5n for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:33 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-6PGz-ByRNW2CcFQlYRkqbw-1; Tue, 02 Aug 2022 02:39:23 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F67E3C01E09; Tue, 2 Aug 2022 06:39:23 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 388F4492CA2; Tue, 2 Aug 2022 06:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=76gzbDxtqg+F5mUECg5pLuW2iaQHOsZmZusZF+Jsh8c=; b=R+YQB8a0pcrwwX8uIYuSdMZtIRLwgQV8gqsMEs2Bg7yEvVyg7GTkBMmRP1/Vvtmivd+AcH +6ypMJYL52sLr2AHEs5roN5nmX+b9Eqztej8uLa+DDnJKhlMu04aBjSQAohf+c3wV6aoyu EZDOIjAJ5jOtXAO4uXcfhfJHgp6D1G8= X-MC-Unique: 6PGz-ByRNW2CcFQlYRkqbw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 06/12] multifd: Make flags field thread local Date: Tue, 2 Aug 2022 08:39:01 +0200 Message-Id: <20220802063907.18882-7-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659422958599100003 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Leonardo Bras --- 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 36f899c56f..a67cefc0a2 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 { =20 /* 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; =20 @@ -172,6 +172,8 @@ typedef struct { =20 /* 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 e25b529235..09a40a9135 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -602,7 +602,7 @@ int multifd_send_sync_main(QEMUFile *f) } =20 p->packet_num =3D multifd_send_state->packet_num++; - p->flags |=3D MULTIFD_FLAG_SYNC; + p->sync_needed =3D true; p->pending_job++; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); @@ -658,7 +658,11 @@ static void *multifd_send_thread(void *opaque) =20 if (p->pending_job) { uint64_t packet_num =3D p->packet_num; - uint32_t flags =3D p->flags; + p->flags =3D 0; + if (p->sync_needed) { + p->flags |=3D MULTIFD_FLAG_SYNC; + p->sync_needed =3D false; + } p->normal_num =3D 0; =20 if (use_zero_copy_send) { @@ -680,14 +684,13 @@ static void *multifd_send_thread(void *opaque) } } multifd_send_fill_packet(p); - p->flags =3D 0; p->num_packets++; p->total_normal_pages +=3D p->normal_num; p->pages->num =3D 0; p->pages->block =3D NULL; qemu_mutex_unlock(&p->mutex); =20 - 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); =20 if (use_zero_copy_send) { @@ -715,7 +718,7 @@ static void *multifd_send_thread(void *opaque) p->pending_job--; qemu_mutex_unlock(&p->mutex); =20 - 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(); =20 while (true) { - uint32_t flags; + bool sync_needed =3D false; =20 if (p->quit) { break; @@ -1112,11 +1115,11 @@ static void *multifd_recv_thread(void *opaque) break; } =20 - flags =3D p->flags; + trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags, + p->next_packet_size); + sync_needed =3D p->flags & MULTIFD_FLAG_SYNC; /* recv methods don't know how to handle the SYNC flag */ p->flags &=3D ~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 +=3D p->normal_num; qemu_mutex_unlock(&p->mutex); @@ -1128,7 +1131,7 @@ static void *multifd_recv_thread(void *opaque) } } =20 - if (flags & MULTIFD_FLAG_SYNC) { + if (sync_needed) { qemu_sem_post(&multifd_recv_state->sem_sync); qemu_sem_wait(&p->sem_sync); } --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659423492; cv=none; d=zohomail.com; s=zohoarc; b=lU8rEKsRVrkOnUALwzFkiYlRJ1z+eaqHTx0u9tfXt7mQvzKR+GzGK7NHhJOiCIcf7NIsJKhdKFfL6c05MUXLuddFadMNY6BmyPH3JmDEltPO27D8aQLKad5AoKfp2+Bj27YOr8k5g2Ch2SvldNSHo8mrpvxLvI82VLJmTRtR6p4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659423492; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BKk+rufYTs+ABq8YvqaTrjARU5zr9e9qkw9xs8rMF60=; b=W/i+hNOgfgXUoIcwjS2TJX+WXmQzAUrgxDH6V+0TPek7EDJRb1QVweC03WnyQ67GekmPJzIwW7sU8jNTPD/ouHvyn/lCsMVhFFndgLLeWZ6CpwLns9AFzmhNsr3UryzAoaZlDJrMv4vK52kIM+4L1S6JKUFiSVzrjY6PWw/mlqk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659423492911789.8130569796456; Mon, 1 Aug 2022 23:58:12 -0700 (PDT) Received: from localhost ([::1]:56070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlr1-0002c3-FS for importer@patchew.org; Tue, 02 Aug 2022 02:58:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYw-0003cZ-F1 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYt-0006AE-D1 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:29 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-231-aF7RiASvPAyDQ_JzKRDPhg-1; Tue, 02 Aug 2022 02:39:25 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34753101AA48; Tue, 2 Aug 2022 06:39:25 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65D4C492C3B; Tue, 2 Aug 2022 06:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BKk+rufYTs+ABq8YvqaTrjARU5zr9e9qkw9xs8rMF60=; b=GtwG+eX+X/u/4Wns6GN/zR4s/y79PEWsMtfUl7t0r0BNEUeUws13LzHpWKfFp+OkBmllkV oTLZ4JRKf7FFni3W+wUADQpX6HXfpLcyOrkJ9KoUwSaMuJfGOmCQTgpV28pN1w90syZxsR SF6HW4MOAlRiE/uSrikDgdOw2xA6GKk= X-MC-Unique: aF7RiASvPAyDQ_JzKRDPhg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 07/12] multifd: Prepare to send a packet without the mutex held Date: Tue, 2 Aug 2022 08:39:02 +0200 Message-Id: <20220802063907.18882-8-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659423495030100001 Content-Type: text/plain; charset="utf-8" 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 =3D=3D 1. Signed-off-by: Juan Quintela --- 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 a67cefc0a2..cd389d18d2 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 =3D=3D 0 -> migration_thread can use it. + * No need for mutex lock. * pending_job !=3D 0 -> multifd_channel can use it. + * No need for mutex lock. */ MultiFDPages_t *pages; =20 diff --git a/migration/multifd.c b/migration/multifd.c index 09a40a9135..68fc9f8e88 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -663,6 +663,8 @@ static void *multifd_send_thread(void *opaque) p->flags |=3D MULTIFD_FLAG_SYNC; p->sync_needed =3D false; } + qemu_mutex_unlock(&p->mutex); + p->normal_num =3D 0; =20 if (use_zero_copy_send) { @@ -684,11 +686,6 @@ static void *multifd_send_thread(void *opaque) } } multifd_send_fill_packet(p); - p->num_packets++; - p->total_normal_pages +=3D p->normal_num; - p->pages->num =3D 0; - p->pages->block =3D NULL; - qemu_mutex_unlock(&p->mutex); =20 trace_multifd_send(p->id, packet_num, p->normal_num, p->flags, p->next_packet_size); @@ -713,6 +710,10 @@ static void *multifd_send_thread(void *opaque) } =20 qemu_mutex_lock(&p->mutex); + p->num_packets++; + p->total_normal_pages +=3D p->normal_num; + p->pages->num =3D 0; + p->pages->block =3D NULL; p->sent_bytes +=3D p->packet_len;; p->sent_bytes +=3D p->next_packet_size; p->pending_job--; --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659422956; cv=none; d=zohomail.com; s=zohoarc; b=lh1pHvNMnacuRIgtmpsnXGx1bQ7/odLNxXh+fnrsNVqHnwuWPMbYbI5gQACssFIJes8YwzMDetLqECS4NBYu6W1Jjlxrgz0Hf9XEbOWXEyO5uuRYQCL7HbzGgRWSGh+y0eHnYMuKyWeoD+lyNw4HBD9ukgnvH5arwhR+f7Svx4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659422956; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s6wxogTvPMNm1WaRmoYfVZ5rHPIZnK67ZSnNj/hwyes=; b=MWpNzuu2Y/HBRF/tn7ubLNa16zLYzKltcXFmiVw9YADvtyVM+Qk0Mk/CYYPqnWgypOxeHPT9eMNZnspJ8mohipOTzPpxVuNWZEE36I3LFgQMtOdhQF0uglBYm9muvbxu7tJaGV99J+pNNMu+qHR44FwUIZTKFFBxcJLcg4cNk0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659422956312908.3077350148119; Mon, 1 Aug 2022 23:49:16 -0700 (PDT) Received: from localhost ([::1]:45078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIliM-0003Bn-N4 for importer@patchew.org; Tue, 02 Aug 2022 02:49:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYw-0003dU-UZ for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYv-0006AN-81 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:30 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-Cenf7TL9PBWTPtel0Kh01A-1; Tue, 02 Aug 2022 02:39:27 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 387D23C01DF9; Tue, 2 Aug 2022 06:39:27 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A6E4492CA4; Tue, 2 Aug 2022 06:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s6wxogTvPMNm1WaRmoYfVZ5rHPIZnK67ZSnNj/hwyes=; b=FvhJ9wZqxVWkKjW5SAE1Ypakjdm0DIb6W6k7j46pw0YXLOmTNYzeSPB8fquetoooJ6GsS0 JHmVru4YBsDM6ejOPMd47JheRSkx7QOdwdaQChDwmTWO6/TRdrJIks7V+61WuVbVaN6GEV bFSt8iP3Ht5WK0NXpccik5cBPLtOkAA= X-MC-Unique: Cenf7TL9PBWTPtel0Kh01A-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 08/12] multifd: Add capability to enable/disable zero_page Date: Tue, 2 Aug 2022 08:39:03 +0200 Message-Id: <20220802063907.18882-9-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659422956804100001 Content-Type: text/plain; charset="utf-8" We have to enable it by default until we introduce the new code. Signed-off-by: Juan Quintela --- Change it to a capability. As capabilities are off by default, have to change MULTIFD_ZERO_PAGE to MAIN_ZERO_PAGE, so it is false for default, and true for older versions. --- qapi/migration.json | 8 +++++++- migration/migration.h | 1 + hw/core/machine.c | 1 + migration/migration.c | 16 +++++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 81185d4311..dc981236ff 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -472,12 +472,18 @@ # Requires that QEMU be permitted to use locked memory # for guest RAM pages. # (since 7.1) +# # @postcopy-preempt: If enabled, the migration process will allow postcopy # requests to preempt precopy stream, so postcopy reque= sts # will be handled faster. This is a performance featur= e and # should not affect the correctness of postcopy migrati= on. # (since 7.1) # +# @main-zero-page: If enabled, the detection of zero pages will be +# done on the main thread. Otherwise it is done on +# the multifd threads. +# (since 7.1) +# # Features: # @unstable: Members @x-colo and @x-ignore-shared are experimental. # @@ -492,7 +498,7 @@ 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', - 'zero-copy-send', 'postcopy-preempt'] } + 'zero-copy-send', 'postcopy-preempt', 'main-zero-page'] } =20 ## # @MigrationCapabilityStatus: diff --git a/migration/migration.h b/migration/migration.h index cdad8aceaa..58b245b138 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -415,6 +415,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_main_zero_page(void); =20 #ifdef CONFIG_LINUX bool migrate_use_zero_copy_send(void); diff --git a/hw/core/machine.c b/hw/core/machine.c index a673302cce..2624b75ab4 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -43,6 +43,7 @@ GlobalProperty hw_compat_7_0[] =3D { { "arm-gicv3-common", "force-8-bit-prio", "on" }, { "nvme-ns", "eui64-default", "on"}, + { "migration", "main-zero-page", "true" }, }; const size_t hw_compat_7_0_len =3D G_N_ELEMENTS(hw_compat_7_0); =20 diff --git a/migration/migration.c b/migration/migration.c index e03f698a3c..ce3e5cc0cd 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -164,7 +164,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snaps= hot, MIGRATION_CAPABILITY_XBZRLE, MIGRATION_CAPABILITY_X_COLO, MIGRATION_CAPABILITY_VALIDATE_UUID, - MIGRATION_CAPABILITY_ZERO_COPY_SEND); + MIGRATION_CAPABILITY_ZERO_COPY_SEND, + MIGRATION_CAPABILITY_MAIN_ZERO_PAGE); =20 /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add @@ -2592,6 +2593,17 @@ bool migrate_use_multifd(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_MULTIFD]; } =20 +bool migrate_use_main_zero_page(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + // We will enable this when we add the right code. + // return s->enabled_capabilities[MIGRATION_CAPABILITY_MAIN_ZERO_PAGE]; + return true; +} + bool migrate_pause_before_switchover(void) { MigrationState *s; @@ -4406,6 +4418,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-zero-copy-send", MIGRATION_CAPABILITY_ZERO_COPY_SEND), #endif + DEFINE_PROP_MIG_CAP("main-zero-page", + MIGRATION_CAPABILITY_MAIN_ZERO_PAGE), =20 DEFINE_PROP_END_OF_LIST(), }; --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659423443; cv=none; d=zohomail.com; s=zohoarc; b=UJIsfR/XQA+Zupibr4bLyVjE3hC9cpu3TKVdVoq6yXFj5kHTYoIgToN6f0tsPOmv5M+M2TGGX4J8eg0KtE+GVEOBweZwPlY3LZvhoz4l685PYQ++TLKFqJDM2v98wGItbaoD33b89ASmQ/VrXrCsVn3O8w0SjcAX8p81Y4wzOtE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659423443; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kHrCvCkUm/81My8+ieIfOxeXeHS005XC+7a4UCb0DDM=; b=CMEMTQNB2A7lMHxtOmk36z+I04RSGom8NoCTjAG3Fco1UkCqziS7Ni7cvHjRVU3D3HfaGtQfo6Az5P3gxA/PeHJ+6xk91r2K3aFU5Wpa9EC2vfCfqTrBjQHfXksaVVz13M8Ia8WYrx8f1MWrG98OgtZHCoYMJN2EzgS3HzWCFOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659423443912311.5643872504429; Mon, 1 Aug 2022 23:57:23 -0700 (PDT) Received: from localhost ([::1]:53260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlqE-0000WA-RN for importer@patchew.org; Tue, 02 Aug 2022 02:57:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ1-0003nO-Uo for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlYz-0006BD-Cj for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:35 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-Ogy2_OtyOs2qyYE4dpKMMA-1; Tue, 02 Aug 2022 02:39:29 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 398F23803909; Tue, 2 Aug 2022 06:39:29 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C297492C3B; Tue, 2 Aug 2022 06:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kHrCvCkUm/81My8+ieIfOxeXeHS005XC+7a4UCb0DDM=; b=ZBhbfRKfjPpzojeRjbablSM/gyBTsf2Dmakdpy1rsNaAF8QtMgqveTeuK4aCD5x87SMvtZ Or7S9EZCDd8RyEeA81RdeC7o7zWEv67YJH5+u85XLlZmXA7N3qwGvwFTfGSzsDrKt+cXW2 I+SItaXgSYqfuzb5m8K7BVGUdqzdW20= X-MC-Unique: Ogy2_OtyOs2qyYE4dpKMMA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 09/12] migration: Export ram_release_page() Date: Tue, 2 Aug 2022 08:39:04 +0200 Message-Id: <20220802063907.18882-10-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659423444962100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- 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 e844966f69..038d52f49f 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -66,6 +66,7 @@ int ram_load_postcopy(QEMUFile *f, int channel); void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); =20 void ram_transferred_add(uint64_t bytes); +void ram_release_page(const char *rbname, uint64_t offset); =20 int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr); bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_off= set); diff --git a/migration/ram.c b/migration/ram.c index 499d9b2a90..291ba5c0ed 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1238,7 +1238,7 @@ static void migration_bitmap_sync_precopy(RAMState *r= s) } } =20 -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; --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659423442; cv=none; d=zohomail.com; s=zohoarc; b=HhiKjcdTApw3gjtIj2lHBxUkr54/yr9YiD53SlsdY08NSvSTkBMRvAvp0dL2o6Nk40DYtaT42VpGnqXb5FlXMvLps4BxN8iMe79iGv+oI5LDnu43KnrQcyUgjAtT7xxo89UE9wbU2lvoWru6FAglhzQIOGcZSjg82TKkS9lNNBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659423442; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gDW9S5ced4Sx6n3tdXtQZM85Bw9CrzB6wNGinbcEKvg=; b=ij7jIUHnvMbPLgBhjlslJmJtr8r+WSxRlqFMPObiXeM1w2VkDvadnEJLFUxPQNGeUn+VDsCybEDLMBdbvf8qCukrG9byimi/LOAb6olviEQMuoskq6vuYnVhMcsz8C1sdFH9ha0ebVwPfQTT3i9edDcRQVaKtKh2QZmSV3KTmSc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659423442566180.73068303291393; Mon, 1 Aug 2022 23:57:22 -0700 (PDT) Received: from localhost ([::1]:53116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlqC-0000Pu-Ak for importer@patchew.org; Tue, 02 Aug 2022 02:57:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ3-0003tr-W5 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ1-0006Bg-Oj for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:37 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-fRuU4r13Me-QleuPv6-tyQ-1; Tue, 02 Aug 2022 02:39:32 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4338811768; Tue, 2 Aug 2022 06:39:31 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81F3F492C3B; Tue, 2 Aug 2022 06:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gDW9S5ced4Sx6n3tdXtQZM85Bw9CrzB6wNGinbcEKvg=; b=jMi7QMppClhp+c6HmAy0iky2HaTjpnRQjj2/f8UvpG62re+ug7Q4fMWSMjna1nXBPOp089 +Chnfijum9tKqDUMaQFFalqDDGe6mjzu+ocrFrId5s9uGP2QGkbuV2fWwn4w1J58tCqeNz vXac3DfdZSFyvhs6qQc/CTUmnAfwerY= X-MC-Unique: fRuU4r13Me-QleuPv6-tyQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 10/12] multifd: Support for zero pages transmission Date: Tue, 2 Aug 2022 08:39:05 +0200 Message-Id: <20220802063907.18882-11-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659423445012100003 Content-Type: text/plain; charset="utf-8" This patch adds counters and similar. Logic will be added on the following patch. Signed-off-by: Juan Quintela --- 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 cd389d18d2..a1b852200d 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 68fc9f8e88..4473d9f834 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -263,6 +263,7 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) packet->normal_pages =3D cpu_to_be32(p->normal_num); packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); packet->packet_num =3D cpu_to_be64(p->packet_num); + packet->zero_pages =3D cpu_to_be32(p->zero_num); =20 if (p->pages->block) { strncpy(packet->ramblock, p->pages->block->idstr, 256); @@ -323,7 +324,15 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); p->packet_num =3D be64_to_cpu(packet->packet_num); =20 - if (p->normal_num =3D=3D 0) { + p->zero_num =3D 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 =3D=3D 0 && p->zero_num =3D=3D 0) { return 0; } =20 @@ -432,6 +441,8 @@ static int multifd_send_pages(QEMUFile *f) ram_counters.multifd_bytes +=3D p->sent_bytes; qemu_file_acct_rate_limit(f, p->sent_bytes); p->sent_bytes =3D 0; + ram_counters.normal +=3D p->normal_num; + ram_counters.duplicate +=3D p->zero_num; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 @@ -545,6 +556,8 @@ void multifd_save_cleanup(void) p->iov =3D NULL; g_free(p->normal); p->normal =3D NULL; + g_free(p->zero); + p->zero =3D NULL; multifd_send_state->ops->send_cleanup(p, &local_err); if (local_err) { migrate_set_error(migrate_get_current(), local_err); @@ -666,6 +679,7 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(&p->mutex); =20 p->normal_num =3D 0; + p->zero_num =3D 0; =20 if (use_zero_copy_send) { p->iovs_num =3D 0; @@ -687,8 +701,8 @@ static void *multifd_send_thread(void *opaque) } multifd_send_fill_packet(p); =20 - 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_n= um, + p->flags, p->next_packet_size); =20 if (use_zero_copy_send) { /* Send header first, without zerocopy */ @@ -712,6 +726,7 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(&p->mutex); p->num_packets++; p->total_normal_pages +=3D p->normal_num; + p->total_zero_pages +=3D p->zero_num; p->pages->num =3D 0; p->pages->block =3D NULL; p->sent_bytes +=3D p->packet_len;; @@ -753,7 +768,8 @@ out: qemu_mutex_unlock(&p->mutex); =20 rcu_unregister_thread(); - trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_p= ages); + trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_p= ages, + p->total_zero_pages); =20 return NULL; } @@ -938,6 +954,7 @@ int multifd_save_setup(Error **errp) p->normal =3D g_new0(ram_addr_t, page_count); p->page_size =3D qemu_target_page_size(); p->page_count =3D page_count; + p->zero =3D g_new0(ram_addr_t, page_count); =20 if (migrate_use_zero_copy_send()) { p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; @@ -1046,6 +1063,8 @@ int multifd_load_cleanup(Error **errp) p->iov =3D NULL; g_free(p->normal); p->normal =3D NULL; + g_free(p->zero); + p->zero =3D 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; } =20 - 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_nu= m, + p->flags, p->next_packet_size); sync_needed =3D p->flags & MULTIFD_FLAG_SYNC; /* recv methods don't know how to handle the SYNC flag */ p->flags &=3D ~MULTIFD_FLAG_SYNC; p->num_packets++; p->total_normal_pages +=3D p->normal_num; + p->total_normal_pages +=3D p->zero_num; qemu_mutex_unlock(&p->mutex); =20 if (p->normal_num) { @@ -1147,7 +1167,8 @@ static void *multifd_recv_thread(void *opaque) qemu_mutex_unlock(&p->mutex); =20 rcu_unregister_thread(); - trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_p= ages); + trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_p= ages, + p->total_zero_pages); =20 return NULL; } @@ -1187,6 +1208,7 @@ int multifd_load_setup(Error **errp) p->normal =3D g_new0(ram_addr_t, page_count); p->page_count =3D page_count; p->page_size =3D qemu_target_page_size(); + p->zero =3D g_new0(ram_addr_t, page_count); } =20 for (i =3D 0; i < thread_count; i++) { diff --git a/migration/ram.c b/migration/ram.c index 291ba5c0ed..2af70f517a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1412,8 +1412,6 @@ static int ram_save_multifd_page(RAMState *rs, RAMBlo= ck *block, if (multifd_queue_page(rs->f, block, offset) < 0) { return -1; } - ram_counters.normal++; - return 1; } =20 diff --git a/migration/trace-events b/migration/trace-events index a34afe7b85..d34aec177c 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -120,21 +120,21 @@ postcopy_preempt_reset_channel(void) "" =20 # 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 flag= s, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " pages %u f= lags 0x%x next packet size %u" +multifd_recv(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t ze= ro, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PR= Iu64 " 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) "cha= nnel %u packets %" PRIu64 " pages %" PRIu64 +multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t normal_page= s, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRI= u64 " 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 fl= ags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal p= ages %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 packe= t_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_page= s) "channel %u packets %" PRIu64 " normal pages %" PRIu64 +multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_page= s, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PR= Iu64 " zero pages %" PRIu64 multifd_send_thread_start(uint8_t id) "%u" multifd_tls_outgoing_handshake_start(void *ioc, void *tioc, const char *ho= stname) "ioc=3D%p tioc=3D%p hostname=3D%s" multifd_tls_outgoing_handshake_error(void *ioc, const char *err) "ioc=3D%p= err=3D%s" --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659423906; cv=none; d=zohomail.com; s=zohoarc; b=DOScQlxrtgCCRBndt9ZgF7JbgLESa+rHW2IW6i0uHXLViZaar08IwL8j3FVTVNvn8xbsy5eA5XHw+YqtHyWpjeUA3/tK6WF0nsjREjZ4x2QLvCkO3Izz5kUkVeoMdLQGy711PEVKuDsxKyBxXGwGT+fAhDzMy0Ye8kAtYww8lm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659423906; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AqSKwBl1Lj03FgccrlDouwvURsMXTaeos2WOpfs/ILw=; b=WRh0Jz7l1rfE0hwCrog9+xEdKInSx50IgVnt78gZSC3OziO2YXCOMpuGtvxykjL4PwCn0cKCL3eE0KaNohaVA48EZa8q+QiraGN2+aGdmb9pVgaU9YlyCYcipK1EJwNXZFXX9Uewn30YqANTJCCid/GZBvYYyOcr4dN4L6b8TEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659423906681308.10429524647157; Tue, 2 Aug 2022 00:05:06 -0700 (PDT) Received: from localhost ([::1]:34178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIlxg-0007Fu-Fc for importer@patchew.org; Tue, 02 Aug 2022 03:05:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ5-0003yo-Hf for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ3-0006By-Qz for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:39 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-381-DKGpRXJiNSmrbI4Gq-AI4Q-1; Tue, 02 Aug 2022 02:39:34 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C45471C0BDFC; Tue, 2 Aug 2022 06:39:33 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0EFA492CA4; Tue, 2 Aug 2022 06:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AqSKwBl1Lj03FgccrlDouwvURsMXTaeos2WOpfs/ILw=; b=Qxh2ZOt9dYSZwmGFna2Zd5pVL7Nku7748eaM5+pG0+jDhCjC+mihjqSTFM5hnQOKL25zrw Djfz7EQ8dcV16GXLTyBB8xbP2UH0nANe/QHHv0xnqqPfSUvd6iXXpF/IrWwx6QLQ8Ej3Dz AL+dZRjNGjREKNrYA8hy4qdlIwLsOFg= X-MC-Unique: DKGpRXJiNSmrbI4Gq-AI4Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 11/12] multifd: Zero pages transmission Date: Tue, 2 Aug 2022 08:39:06 +0200 Message-Id: <20220802063907.18882-12-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659423908222100001 Content-Type: text/plain; charset="utf-8" This implements the zero page dection and handling. Signed-off-by: Juan Quintela --- 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 a1b852200d..5931de6f86 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; =20 diff --git a/migration/multifd.c b/migration/multifd.c index 4473d9f834..89811619d8 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -11,6 +11,7 @@ */ =20 #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) =20 packet->offset[i] =3D cpu_to_be64(temp); } + for (i =3D 0; i < p->zero_num; i++) { + /* there are architectures where ram_addr_t is 32 bit */ + uint64_t temp =3D p->zero[i]; + + packet->offset[p->normal_num + i] =3D cpu_to_be64(temp); + } } =20 static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) @@ -358,6 +365,18 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) p->normal[i] =3D offset; } =20 + for (i =3D 0; i < p->zero_num; i++) { + uint64_t offset =3D 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] =3D offset; + } + return 0; } =20 @@ -648,6 +667,8 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; + /* qemu older than 7.0 don't understand zero page on multifd channel */ + bool use_zero_page =3D migrate_use_multifd_zero_page(); int ret =3D 0; bool use_zero_copy_send =3D migrate_use_zero_copy_send(); =20 @@ -670,6 +691,7 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(&p->mutex); =20 if (p->pending_job) { + RAMBlock *rb =3D p->pages->block; uint64_t packet_num =3D p->packet_num; p->flags =3D 0; if (p->sync_needed) { @@ -688,8 +710,16 @@ static void *multifd_send_thread(void *opaque) } =20 for (int i =3D 0; i < p->pages->num; i++) { - p->normal[p->normal_num] =3D p->pages->offset[i]; - p->normal_num++; + uint64_t offset =3D p->pages->offset[i]; + if (use_zero_page && + buffer_is_zero(rb->host + offset, p->page_size)) { + p->zero[p->zero_num] =3D offset; + p->zero_num++; + ram_release_page(rb->idstr, offset); + } else { + p->normal[p->normal_num] =3D offset; + p->normal_num++; + } } =20 if (p->normal_num) { @@ -1152,6 +1182,13 @@ static void *multifd_recv_thread(void *opaque) } } =20 + for (int i =3D 0; i < p->zero_num; i++) { + void *page =3D 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); --=20 2.37.1 From nobody Wed May 8 12:28:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659424211; cv=none; d=zohomail.com; s=zohoarc; b=MaodyW6osZExgtLlrXWVHrgFgSGvqOCdIDrPcBxuF5c8VD9h7esYWgqi7ZQEtEQ2PkfTweOZbeg8EuJGPlbJcjZKgj1Bcajk2k7phM5tnCVWcBIKvUYHwpGsF2alq1XrTqa4Bfvxx+PXRB4pq6Djs1KEVgOjzO32J4o6FdIJE9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659424211; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HECFGisbQQcbT4PmmaGdUPkuChGDj0eKtg2geSd4FNc=; b=iVwRLlEQ3mljopTwlr9PDkYLiXlPDEuUtdvpUjEwyvLX955lha1HMTM5qEgh7vKRKUbu3LO5VMygcPpYw+25GUl/hTKSYoJTma57IboPy/PvFugiSAs8e7SRvxiVWNXLriJCsJV0418uZv4TBOFtB88P7Ib5taUb4r03Zr10U9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659424211603799.1405662990428; Tue, 2 Aug 2022 00:10:11 -0700 (PDT) Received: from localhost ([::1]:39096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIm2b-0002Z7-BO for importer@patchew.org; Tue, 02 Aug 2022 03:10:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ7-00043V-HC for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIlZ5-0006CC-RV for qemu-devel@nongnu.org; Tue, 02 Aug 2022 02:39:41 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-TxUv4O5wPWupoZK2IAxxkw-1; Tue, 02 Aug 2022 02:39:36 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E728C3803903; Tue, 2 Aug 2022 06:39:35 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14323492CA2; Tue, 2 Aug 2022 06:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659422379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HECFGisbQQcbT4PmmaGdUPkuChGDj0eKtg2geSd4FNc=; b=WVdoSWfXgx/3uwmTnW8JwGSZ+sEBULhJdHffzcws4YD9pPMSG3kg1V+VVTQFPA9vzq6B50 KQY7U46R86UEFaegkX6KVaGoUOV4tA0GjCGJ69HKX5IuYbnGPDGPW/LZwMQ/D1V1wm1jbu /6CX28Q21PJH1yu1A+IQ/b6XLdI8fTI= X-MC-Unique: TxUv4O5wPWupoZK2IAxxkw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Dr. David Alan Gilbert" , Leonardo Bras , Peter Xu , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Markus Armbruster , Eduardo Habkost Subject: [PATCH v7 12/12] So we use multifd to transmit zero pages. Date: Tue, 2 Aug 2022 08:39:07 +0200 Message-Id: <20220802063907.18882-13-quintela@redhat.com> In-Reply-To: <20220802063907.18882-1-quintela@redhat.com> References: <20220802063907.18882-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659424212877100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- - Check zero_page property before using new code (Dave) --- migration/migration.c | 4 +--- migration/multifd.c | 6 +++--- migration/ram.c | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index ce3e5cc0cd..13842f6803 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2599,9 +2599,7 @@ bool migrate_use_main_zero_page(void) =20 s =3D migrate_get_current(); =20 - // We will enable this when we add the right code. - // return s->enabled_capabilities[MIGRATION_CAPABILITY_MAIN_ZERO_PAGE]; - return true; + return s->enabled_capabilities[MIGRATION_CAPABILITY_MAIN_ZERO_PAGE]; } =20 bool migrate_pause_before_switchover(void) diff --git a/migration/multifd.c b/migration/multifd.c index 89811619d8..54acdc004c 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -667,8 +667,8 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; - /* qemu older than 7.0 don't understand zero page on multifd channel */ - bool use_zero_page =3D migrate_use_multifd_zero_page(); + /* older qemu don't understand zero page on multifd channel */ + bool use_multifd_zero_page =3D !migrate_use_main_zero_page(); int ret =3D 0; bool use_zero_copy_send =3D migrate_use_zero_copy_send(); =20 @@ -711,7 +711,7 @@ static void *multifd_send_thread(void *opaque) =20 for (int i =3D 0; i < p->pages->num; i++) { uint64_t offset =3D p->pages->offset[i]; - if (use_zero_page && + if (use_multifd_zero_page && buffer_is_zero(rb->host + offset, p->page_size)) { p->zero[p->zero_num] =3D offset; p->zero_num++; diff --git a/migration/ram.c b/migration/ram.c index 2af70f517a..26e60b9cc1 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2428,6 +2428,32 @@ static void postcopy_preempt_reset_channel(RAMState = *rs) } } =20 +/** + * 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 *ps= s) +{ + RAMBlock *block =3D pss->block; + ram_addr_t offset =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; + int res; + + if (!migration_in_postcopy()) { + return ram_save_multifd_page(rs, block, offset); + } + + res =3D 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 * @@ -3225,7 +3251,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); =20 - (*rsp)->ram_save_target_page =3D ram_save_target_page_legacy; + if (migrate_use_multifd() && !migrate_use_main_zero_page()) { + (*rsp)->ram_save_target_page =3D ram_save_target_page_multifd; + } else { + (*rsp)->ram_save_target_page =3D ram_save_target_page_legacy; + } + ret =3D multifd_send_sync_main(f); if (ret < 0) { return ret; --=20 2.37.1