From nobody Fri May 10 16:01:01 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 1669040522928281.56360686727976; Mon, 21 Nov 2022 06:22:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rs-0001Pf-0b; Mon, 21 Nov 2022 08:29:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rI-0000hq-GO for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004nx-IY for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:09 -0500 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-510-hSPBH_rMPeyTNigPog3tyA-1; Mon, 21 Nov 2022 08:27:28 -0500 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 AE05C296A612; Mon, 21 Nov 2022 13:27:27 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8789C4B3FC6; Mon, 21 Nov 2022 13:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037252; 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=UZm70PSygUPn7UXNAT5LnhWWt6V/uNbWzHaNnNPhKro=; b=Eznww+/aWI5xthSpfEPJFkgwwm97K4YZpTkVnQTeeo9f18h9ZP1mt/ol+anF7oObrdcPDn 9E8mGuL9UaMrmdOfrdzlJrRP/OedcfKtgqCfOO4p5T6vSKtw0Q4lFuzpc+qsC4D1qTkFX4 DJJhtMDXmi3egxvuvqxF3sfRfO/Uw9U= X-MC-Unique: hSPBH_rMPeyTNigPog3tyA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier , Leonardo Bras Subject: [PATCH 01/19] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Date: Mon, 21 Nov 2022 14:26:59 +0100 Message-Id: <20221121132717.63070-2-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1669040525090100003 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 509bbbe3bf..efffa77a76 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; @@ -947,6 +943,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; @@ -1194,6 +1191,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.38.1 From nobody Fri May 10 16:01:01 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 1669037603188504.2688092922193; Mon, 21 Nov 2022 05:33:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rr-0001PK-O6; Mon, 21 Nov 2022 08:29:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rF-0000fK-Jj for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004o1-F1 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:28:56 -0500 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-630-4Mb44RdJOeCemK8Lsg1dtg-1; Mon, 21 Nov 2022 08:27:31 -0500 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 BEE391C0758C; Mon, 21 Nov 2022 13:27:30 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0040B4B3FC6; Mon, 21 Nov 2022 13:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037252; 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=9tm0aYZytXya9yAOHxEbm0Rd0xivxdFo7KkNO5L47xU=; b=Bxw1rIoXn8B8dHJRPaHF1gZXaGF3kcPtiKY5nBR7+DaxwcEw7fqNee3gvebQSjFjX7yoq6 xhmQhaiD/Hlpc8FJZ5hss7b0M3AYEeB/e31A8+kNA+KGGEVzm2XDmzZnRRbkaN+frqcdas tU9FfsZryYnQPIU8DYf3PJVCjmcsELk= X-MC-Unique: 4Mb44RdJOeCemK8Lsg1dtg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier , Leonardo Bras Subject: [PATCH 02/19] multifd: Create page_count fields into both MultiFD{Recv, Send}Params Date: Mon, 21 Nov 2022 14:27:00 +0100 Message-Id: <20221121132717.63070-3-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1669037603945100001 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 efffa77a76..b8dc559d24 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 @@ -944,6 +943,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; @@ -1191,6 +1191,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.38.1 From nobody Fri May 10 16:01:01 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=1669037693; cv=none; d=zohomail.com; s=zohoarc; b=m37X9wJ285z0FPENn3yN84CFmiWJMz26n3ZOmVqqnOR6RnWggqVR1QQBInkCjpNnMxPJvGvp18AQ7BiOTnOkudzLvoc1QDE041N20SsjhChvn8rg66dstUwt8etkrlbN7MKWTb4oQZy3TEl9/NbeUx4Etv3mHtLxMpnhxMuv99A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669037693; 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=wht3cZbEag0AF4cSKduIqGDfC02z0cnt1HmfpmfZWO0=; b=UnrogNr3F4eDKrWqVCxIlKnI1SjpIcWurYnWt0eOrmqiSGHbVENtnu7pAhmx4UqVajAf/FljUNqSsRaszNlT85127Omf4ZuhHajmbUU3OeF+clKzBbOkG1+yY7aKx5s6NH69PsuaoLrHsxZOdDhO9mCklZYco8ttW5tz2+wIOLU= 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 1669037693155250.44352804072219; Mon, 21 Nov 2022 05:34:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rr-0001LP-6X; Mon, 21 Nov 2022 08:29:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rM-0000jL-6z for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qZ-0004oT-R3 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:14 -0500 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-518-qWVZhZEmPgmAKYlfSQ0eaA-1; Mon, 21 Nov 2022 08:27:34 -0500 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 05CE3811E67; Mon, 21 Nov 2022 13:27:34 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15FCC4B3FC6; Mon, 21 Nov 2022 13:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037258; 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=wht3cZbEag0AF4cSKduIqGDfC02z0cnt1HmfpmfZWO0=; b=FboxHC3tTTS0mm/yyNEPmUnxW8R7lmkRUDiKoisj8y0XQYi1LH1tWBvf7XPVjiRvHEKOqp Hi6gCQmR5Mq9EaV3mJeQcVaq99ZwdLlkEv54ykRMpyQX20fE73R+6exJ7y+8nMD9cDwhyj cBVvHhBgMB4v3eNlFEV+v2ZH33Ev7CI= X-MC-Unique: qWVZhZEmPgmAKYlfSQ0eaA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier , David Edmondson , Leonardo Bras Subject: [PATCH 03/19] migration: Export ram_transferred_ram() Date: Mon, 21 Nov 2022 14:27:01 +0100 Message-Id: <20221121132717.63070-4-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669037694232100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson 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 1338e47665..2cbe707bfc 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.38.1 From nobody Fri May 10 16:01:01 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=1669037374; cv=none; d=zohomail.com; s=zohoarc; b=D2Zw0XC8Ika8vkHZw6Mm8xdwmIYFu3lW2vwaKpYxBGHNSltvzXpAIBCEVhynAYWWaTj2Drox6JKlaqYc04niRzXPZn/M8RWLf8x94zJGccvDg+8AxGqBJg9/eyQqbgjg1CscOwK6I3YcV+1liL3pO2K5YSYvs4ewJZPUXSkT8v8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669037374; 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=82n06ypGY49Plz4M2tcMx6flFk5mja5S3ptKNYMoHNk=; b=ikd9eRNqmK2g2FiCnIPWtvm+2rO4dWWaS99GQ+xs+3tXPxJvVzCNKKVzIv+V80weuTOezzvju2eojDoSD++NyHZdU1Jpw+QcB7zzfrOY8CCpNpo1b9PZkozs0wmacCImZh8WhbGlCUlY9OWcQZhVUFTnB/ASjuQnxdL7HCT/neo= 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 1669037374432678.036635045353; Mon, 21 Nov 2022 05:29:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rH-0000da-G9; Mon, 21 Nov 2022 08:29:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qX-0000PV-0R for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:28:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6py-0004og-Jq for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:28:04 -0500 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-77-_tyt2sCmPPmgn2blQFtoWg-1; Mon, 21 Nov 2022 08:27:37 -0500 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 0F700101A52A; Mon, 21 Nov 2022 13:27:37 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AFCF4B3FC6; Mon, 21 Nov 2022 13:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037260; 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=82n06ypGY49Plz4M2tcMx6flFk5mja5S3ptKNYMoHNk=; b=gI/n7I4r1KXSO/AWI9cCTPlgzpHvZ8dc2LWsnZRsoYKCquHJjXio4SQE7i65alEAioIqxf YQemIpQlNdWNWClAu7vLt+f+BLGoWDZpww5mBW7OsHj1XVoyBhVkElZ+Eg02VOTLUlaUOE UGTZ5t/UPQXceHu+GyWbFYNbsyC0FVQ= X-MC-Unique: _tyt2sCmPPmgn2blQFtoWg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier , Leonardo Bras Subject: [PATCH 04/19] migration: Export ram_release_page() Date: Mon, 21 Nov 2022 14:27:02 +0100 Message-Id: <20221121132717.63070-5-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669037375817100001 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 2cbe707bfc..8aad17c429 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1234,7 +1234,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.38.1 From nobody Fri May 10 16:01:01 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=1669039000; cv=none; d=zohomail.com; s=zohoarc; b=B0BkTmmUVNEyd95p/lRwFKzwoNPgLDSQaYSBLEJcUyaN5ofiuRdAy+kx6S5sJuQG4iScB9PDlJFinRpi4LwmjZ+DrT+AzutAc2WxvShQm7RysvW69p4Ass0tJZWAjh+tpfbQLjKZFNgYj1VRVRijt1EdgRJY2tqCzySFQ392JKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669039000; 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=mwG7VmeQ4OSrYdmnU8HIXq4U+zlJC1ZXAM3D1p/Nf8Q=; b=Q/kfoMYILk8cZm21ppboq0qbbeddMaArnRmFaxtmRXDjda0KRmOuQhtUqAT84D5XBui6POI28z9GhLJL12KI5rNiGJvtf9zVew1GVQtEKYKVT8MZANV/zNX3x56fm0Bwb/jQf+MdKrtDcJXVBZDqNwW3OeLKxuk3S5NJjA6Di3o= 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 1669039000839305.123139165825; Mon, 21 Nov 2022 05:56:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rY-0000yj-R3; Mon, 21 Nov 2022 08:29:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rK-0000hx-4k for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004qD-KY for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:12 -0500 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-138-VUpRjAEiNYeajmOJ_9y2_A-1; Mon, 21 Nov 2022 08:27:40 -0500 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 F3B00185A79C; Mon, 21 Nov 2022 13:27:39 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54D504B3FC6; Mon, 21 Nov 2022 13:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037264; 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=mwG7VmeQ4OSrYdmnU8HIXq4U+zlJC1ZXAM3D1p/Nf8Q=; b=cy8vIWElo5CB7TrncZIF3D5WGafzdZoCz2ieKwKNmZ5zIuqjLmZNz2FUIXvqwp7+57fdoT TTxlN/VN16rz7JDCmU9MU4OFqW/rEIXkUYqL1WQUu3CmzVVtjFe8LZkgVEFlnIfkcvcwoA MSZCyaRYeA7NBXkeEcuZpATJu8+b8oY= X-MC-Unique: VUpRjAEiNYeajmOJ_9y2_A-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 05/19] migration: Take bitmap mutex when completing ram migration Date: Mon, 21 Nov 2022 14:27:03 +0100 Message-Id: <20221121132717.63070-6-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669039001750100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Any call to ram_find_and_save_block() needs to take the bitmap mutex. We used to not take it for most of ram_save_complete() because we thought we're the only one left using the bitmap, but it's not true after the preempt full patchset applied, since the return path can be taking it too. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 8aad17c429..cc72c24c18 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3406,6 +3406,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) /* try transferring iterative blocks of memory */ =20 /* flush all remaining blocks regardless of rate limiting */ + qemu_mutex_lock(&rs->bitmap_mutex); while (true) { int pages; =20 @@ -3419,6 +3420,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) break; } } + qemu_mutex_unlock(&rs->bitmap_mutex); =20 flush_compressed_data(rs); ram_control_after_iterate(f, RAM_CONTROL_FINISH); --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669039820; cv=none; d=zohomail.com; s=zohoarc; b=l/TFOFSsqtFCwZ7NrCJKZSrrW93SFAEIRQKn9yNwS6Dt5HvV/YtFdTYplYBzTuedqF8f8dQQEb5dI6AIY8FnbEJ/8l5WxkXiiTV/H6/n73BqZB3ruTQlDx49h3lCLRtDaoVoIFCiwzs3wXJOnRz2hGEE9o8JVXS1NKb7hl5/UyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669039820; 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=Y2FikQbfX3Vpm8/roYrQu/IEscu7tBjOtyBOMBEKAZ8=; b=T4O9OvIMXqde5Twu1E+8WITpQeuJEvFARSUXYVe0aUau/Oqrk0aa24j9usq67+IVlYIjguId4Lg06P19Zllqehkcswna6tADWo3kSeovqfaiK7HJi7F73wOh2Uq156FBs3PcTshgjawZsF365C9viExcDAOiaQ6tlllgJpMYxtc= 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 1669039820317306.0258888071255; Mon, 21 Nov 2022 06:10:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rt-0001SB-OQ; Mon, 21 Nov 2022 08:29:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rP-0000oW-3f for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qZ-0004qP-R8 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:18 -0500 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-553-zLQRU9G-NnGa43k65L3VAw-1; Mon, 21 Nov 2022 08:27:43 -0500 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 D701785A5A6; Mon, 21 Nov 2022 13:27:42 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46F7E4B3FC6; Mon, 21 Nov 2022 13:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037266; 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=Y2FikQbfX3Vpm8/roYrQu/IEscu7tBjOtyBOMBEKAZ8=; b=ANt3AKEzEwHUgE9c48b4+RoMLz13lONPNltd3zpod4C1W08T1BUpAs3/0Wi8dGBV26dzpA AuoGl5mty9I809mkYngGD2OjUpWED+ggefzjqVustvJ0nINtnhxjvxgDmB3Z5BTtKU1b/Q 2MbYXVpe1HhjPjjbHEx81DCzz8Jx7GY= X-MC-Unique: zLQRU9G-NnGa43k65L3VAw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 06/19] migration: Add postcopy_preempt_active() Date: Mon, 21 Nov 2022 14:27:04 +0100 Message-Id: <20221121132717.63070-7-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669039821486100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Add the helper to show that postcopy preempt enabled, meanwhile active. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index cc72c24c18..00a2e30322 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -162,6 +162,11 @@ out: return ret; } =20 +static bool postcopy_preempt_active(void) +{ + return migrate_postcopy_preempt() && migration_in_postcopy(); +} + bool ramblock_is_ignored(RAMBlock *block) { return !qemu_ram_is_migratable(block) || @@ -2433,7 +2438,7 @@ static void postcopy_preempt_choose_channel(RAMState = *rs, PageSearchStatus *pss) /* We need to make sure rs->f always points to the default channel elsewhe= re */ static void postcopy_preempt_reset_channel(RAMState *rs) { - if (migrate_postcopy_preempt() && migration_in_postcopy()) { + if (postcopy_preempt_active()) { rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; rs->f =3D migrate_get_current()->to_dst_file; trace_postcopy_preempt_reset_channel(); @@ -2471,7 +2476,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) return 0; } =20 - if (migrate_postcopy_preempt() && migration_in_postcopy()) { + if (postcopy_preempt_active()) { postcopy_preempt_choose_channel(rs, pss); } =20 --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669037481; cv=none; d=zohomail.com; s=zohoarc; b=I4fMv+ZoChv9YmMi9Nc7ngVcQJ1YCldLH/pJJlRCnxpoc1vp0exeLprdfKYXhK+bnzazDZDfyPRE5Sd8CkziMzly215mzac5j3pW4HSEOzYpTARPWJbQO/80dJPHHweHSZjPUg3arcojojQd6O2G84vJrYq+I0FuTlULfVYjVOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669037481; 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=8T5xObxYus8mUaDCig1/nmq01TyjcG4leYqxs3OOcvM=; b=cMaAR+rlG7Db5F+w1A016X//kvikJthHNRIfmqh/8GC+uICRrVZMyfNSwb58Oy93t/kI4QS/9xj9g09ysz5e7E1N5X3jSpFeFGsqylyMz9yxJWVUKfq9I/8w0QJNhyLWiuJkK+BWFNau8dzELUJRQ7qf0MgLQ7Nsm/I5nFHqVJ8= 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 1669037481136261.16440872025714; Mon, 21 Nov 2022 05:31:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rR-0000sp-MV; Mon, 21 Nov 2022 08:29:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rK-0000hz-5J for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004qx-L1 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:12 -0500 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-139-ymC-DYilM4K2SxxAxN564Q-1; Mon, 21 Nov 2022 08:27:46 -0500 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 C7A942A2AD78; Mon, 21 Nov 2022 13:27:45 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 293D44B3FC6; Mon, 21 Nov 2022 13:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037270; 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=8T5xObxYus8mUaDCig1/nmq01TyjcG4leYqxs3OOcvM=; b=Eok6+095H98Xs/qv8kDSzcTksoe0ylYBWE5cNcPksdk0wyt4dcXhhiyxk4W1eP82yuu+2Z d2BmHlra3tLt6v6URGTMe0OKQp0vKjlOBX6A4y2+P1R8PXZk1Rp3+SmGZptZJhxNHZhngj Jium+ZYpCfi1iLPWI+DP2eyPfsNBWIE= X-MC-Unique: ymC-DYilM4K2SxxAxN564Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 07/19] migration: Cleanup xbzrle zero page cache update logic Date: Mon, 21 Nov 2022 14:27:05 +0100 Message-Id: <20221121132717.63070-8-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669037483014100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu The major change is to replace "!save_page_use_compression()" with "xbzrle_enabled" to make it clear. Reasonings: (1) When compression enabled, "!save_page_use_compression()" is exactly the same as checking "xbzrle_enabled". (2) When compression disabled, "!save_page_use_compression()" always return true. We used to try calling the xbzrle code, but after this change we won't, and we shouldn't need to. Since at it, drop the xbzrle_enabled check in xbzrle_cache_zero_page() because with this change it's not needed anymore. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 00a2e30322..7124ff531c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -741,10 +741,6 @@ void mig_throttle_counter_reset(void) */ static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr) { - if (!rs->xbzrle_enabled) { - return; - } - /* We don't care if this fails to allocate a new cache page * as long as it updated an old one */ cache_insert(XBZRLE.cache, current_addr, XBZRLE.zero_target_page, @@ -2301,7 +2297,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale */ - if (!save_page_use_compression(rs)) { + if (rs->xbzrle_enabled) { XBZRLE_cache_lock(); xbzrle_cache_zero_page(rs, block->offset + offset); XBZRLE_cache_unlock(); --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669038792; cv=none; d=zohomail.com; s=zohoarc; b=E2/b9peDv6UPKlFh3AJZnkltlDSTYWLs+33D6UZ0s1LJf+dRXAFldikmAM/5Et+BZmBE0jnMSYJKmCFFF4ISDL0nnXgGjtGpmsjItvCWQZIWlZ3RSZFAxzzcJU7D0NEOJF6X6J9P71OBj/tsvK/J1VNWPl52yK1WbWcvS25LA3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669038792; 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=H71cToLy64HTbBPdrL5diYAVzVjBcZDaRr6Ge6ZYDPU=; b=AlKfY144o7tk7DMRasux5CZyR2r5USdAJaqcfN5ICfRZxQITr6CqoexNg9CgS8FRjItC9SyUedOw7y5hHRCCN2/nAaWcT2yOwVfMJmDBFedLziFGRKYZWhFLqpBzdmXH6yMkJYIs0yv9LAwJxWxcoYV8Vp2vu6A6l3F7885W1+E= 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 166903879267914.693537837998974; Mon, 21 Nov 2022 05:53:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rP-0000qa-Uh; Mon, 21 Nov 2022 08:29:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qa-0000Q7-8G for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:28:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qT-0004rE-BR for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:28:27 -0500 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-67-BOJCIdrgOfS4aGJpXtcMvA-1; Mon, 21 Nov 2022 08:27:49 -0500 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 B067D101A52A; Mon, 21 Nov 2022 13:27:48 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C5A04B3FC6; Mon, 21 Nov 2022 13:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037273; 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=H71cToLy64HTbBPdrL5diYAVzVjBcZDaRr6Ge6ZYDPU=; b=YIbcKoXt8lcwMgjcNiyKXNX+x4V57U28BkpxIOJhN52UydgAtV7AjjGrRjbBMXxmyOkT+9 jwf4KYAUSWdh3RGIB9EzyesBzkA1RM20cK1HhF4OLJtRr/6dJsjRaFkWdyIe7yvZO/sIPk XifS/qTnrIufb/oppWMHdkX7CG0DDHM= X-MC-Unique: BOJCIdrgOfS4aGJpXtcMvA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 08/19] migration: Trivial cleanup save_page_header() on same block check Date: Mon, 21 Nov 2022 14:27:06 +0100 Message-Id: <20221121132717.63070-9-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669038793282100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu The 2nd check on RAM_SAVE_FLAG_CONTINUE is a bit redundant. Use a boolean to be clearer. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 7124ff531c..41475431fc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -661,14 +661,15 @@ static size_t save_page_header(RAMState *rs, QEMUFile= *f, RAMBlock *block, ram_addr_t offset) { size_t size, len; + bool same_block =3D (block =3D=3D rs->last_sent_block); =20 - if (block =3D=3D rs->last_sent_block) { + if (same_block) { offset |=3D RAM_SAVE_FLAG_CONTINUE; } qemu_put_be64(f, offset); size =3D 8; =20 - if (!(offset & RAM_SAVE_FLAG_CONTINUE)) { + if (!same_block) { len =3D strlen(block->idstr); qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)block->idstr, len); --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669040363; cv=none; d=zohomail.com; s=zohoarc; b=hM9wir9H7ZjmmqVoUufnFyrdXUB2Ft56NhvY2jn+uEM1A9u8F8JuyOOb6N0D2a1t8n5swttD97Of5Oi9ldLXVVSL7zcVNwv27Mk4XZIsmxzfKyhzjLzX41ZXf9/g1TGZAkeiFpB03HfP8s8jGRfEoYNxzr0BFGOyIhwsWIJoyPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669040363; 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=MyOOzG/IByBPCSi/RuF6EO6mdBGoKRDsMNpVGRjYHyo=; b=bLl+us1SXaURo1RvaCReWfwDMuE9OFfCIXRPCRKWN1i4X8RV63y5+ApentAH2G4xqPQze45L3ohpJLZPgVTQQxr2yPtgSoHPmdAiqM6a2YTfnYerD+Rk/GDNCZN72Sm8n1I4RBzu42RmSrr5t4yhRrxLgK+Uas2mO5xgTxii8Q8= 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 1669040363760978.6257296461333; Mon, 21 Nov 2022 06:19:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rs-0001R5-Sg; Mon, 21 Nov 2022 08:29:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rI-0000hn-FC for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004rN-KW for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:11 -0500 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-73-yDdLt79HP0ir__7HPJghgA-1; Mon, 21 Nov 2022 08:27:52 -0500 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 943F3802C16; Mon, 21 Nov 2022 13:27:51 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 033604B3FC6; Mon, 21 Nov 2022 13:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037273; 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=MyOOzG/IByBPCSi/RuF6EO6mdBGoKRDsMNpVGRjYHyo=; b=PxZeAZEDO9iD/H+KbfEZ9EwQuvPt1YeAqLuaY6ouOiBo/kV1ACRN8UGJp4ECr5hZ8pVP9p lq2yTqnvEUOZxASKrU2BYr+eBoFftc0XHpapPD9J0HSLZTqqF0+anU4kdcXBigKxRSFTJY DP+lx+HBgNoclJFp5CG2nTPbbVYQzPQ= X-MC-Unique: yDdLt79HP0ir__7HPJghgA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 09/19] migration: Remove RAMState.f references in compression code Date: Mon, 21 Nov 2022 14:27:07 +0100 Message-Id: <20221121132717.63070-10-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669040365630100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Removing referencing to RAMState.f in compress_page_with_multi_thread() and flush_compressed_data(). Compression code by default isn't compatible with having >1 channels (or it won't currently know which channel to flush the compressed data), so to make it simple we always flush on the default to_dst_file port until someone wants to add >1 ports support, as rs->f right now can really change (after postcopy preempt is introduced). There should be no functional change at all after patch applied, since as long as rs->f referenced in compression code, it must be to_dst_file. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Signed-off-by: Juan Quintela --- migration/ram.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 41475431fc..6e3dc845c5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1461,6 +1461,7 @@ static bool save_page_use_compression(RAMState *rs); =20 static void flush_compressed_data(RAMState *rs) { + MigrationState *ms =3D migrate_get_current(); int idx, len, thread_count; =20 if (!save_page_use_compression(rs)) { @@ -1479,7 +1480,7 @@ static void flush_compressed_data(RAMState *rs) for (idx =3D 0; idx < thread_count; idx++) { qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { - len =3D qemu_put_qemu_file(rs->f, comp_param[idx].file); + len =3D qemu_put_qemu_file(ms->to_dst_file, comp_param[idx].fi= le); /* * it's safe to fetch zero_page without holding comp_done_lock * as there is no further request submitted to the thread, @@ -1498,11 +1499,11 @@ static inline void set_compress_params(CompressPara= m *param, RAMBlock *block, param->offset =3D offset; } =20 -static int compress_page_with_multi_thread(RAMState *rs, RAMBlock *block, - ram_addr_t offset) +static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t off= set) { int idx, thread_count, bytes_xmit =3D -1, pages =3D -1; bool wait =3D migrate_compress_wait_thread(); + MigrationState *ms =3D migrate_get_current(); =20 thread_count =3D migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); @@ -1510,7 +1511,8 @@ retry: for (idx =3D 0; idx < thread_count; idx++) { if (comp_param[idx].done) { comp_param[idx].done =3D false; - bytes_xmit =3D qemu_put_qemu_file(rs->f, comp_param[idx].file); + bytes_xmit =3D qemu_put_qemu_file(ms->to_dst_file, + comp_param[idx].file); qemu_mutex_lock(&comp_param[idx].mutex); set_compress_params(&comp_param[idx], block, offset); qemu_cond_signal(&comp_param[idx].cond); @@ -2263,7 +2265,7 @@ static bool save_compress_page(RAMState *rs, RAMBlock= *block, ram_addr_t offset) return false; } =20 - if (compress_page_with_multi_thread(rs, block, offset) > 0) { + if (compress_page_with_multi_thread(block, offset) > 0) { return true; } =20 --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669039035; cv=none; d=zohomail.com; s=zohoarc; b=l4WketDMDbFOo96ToozMmL1o1HJyVG4m3j3WIh9eLiAwxCiZ+IuHhDl2nBg1UDkd254nEVQD4bLAlfxxkmAi3PrI+56m+LzRezAyFODdNHEoleGsIsEw3umkmBmpQXXYeGouHrwHOb/1Rxe1WFxlFq/5VU8Yxvo77v2cUQf/UNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669039035; 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=30+Kq9dPR7peGz5envehc+sa5UbYD15LI+w9Psis5To=; b=oL9RARgDN4lLqW+30EquczRhqtbNXkQqZVHpEE2G+N++6gX8ru6MCoetTaw6aDSFXzDRw0lqM0blOeoIUMgrhVVcYM0it0F3tXx4Nf+bYI2eZXJGrwYTfjweqnO2ckvagK+vw6l1GZuVeA+KK98SJU3/XguKLMvGw00AnPqAYBY= 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 1669039035171909.6007954368757; Mon, 21 Nov 2022 05:57:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rq-0001KS-6o; Mon, 21 Nov 2022 08:29:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rP-0000oj-4Q for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qZ-0004t0-R5 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:18 -0500 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-225-vKpOes1nOiaHxTFnrI2G3Q-1; Mon, 21 Nov 2022 08:27:55 -0500 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 999A8811E81; Mon, 21 Nov 2022 13:27:54 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id D98064B3FC6; Mon, 21 Nov 2022 13:27:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037279; 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=30+Kq9dPR7peGz5envehc+sa5UbYD15LI+w9Psis5To=; b=BUpJCatNLV/JWoqO3kHGfGpPPg8bqpU2I9e9JgWQXI7VzsnGnM2tauc5SViVFlMPzFqsmo aJ5UOeQAVmQfiHjesZ+7nCogtr2cAVpPVSiLgerm6H4kXJ0dOEmhGKYwxPsE2aOpwBejfx OCNCDn8/g6zOlWdZE95MdPrIvyRL+U8= X-MC-Unique: vKpOes1nOiaHxTFnrI2G3Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 10/19] migration: Yield bitmap_mutex properly when sending/sleeping Date: Mon, 21 Nov 2022 14:27:08 +0100 Message-Id: <20221121132717.63070-11-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669039036156100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Don't take the bitmap mutex when sending pages, or when being throttled by migration_rate_limit() (which is a bit tricky to call it here in ram code, but seems still helpful). It prepares for the possibility of concurrently sending pages in >1 threads using the function ram_save_host_page() because all threads may need the bitmap_mutex to operate on bitmaps, so that either sendmsg() or any kind of qemu_sem_wait() blocking for one thread will not block the other from progressing. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 6e3dc845c5..5379164749 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2452,9 +2452,14 @@ static void postcopy_preempt_reset_channel(RAMState = *rs) * a host page in which case the remainder of the hostpage is sent. * Only dirty target pages are sent. Note that the host page size may * be a huge page for this block. + * * The saving stops at the boundary of the used_length of the block * if the RAMBlock isn't a multiple of the host page size. * + * The caller must be with ram_state.bitmap_mutex held to call this + * function. Note that this function can temporarily release the lock, but + * when the function is returned it'll make sure the lock is still held. + * * Returns the number of pages written or negative on error * * @rs: current RAM state @@ -2462,6 +2467,7 @@ static void postcopy_preempt_reset_channel(RAMState *= rs) */ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) { + bool page_dirty, preempt_active =3D postcopy_preempt_active(); int tmppages, pages =3D 0; size_t pagesize_bits =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; @@ -2485,22 +2491,40 @@ static int ram_save_host_page(RAMState *rs, PageSea= rchStatus *pss) break; } =20 + page_dirty =3D migration_bitmap_clear_dirty(rs, pss->block, pss->p= age); + /* Check the pages is dirty and if it is send it */ - if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { + if (page_dirty) { + /* + * Properly yield the lock only in postcopy preempt mode + * because both migration thread and rp-return thread can + * operate on the bitmaps. + */ + if (preempt_active) { + qemu_mutex_unlock(&rs->bitmap_mutex); + } tmppages =3D ram_save_target_page(rs, pss); - if (tmppages < 0) { - return tmppages; + if (tmppages >=3D 0) { + pages +=3D tmppages; + /* + * Allow rate limiting to happen in the middle of huge pag= es if + * something is sent in the current iteration. + */ + if (pagesize_bits > 1 && tmppages > 0) { + migration_rate_limit(); + } } - - pages +=3D tmppages; - /* - * Allow rate limiting to happen in the middle of huge pages if - * something is sent in the current iteration. - */ - if (pagesize_bits > 1 && tmppages > 0) { - migration_rate_limit(); + if (preempt_active) { + qemu_mutex_lock(&rs->bitmap_mutex); } + } else { + tmppages =3D 0; + } + + if (tmppages < 0) { + return tmppages; } + pss->page =3D migration_bitmap_find_dirty(rs, pss->block, pss->pag= e); } while ((pss->page < hostpage_boundary) && offset_in_ramblock(pss->block, --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669041767; cv=none; d=zohomail.com; s=zohoarc; b=exxDAT58D3wjolORPqTtBsVLju63NCXMFpvNtsUJz/XgVkJgqrpVdLQ3X2XjcF6IUElKfmGW2I3gUi9qmIN9pv7ydhNgpE38vIB3tY0IhiwptqrK1sCvsHaTY0TZ+myMc6fZzZ3fsNKnh6kWMlpeXV/qiy+4AbFI7GBJd2j2SQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669041767; 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=KjyAtJBI1Le1Avp7uOYNzGtZI6T2gunZpw5nO71qFnU=; b=R64tn2TJw5nPoQBIe5Sikh1Fi+K7kW6CGQWY3I7papRSDthRoe7Sbw4ukQ9MjoMWPypuqprkIEIh5b1hUfA4QCfaYC6fCDZ1KClH2xr4MuWmVO/8/tcj1IXLr+U7iUuKBVAozfiGI6gnsLeJKBdBpYmLAt6Q0X16lnGI540MmxI= 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 1669041767691801.0814819499161; Mon, 21 Nov 2022 06:42:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6ru-0001T5-3r; Mon, 21 Nov 2022 08:29:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rM-0000jM-77 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004ur-3Y for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:13 -0500 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-359-aAEuxA8dORWdpFacEwmF8Q-1; Mon, 21 Nov 2022 08:27:58 -0500 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 A71FA85A5A6; Mon, 21 Nov 2022 13:27:57 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id E56124B3FC6; Mon, 21 Nov 2022 13:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037281; 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=KjyAtJBI1Le1Avp7uOYNzGtZI6T2gunZpw5nO71qFnU=; b=TIPbswuh6UScmMWFe9Pgwm9sqEc8SiKRWXoPLy++bsjZd1xk//WNSiAYGcV7Wn2UqC60bW rsO0JMwqdeIOga2IRRLWqTAlemsA5VTYFzpb5zXrBZKMH06lwwr8GKhsBbb30VV+XAjESc 3qyOzhwrA0eZR3TKMEYi18HrIQY3r+Q= X-MC-Unique: aAEuxA8dORWdpFacEwmF8Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 11/19] migration: Use atomic ops properly for page accountings Date: Mon, 21 Nov 2022 14:27:09 +0100 Message-Id: <20221121132717.63070-12-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669041770798100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu To prepare for thread-safety on page accountings, at least below counters need to be accessed only atomically, they are: ram_counters.transferred ram_counters.duplicate ram_counters.normal ram_counters.postcopy_bytes There are a lot of other counters but they won't be accessed outside migration thread, then they're still safe to be accessed without atomic ops. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.h | 20 ++++++++++++++++++++ migration/migration.c | 10 +++++----- migration/multifd.c | 4 ++-- migration/ram.c | 40 ++++++++++++++++++++++++---------------- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/migration/ram.h b/migration/ram.h index 038d52f49f..81cbb0947c 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -32,7 +32,27 @@ #include "qapi/qapi-types-migration.h" #include "exec/cpu-common.h" #include "io/channel.h" +#include "qemu/stats64.h" =20 +/* + * These are the migration statistic counters that need to be updated using + * atomic ops (can be accessed by more than one thread). Here since we + * cannot modify MigrationStats directly to use Stat64 as it was defined in + * the QAPI scheme, we define an internal structure to hold them, and we + * propagate the real values when QMP queries happen. + * + * IOW, the corresponding fields within ram_counters on these specific + * fields will be always zero and not being used at all; they're just + * placeholders to make it QAPI-compatible. + */ +typedef struct { + Stat64 transferred; + Stat64 duplicate; + Stat64 normal; + Stat64 postcopy_bytes; +} MigrationAtomicStats; + +extern MigrationAtomicStats ram_atomic_counters; extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; extern CompressionStats compression_counters; diff --git a/migration/migration.c b/migration/migration.c index f485eea5fb..de83c50f51 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1049,13 +1049,13 @@ static void populate_ram_info(MigrationInfo *info, = MigrationState *s) =20 info->has_ram =3D true; info->ram =3D g_malloc0(sizeof(*info->ram)); - info->ram->transferred =3D ram_counters.transferred; + info->ram->transferred =3D stat64_get(&ram_atomic_counters.transferred= ); info->ram->total =3D ram_bytes_total(); - info->ram->duplicate =3D ram_counters.duplicate; + info->ram->duplicate =3D stat64_get(&ram_atomic_counters.duplicate); /* legacy value. It is not used anymore */ info->ram->skipped =3D 0; - info->ram->normal =3D ram_counters.normal; - info->ram->normal_bytes =3D ram_counters.normal * page_size; + info->ram->normal =3D stat64_get(&ram_atomic_counters.normal); + info->ram->normal_bytes =3D info->ram->normal * page_size; info->ram->mbps =3D s->mbps; info->ram->dirty_sync_count =3D ram_counters.dirty_sync_count; info->ram->dirty_sync_missed_zero_copy =3D @@ -1066,7 +1066,7 @@ static void populate_ram_info(MigrationInfo *info, Mi= grationState *s) info->ram->pages_per_second =3D s->pages_per_second; info->ram->precopy_bytes =3D ram_counters.precopy_bytes; info->ram->downtime_bytes =3D ram_counters.downtime_bytes; - info->ram->postcopy_bytes =3D ram_counters.postcopy_bytes; + info->ram->postcopy_bytes =3D stat64_get(&ram_atomic_counters.postcopy= _bytes); =20 if (migrate_use_xbzrle()) { info->has_xbzrle_cache =3D true; diff --git a/migration/multifd.c b/migration/multifd.c index b8dc559d24..000ca4d4ec 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -432,7 +432,7 @@ static int multifd_send_pages(QEMUFile *f) 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; + stat64_add(&ram_atomic_counters.transferred, transferred); qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 @@ -624,7 +624,7 @@ int multifd_send_sync_main(QEMUFile *f) 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; + stat64_add(&ram_atomic_counters.transferred, p->packet_len); qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 diff --git a/migration/ram.c b/migration/ram.c index 5379164749..f4cd9038f4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -425,18 +425,25 @@ uint64_t ram_bytes_remaining(void) 0; } =20 +/* + * NOTE: not all stats in ram_counters are used in reality. See comments + * for struct MigrationAtomicStats. The ultimate result of ram migration + * counters will be a merged version with both ram_counters and the atomic + * fields in ram_atomic_counters. + */ MigrationStats ram_counters; +MigrationAtomicStats ram_atomic_counters; =20 void ram_transferred_add(uint64_t bytes) { if (runstate_is_running()) { ram_counters.precopy_bytes +=3D bytes; } else if (migration_in_postcopy()) { - ram_counters.postcopy_bytes +=3D bytes; + stat64_add(&ram_atomic_counters.postcopy_bytes, bytes); } else { ram_counters.downtime_bytes +=3D bytes; } - ram_counters.transferred +=3D bytes; + stat64_add(&ram_atomic_counters.transferred, bytes); } =20 void dirty_sync_missed_zero_copy(void) @@ -725,7 +732,7 @@ void mig_throttle_counter_reset(void) =20 rs->time_last_bitmap_sync =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); rs->num_dirty_pages_period =3D 0; - rs->bytes_xfer_prev =3D ram_counters.transferred; + rs->bytes_xfer_prev =3D stat64_get(&ram_atomic_counters.transferred); } =20 /** @@ -1085,8 +1092,9 @@ uint64_t ram_pagesize_summary(void) =20 uint64_t ram_get_total_transferred_pages(void) { - return ram_counters.normal + ram_counters.duplicate + - compression_counters.pages + xbzrle_counters.pages; + return stat64_get(&ram_atomic_counters.normal) + + stat64_get(&ram_atomic_counters.duplicate) + + compression_counters.pages + xbzrle_counters.pages; } =20 static void migration_update_rates(RAMState *rs, int64_t end_time) @@ -1145,8 +1153,8 @@ static void migration_trigger_throttle(RAMState *rs) { MigrationState *s =3D migrate_get_current(); uint64_t threshold =3D s->parameters.throttle_trigger_threshold; - - uint64_t bytes_xfer_period =3D ram_counters.transferred - rs->bytes_xf= er_prev; + uint64_t bytes_xfer_period =3D + stat64_get(&ram_atomic_counters.transferred) - rs->bytes_xfer_prev; uint64_t bytes_dirty_period =3D rs->num_dirty_pages_period * TARGET_PA= GE_SIZE; uint64_t bytes_dirty_threshold =3D bytes_xfer_period * threshold / 100; =20 @@ -1209,7 +1217,7 @@ static void migration_bitmap_sync(RAMState *rs) /* reset period counters */ rs->time_last_bitmap_sync =3D end_time; rs->num_dirty_pages_period =3D 0; - rs->bytes_xfer_prev =3D ram_counters.transferred; + rs->bytes_xfer_prev =3D stat64_get(&ram_atomic_counters.transferre= d); } if (migrate_use_events()) { qapi_event_send_migration_pass(ram_counters.dirty_sync_count); @@ -1285,7 +1293,7 @@ static int save_zero_page(RAMState *rs, RAMBlock *blo= ck, ram_addr_t offset) int len =3D save_zero_page_to_file(rs, rs->f, block, offset); =20 if (len) { - ram_counters.duplicate++; + stat64_add(&ram_atomic_counters.duplicate, 1); ram_transferred_add(len); return 1; } @@ -1322,9 +1330,9 @@ static bool control_save_page(RAMState *rs, RAMBlock = *block, ram_addr_t offset, } =20 if (bytes_xmit > 0) { - ram_counters.normal++; + stat64_add(&ram_atomic_counters.normal, 1); } else if (bytes_xmit =3D=3D 0) { - ram_counters.duplicate++; + stat64_add(&ram_atomic_counters.duplicate, 1); } =20 return true; @@ -1354,7 +1362,7 @@ static int save_normal_page(RAMState *rs, RAMBlock *b= lock, ram_addr_t offset, qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); } ram_transferred_add(TARGET_PAGE_SIZE); - ram_counters.normal++; + stat64_add(&ram_atomic_counters.normal, 1); return 1; } =20 @@ -1410,7 +1418,7 @@ 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++; + stat64_add(&ram_atomic_counters.normal, 1); =20 return 1; } @@ -1448,7 +1456,7 @@ update_compress_thread_counts(const CompressParam *pa= ram, int bytes_xmit) ram_transferred_add(bytes_xmit); =20 if (param->zero_page) { - ram_counters.duplicate++; + stat64_add(&ram_atomic_counters.duplicate, 1); return; } =20 @@ -2623,9 +2631,9 @@ void acct_update_position(QEMUFile *f, size_t size, b= ool zero) uint64_t pages =3D size / TARGET_PAGE_SIZE; =20 if (zero) { - ram_counters.duplicate +=3D pages; + stat64_add(&ram_atomic_counters.duplicate, pages); } else { - ram_counters.normal +=3D pages; + stat64_add(&ram_atomic_counters.normal, pages); ram_transferred_add(size); qemu_file_credit_transfer(f, size); } --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669038915; cv=none; d=zohomail.com; s=zohoarc; b=UUzx0HCB3Zv8GyTNYuNu+rB1ph6UFfGN4uHfAD5ajZsojziN0wCXcBSWaTXz/fOWy6wZkQbKjIY7hck7Tkn4RSdQFC1mzlSbYc0cUfomGZnjaeBAfOmHNuh7HWK9RdIVXy8VwkxXyEd/u4RBLMfN8n5OR9h+1kzEAVghfbLyHvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669038915; 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=xvso+uqexrJS++o89EhHm9GXqK2SAyeGs3yfsu8kVfg=; b=PdkGB6XiEG5n1CoLwtTIhk7umGW0YaTCHyHVhevPobrgOFCjVABE2CHxaiT2dBsYs87VEoBwVu1iqIHilqmcDpcy+9u5Tby+VBuR8peiUhSF0amarYDNac251V+77BQjuSkPZQPgLIQi5v/GIj7hK76dIXMY4f8VAf5IYj4N5Xw= 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 1669038915895871.960054449189; Mon, 21 Nov 2022 05:55:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rp-0001IT-7G; Mon, 21 Nov 2022 08:29:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rK-0000i0-5h for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004wa-Kj for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:12 -0500 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-385-oYRgKpdMNHulbfUJiIu-Pg-1; Mon, 21 Nov 2022 08:28:01 -0500 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 92696811E67; Mon, 21 Nov 2022 13:28:00 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1CB04B3FC6; Mon, 21 Nov 2022 13:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037284; 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=xvso+uqexrJS++o89EhHm9GXqK2SAyeGs3yfsu8kVfg=; b=DFl7OX//5UcoTK0moFaVUYpDtYtKiSPehp8TKnXVCKAJ50+HgGCNx2qFQS0bOzlBzvazUf 6I9vb536miCF2h2RZajrxCjiBAbNQfeDJ0E7UOIbRzRSBJZq0zxbSFm7blR1/apekowHiM ueAuFPg4ycz9z+LPq8qAdjn6Mi0aWw0= X-MC-Unique: oYRgKpdMNHulbfUJiIu-Pg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 12/19] migration: Teach PSS about host page Date: Mon, 21 Nov 2022 14:27:10 +0100 Message-Id: <20221121132717.63070-13-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669038918366100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Migration code has a lot to do with host pages. Teaching PSS core about the idea of host page helps a lot and makes the code clean. Meanwhile, this prepares for the future changes that can leverage the new PSS helpers that this patch introduces to send host page in another thread. Three more fields are introduced for this: (1) host_page_sending: this is set to true when QEMU is sending a host page, false otherwise. (2) host_page_{start|end}: these point to the start/end of host page we're sending, and it's only valid when host_page_sending=3D=3Dtrue. For example, when we look up the next dirty page on the ramblock, with host_page_sending=3D=3Dtrue, we'll not try to look for anything beyond the current host page boundary. This can be slightly efficient than current code because currently we'll set pss->page to next dirty bit (which can be over current host page boundary) and reset it to host page boundary if we found it goes beyond that. With above, we can easily make migration_bitmap_find_dirty() self contained by updating pss->page properly. rs* parameter is removed because it's not even used in old code. When sending a host page, we should use the pss helpers like this: - pss_host_page_prepare(pss): called before sending host page - pss_within_range(pss): whether we're still working on the cur host page? - pss_host_page_finish(pss): called after sending a host page Then we can use ram_save_target_page() to save one small page. Currently ram_save_host_page() is still the only user. If there'll be another function to send host page (e.g. in return path thread) in the future, it should follow the same style. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 95 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index f4cd9038f4..4d7b50ef79 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -481,6 +481,11 @@ struct PageSearchStatus { * postcopy pages via postcopy preempt channel. */ bool postcopy_target_channel; + /* Whether we're sending a host page */ + bool host_page_sending; + /* The start/end of current host page. Only valid if host_page_sendin= g=3D=3Dtrue */ + unsigned long host_page_start; + unsigned long host_page_end; }; typedef struct PageSearchStatus PageSearchStatus; =20 @@ -858,26 +863,38 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **c= urrent_data, } =20 /** - * migration_bitmap_find_dirty: find the next dirty page from start + * pss_find_next_dirty: find the next dirty page of current ramblock * - * Returns the page offset within memory region of the start of a dirty pa= ge + * This function updates pss->page to point to the next dirty page index + * within the ramblock to migrate, or the end of ramblock when nothing + * found. Note that when pss->host_page_sending=3D=3Dtrue it means we're + * during sending a host page, so we won't look for dirty page that is + * outside the host page boundary. * - * @rs: current RAM state - * @rb: RAMBlock where to search for dirty pages - * @start: page where we start the search + * @pss: the current page search status */ -static inline -unsigned long migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb, - unsigned long start) +static void pss_find_next_dirty(PageSearchStatus *pss) { + RAMBlock *rb =3D pss->block; unsigned long size =3D rb->used_length >> TARGET_PAGE_BITS; unsigned long *bitmap =3D rb->bmap; =20 if (ramblock_is_ignored(rb)) { - return size; + /* Points directly to the end, so we know no dirty page */ + pss->page =3D size; + return; } =20 - return find_next_bit(bitmap, size, start); + /* + * If during sending a host page, only look for dirty pages within the + * current host page being send. + */ + if (pss->host_page_sending) { + assert(pss->host_page_end); + size =3D MIN(size, pss->host_page_end); + } + + pss->page =3D find_next_bit(bitmap, size, pss->page); } =20 static void migration_clear_memory_region_dirty_bitmap(RAMBlock *rb, @@ -1563,7 +1580,9 @@ static bool find_dirty_block(RAMState *rs, PageSearch= Status *pss, bool *again) pss->postcopy_requested =3D false; pss->postcopy_target_channel =3D RAM_CHANNEL_PRECOPY; =20 - pss->page =3D migration_bitmap_find_dirty(rs, pss->block, pss->page); + /* Update pss->page for the next dirty bit in ramblock */ + pss_find_next_dirty(pss); + if (pss->complete_round && pss->block =3D=3D rs->last_seen_block && pss->page >=3D rs->last_page) { /* @@ -2452,6 +2471,44 @@ static void postcopy_preempt_reset_channel(RAMState = *rs) } } =20 +/* Should be called before sending a host page */ +static void pss_host_page_prepare(PageSearchStatus *pss) +{ + /* How many guest pages are there in one host page? */ + size_t guest_pfns =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BIT= S; + + pss->host_page_sending =3D true; + pss->host_page_start =3D ROUND_DOWN(pss->page, guest_pfns); + pss->host_page_end =3D ROUND_UP(pss->page + 1, guest_pfns); +} + +/* + * Whether the page pointed by PSS is within the host page being sent. + * Must be called after a previous pss_host_page_prepare(). + */ +static bool pss_within_range(PageSearchStatus *pss) +{ + ram_addr_t ram_addr; + + assert(pss->host_page_sending); + + /* Over host-page boundary? */ + if (pss->page >=3D pss->host_page_end) { + return false; + } + + ram_addr =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; + + return offset_in_ramblock(pss->block, ram_addr); +} + +static void pss_host_page_finish(PageSearchStatus *pss) +{ + pss->host_page_sending =3D false; + /* This is not needed, but just to reset it */ + pss->host_page_start =3D pss->host_page_end =3D 0; +} + /** * ram_save_host_page: save a whole host page * @@ -2479,8 +2536,6 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) int tmppages, pages =3D 0; size_t pagesize_bits =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; - unsigned long hostpage_boundary =3D - QEMU_ALIGN_UP(pss->page + 1, pagesize_bits); unsigned long start_page =3D pss->page; int res; =20 @@ -2493,6 +2548,9 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) postcopy_preempt_choose_channel(rs, pss); } =20 + /* Update host page boundary information */ + pss_host_page_prepare(pss); + do { if (postcopy_needs_preempt(rs, pss)) { postcopy_do_preempt(rs, pss); @@ -2530,15 +2588,14 @@ static int ram_save_host_page(RAMState *rs, PageSea= rchStatus *pss) } =20 if (tmppages < 0) { + pss_host_page_finish(pss); return tmppages; } =20 - pss->page =3D migration_bitmap_find_dirty(rs, pss->block, pss->pag= e); - } while ((pss->page < hostpage_boundary) && - offset_in_ramblock(pss->block, - ((ram_addr_t)pss->page) << TARGET_PAGE_BIT= S)); - /* The offset we leave with is the min boundary of host page and block= */ - pss->page =3D MIN(pss->page, hostpage_boundary); + pss_find_next_dirty(pss); + } while (pss_within_range(pss)); + + pss_host_page_finish(pss); =20 /* * When with postcopy preempt mode, flush the data as soon as possible= for --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669040956; cv=none; d=zohomail.com; s=zohoarc; b=VoHltraDkprxR4c4yEa273TNghq6HCh1Slh7UaK9snELOUl3Zp615UgKngAA8wrcDCdpYZUD2S6lutoI9tSkxcmLXTpHXuJjIzZfnSByi6xLUHeeSVBG+1rmpyFNzeKa7vGzYp3EEHGCCn7Q+bTPGITf+NgY2NVfyLxCVu48F78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669040956; 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=KkPlQ4gEg9a7Yj+e7nBmIk5Ti/EnLgZT1bGXxBuSW7U=; b=ZFQS+HSE0jJqQchGFPlvoBBfijnUq6W1c+jS5ZMT+870BKHcPxgw4Hh/i4iC6OyCNkxO/GgrB731NbZ6lbiZsjwKyNJR+SGe04ILbog+iHMlAuoP8tvfNXfAzVe+NMeJBkAnSe9Ho72tZFhouqkfk3KsnzVCqXG60iFca/dRBCA= 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 1669040956089264.4387106991056; Mon, 21 Nov 2022 06:29:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rr-0001PW-Tu; Mon, 21 Nov 2022 08:29:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rO-0000kK-4G for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qZ-00051J-Qx for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:15 -0500 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-142-LhcNS1qZPE-vRbWGvYsEqg-1; Mon, 21 Nov 2022 08:28:03 -0500 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 7A49A85A588; Mon, 21 Nov 2022 13:28:03 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEE7E4B3FC6; Mon, 21 Nov 2022 13:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037294; 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=KkPlQ4gEg9a7Yj+e7nBmIk5Ti/EnLgZT1bGXxBuSW7U=; b=F+oqEuF+PJaCxAth6u0XYeEyIKqyK5OSnkLxyi5dO4j/Dxph5KerrPvDC2Bkj0dhOLHERH UQcpmuziBSnEIGBIfLDFp/wvTpAKA4399Y5PUKJauKd6BmhnYXNiqZAConMY4PN4Ly9R65 YwLjD41ijaRD9jJKIC/9DxYvNFqGKew= X-MC-Unique: LhcNS1qZPE-vRbWGvYsEqg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 13/19] migration: Introduce pss_channel Date: Mon, 21 Nov 2022 14:27:11 +0100 Message-Id: <20221121132717.63070-14-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669040957791100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Introduce pss_channel for PageSearchStatus, define it as "the migration channel to be used to transfer this host page". We used to have rs->f, which is a mirror to MigrationState.to_dst_file. After postcopy preempt initial version, rs->f can be dynamically changed depending on which channel we want to use. But that later work still doesn't grant full concurrency of sending pages in e.g. different threads, because rs->f can either be the PRECOPY channel or POSTCOPY channel. This needs to be per-thread too. PageSearchStatus is actually a good piece of struct which we can leverage if we want to have multiple threads sending pages. Sending a single guest page may not make sense, so we make the granule to be "host page", and in the PSS structure we allow specify a QEMUFile* to migrate a specific host page. Then we open the possibility to specify different channels in different threads with different PSS structures. The PSS prefix can be slightly misleading here because e.g. for the upcoming usage of postcopy channel/thread it's not "searching" (or, scanning) at all but sending the explicit page that was requested. However since PSS existed for some years keep it as-is until someone complains. This patch mostly (simply) replace rs->f with pss->pss_channel only. No functional change intended for this patch yet. But it does prepare to finally drop rs->f, and make ram_save_guest_page() thread safe. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 70 +++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 4d7b50ef79..571d780987 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -453,6 +453,8 @@ void dirty_sync_missed_zero_copy(void) =20 /* used by the search for pages to send */ struct PageSearchStatus { + /* The migration channel used for a specific host page */ + QEMUFile *pss_channel; /* Current block being searched */ RAMBlock *block; /* Current page to search from */ @@ -775,9 +777,9 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_ad= dr_t current_addr) * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_xbzrle_page(RAMState *rs, uint8_t **current_data, - ram_addr_t current_addr, RAMBlock *block, - ram_addr_t offset) +static int save_xbzrle_page(RAMState *rs, QEMUFile *file, + uint8_t **current_data, ram_addr_t current_add= r, + RAMBlock *block, ram_addr_t offset) { int encoded_len =3D 0, bytes_xbzrle; uint8_t *prev_cached_page; @@ -845,11 +847,11 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **c= urrent_data, } =20 /* Send XBZRLE based compressed page */ - bytes_xbzrle =3D save_page_header(rs, rs->f, block, + bytes_xbzrle =3D save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_XBZRLE); - qemu_put_byte(rs->f, ENCODING_FLAG_XBZRLE); - qemu_put_be16(rs->f, encoded_len); - qemu_put_buffer(rs->f, XBZRLE.encoded_buf, encoded_len); + qemu_put_byte(file, ENCODING_FLAG_XBZRLE); + qemu_put_be16(file, encoded_len); + qemu_put_buffer(file, XBZRLE.encoded_buf, encoded_len); bytes_xbzrle +=3D encoded_len + 1 + 2; /* * Like compressed_size (please see update_compress_thread_counts), @@ -1305,9 +1307,10 @@ static int save_zero_page_to_file(RAMState *rs, QEMU= File *file, * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) +static int save_zero_page(RAMState *rs, QEMUFile *file, RAMBlock *block, + ram_addr_t offset) { - int len =3D save_zero_page_to_file(rs, rs->f, block, offset); + int len =3D save_zero_page_to_file(rs, file, block, offset); =20 if (len) { stat64_add(&ram_atomic_counters.duplicate, 1); @@ -1324,15 +1327,15 @@ static int save_zero_page(RAMState *rs, RAMBlock *b= lock, ram_addr_t offset) * * Return true if the pages has been saved, otherwise false is returned. */ -static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t of= fset, - int *pages) +static bool control_save_page(PageSearchStatus *pss, RAMBlock *block, + ram_addr_t offset, int *pages) { uint64_t bytes_xmit =3D 0; int ret; =20 *pages =3D -1; - ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAG= E_SIZE, - &bytes_xmit); + ret =3D ram_control_save_page(pss->pss_channel, block->offset, offset, + TARGET_PAGE_SIZE, &bytes_xmit); if (ret =3D=3D RAM_SAVE_CONTROL_NOT_SUPP) { return false; } @@ -1366,17 +1369,17 @@ static bool control_save_page(RAMState *rs, RAMBloc= k *block, ram_addr_t offset, * @buf: the page to be sent * @async: send to page asyncly */ -static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offs= et, - uint8_t *buf, bool async) +static int save_normal_page(RAMState *rs, QEMUFile *file, RAMBlock *block, + ram_addr_t offset, uint8_t *buf, bool async) { - ram_transferred_add(save_page_header(rs, rs->f, block, + ram_transferred_add(save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_PAGE)); if (async) { - qemu_put_buffer_async(rs->f, buf, TARGET_PAGE_SIZE, + qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, migrate_release_ram() && migration_in_postcopy()); } else { - qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); + qemu_put_buffer(file, buf, TARGET_PAGE_SIZE); } ram_transferred_add(TARGET_PAGE_SIZE); stat64_add(&ram_atomic_counters.normal, 1); @@ -1409,8 +1412,8 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 XBZRLE_cache_lock(); if (rs->xbzrle_enabled && !migration_in_postcopy()) { - pages =3D save_xbzrle_page(rs, &p, current_addr, block, - offset); + pages =3D save_xbzrle_page(rs, pss->pss_channel, &p, current_addr, + block, offset); if (!rs->last_stage) { /* Can't send this cached data async, since the cache page * might get updated before it gets to the wire @@ -1421,7 +1424,8 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - pages =3D save_normal_page(rs, block, offset, p, send_async); + pages =3D save_normal_page(rs, pss->pss_channel, block, offset, + p, send_async); } =20 XBZRLE_cache_unlock(); @@ -1429,10 +1433,10 @@ static int ram_save_page(RAMState *rs, PageSearchSt= atus *pss) return pages; } =20 -static int ram_save_multifd_page(RAMState *rs, RAMBlock *block, +static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block, ram_addr_t offset) { - if (multifd_queue_page(rs->f, block, offset) < 0) { + if (multifd_queue_page(file, block, offset) < 0) { return -1; } stat64_add(&ram_atomic_counters.normal, 1); @@ -1727,7 +1731,7 @@ static int ram_save_release_protection(RAMState *rs, = PageSearchStatus *pss, uint64_t run_length =3D (pss->page - start_page) << TARGET_PAGE_BI= TS; =20 /* Flush async buffers before un-protect. */ - qemu_fflush(rs->f); + qemu_fflush(pss->pss_channel); /* Un-protect memory range. */ res =3D uffd_change_protection(rs->uffdio_fd, page_address, run_le= ngth, false, false); @@ -2314,7 +2318,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) ram_addr_t offset =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; int res; =20 - if (control_save_page(rs, block, offset, &res)) { + if (control_save_page(pss, block, offset, &res)) { return res; } =20 @@ -2322,7 +2326,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) return 1; } =20 - res =3D save_zero_page(rs, block, offset); + res =3D save_zero_page(rs, pss->pss_channel, block, offset); if (res > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale @@ -2342,7 +2346,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) * still see partially copied pages which is data corruption. */ if (migrate_use_multifd() && !migration_in_postcopy()) { - return ram_save_multifd_page(rs, block, offset); + return ram_save_multifd_page(pss->pss_channel, block, offset); } =20 return ram_save_page(rs, pss); @@ -2544,10 +2548,6 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) return 0; } =20 - if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, pss); - } - /* Update host page boundary information */ pss_host_page_prepare(pss); =20 @@ -2607,7 +2607,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) * explicit flush or it won't flush until the buffer is full. */ if (migrate_postcopy_preempt() && pss->postcopy_requested) { - qemu_fflush(rs->f); + qemu_fflush(pss->pss_channel); } =20 res =3D ram_save_release_protection(rs, pss, start_page); @@ -2673,6 +2673,12 @@ static int ram_find_and_save_block(RAMState *rs) } =20 if (found) { + /* Update rs->f with correct channel */ + if (postcopy_preempt_active()) { + postcopy_preempt_choose_channel(rs, &pss); + } + /* Cache rs->f in pss_channel (TODO: remove rs->f) */ + pss.pss_channel =3D rs->f; pages =3D ram_save_host_page(rs, &pss); } } while (!pages && again); --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669040238; cv=none; d=zohomail.com; s=zohoarc; b=mXo1OxKrcOEZjiJ4iTFyUA5f3QrdEJfaA8mGXPQbN7WYpd/wA/4sMRtwjW4mCMSOqYjWDMWzMq/UnMYxTq8X29QQvI7OYwO6deLsy5mQ9pISGlRsJx7sHkQhH1vLiCfXSzbUF+Aaf1grdOC3qy6QKzI8YOZPtEgTDsl06+BbF8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669040238; 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=8lyK5jWTjCJAgRQLnodHZvbuyoizfgIifPcdRmMqw2Q=; b=N/lKzThchMCqEbgvBQF3urgAxe4btFIC77dLgz69rwE/a8WvtYShFS/d+LKa7YV9oNrjUcfy4nvpxL+wxMIjYrpniVUp5olXseojK1nrwAmJnJipuItUInvKp5tQeu5h3kz/xjMlY+UmwP9Gu6rn2Dyb2LLInEOQkJAlHHjRuEY= 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 166904023801442.770685880308065; Mon, 21 Nov 2022 06:17:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6ro-0001Eh-Hn; Mon, 21 Nov 2022 08:29:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rH-0000gT-OJ for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-0004yZ-H8 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:09 -0500 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-183-0plxxgscPT25rqtQU1jvrA-1; Mon, 21 Nov 2022 08:28:07 -0500 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 631041C0758A; Mon, 21 Nov 2022 13:28:06 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id C54124B3FC6; Mon, 21 Nov 2022 13:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037290; 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=8lyK5jWTjCJAgRQLnodHZvbuyoizfgIifPcdRmMqw2Q=; b=YXnYLW6MAHT5XfTW5NfxZ/356RN5zlkpvJ9S4kY6IuknLUzjgeNF3/by++iLhlDFWhPG4o tgC7du4oizG+ag66EYYNAQ1PQl7raEc4S5ZYiiPf6MOyNgavqHd53rT25TsanKocRiAbqN iKOAh+0FuqWy2AMbjwbdk5WHy6jI6qQ= X-MC-Unique: 0plxxgscPT25rqtQU1jvrA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 14/19] migration: Add pss_init() Date: Mon, 21 Nov 2022 14:27:12 +0100 Message-Id: <20221121132717.63070-15-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669040239289100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Helper to init PSS structures. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 571d780987..d81bf7b183 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -542,6 +542,14 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream= *stream, RAMBlock *block, static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss, bool postcopy_requested); =20 +/* NOTE: page is the PFN not real ram_addr_t. */ +static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) +{ + pss->block =3D rb; + pss->page =3D page; + pss->complete_round =3D false; +} + static void *do_data_compress(void *opaque) { CompressParam *param =3D opaque; @@ -2650,9 +2658,7 @@ static int ram_find_and_save_block(RAMState *rs) rs->last_page =3D 0; } =20 - pss.block =3D rs->last_seen_block; - pss.page =3D rs->last_page; - pss.complete_round =3D false; + pss_init(&pss, rs->last_seen_block, rs->last_page); =20 do { again =3D true; --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669041046; cv=none; d=zohomail.com; s=zohoarc; b=IpQQfpz890iaoBYcbGoyEFiiVnM8/hzQyst70CSpwTpWFhDzpNTeYP+oJHG/4SiL46Q+cjydKEzg268+liNLu+sOXRH/Pe2V8eeBQ8n1d4iAaAzgTZ3trIQiqEu5twefcoAItcG+70lCrlYGetUTD9X4d8GNN1EXuBZEsfDl+38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669041046; 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=qYA73M7Ng+wC6nj7QttuHiv7/6zn1BOBSnRJfyDjZvE=; b=jK5s2XWBe26VyNhxpxp4gS8kit+o2AwHiXEc2gSOMNb/8WIss8nYDSSnCTkEC1Dff+mweM5C1mg6kB606KD16lvnV1ovJqM+lP8kx12515HkV+nUdtz1kre/xMkkk48ovemFlm5xTgIPJvaHVWNGGWxS3BoiCSXLt1gy6Qn0Gw0= 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 166904104667022.929950693545948; Mon, 21 Nov 2022 06:30:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rr-0001LG-3M; Mon, 21 Nov 2022 08:29:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rO-0000kr-4w for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qZ-0004zL-Qy for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 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-658-kz1I8UQOMmuqGSVU2wUD6Q-1; Mon, 21 Nov 2022 08:28:09 -0500 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 6A70E3C025D2; Mon, 21 Nov 2022 13:28:09 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9B294B3FC6; Mon, 21 Nov 2022 13:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037291; 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=qYA73M7Ng+wC6nj7QttuHiv7/6zn1BOBSnRJfyDjZvE=; b=aNwpJSujB0xkVR+nVSbPffcDtSJZanBNIhWuJsKDJPrIHu2dU5H2/7fkL+VkqqcSsIbgTq oPlGFN4fIEHZshyCPOG3MA28IM85LsbLfK7JKV6h9Okd1L6CJP0s4DAxgKOnMWRgysgGtm Rn8pawU/DAIcXZcxu7xugrZ2agdYjnE= X-MC-Unique: kz1I8UQOMmuqGSVU2wUD6Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 15/19] migration: Make PageSearchStatus part of RAMState Date: Mon, 21 Nov 2022 14:27:13 +0100 Message-Id: <20221121132717.63070-16-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669041048110100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu We used to allocate PSS structure on the stack for precopy when sending pages. Make it static, so as to describe per-channel ram migration status. Here we declared RAM_CHANNEL_MAX instances, preparing for postcopy to use it, even though this patch has not yet to start using the 2nd instance. This should not have any functional change per se, but it already starts to export PSS information via the RAMState, so that e.g. one PSS channel can start to reference the other PSS channel. Always protect PSS access using the same RAMState.bitmap_mutex. We already do so, so no code change needed, just some comment update. Maybe we should consider renaming bitmap_mutex some day as it's going to be a more commonly and big mutex we use for ram states, but just leave it for later. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 112 ++++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index d81bf7b183..3194997738 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -85,6 +85,46 @@ =20 XBZRLECacheStats xbzrle_counters; =20 +/* used by the search for pages to send */ +struct PageSearchStatus { + /* The migration channel used for a specific host page */ + QEMUFile *pss_channel; + /* Current block being searched */ + RAMBlock *block; + /* Current page to search from */ + unsigned long page; + /* Set once we wrap around */ + bool complete_round; + /* + * [POSTCOPY-ONLY] Whether current page is explicitly requested by + * postcopy. When set, the request is "urgent" because the dest QEMU + * threads are waiting for us. + */ + bool postcopy_requested; + /* + * [POSTCOPY-ONLY] The target channel to use to send current page. + * + * Note: This may _not_ match with the value in postcopy_requested + * above. Let's imagine the case where the postcopy request is exactly + * the page that we're sending in progress during precopy. In this case + * we'll have postcopy_requested set to true but the target channel + * will be the precopy channel (so that we don't split brain on that + * specific page since the precopy channel already contains partial of + * that page data). + * + * Besides that specific use case, postcopy_target_channel should + * always be equal to postcopy_requested, because by default we send + * postcopy pages via postcopy preempt channel. + */ + bool postcopy_target_channel; + /* Whether we're sending a host page */ + bool host_page_sending; + /* The start/end of current host page. Invalid if host_page_sending= =3D=3Dfalse */ + unsigned long host_page_start; + unsigned long host_page_end; +}; +typedef struct PageSearchStatus PageSearchStatus; + /* struct contains XBZRLE cache and a static page used by the compression */ static struct { @@ -319,6 +359,11 @@ typedef struct { struct RAMState { /* QEMUFile used for this migration */ QEMUFile *f; + /* + * PageSearchStatus structures for the channels when send pages. + * Protected by the bitmap_mutex. + */ + PageSearchStatus pss[RAM_CHANNEL_MAX]; /* UFFD file descriptor, used in 'write-tracking' migration */ int uffdio_fd; /* Last block that we have visited searching for dirty pages */ @@ -362,7 +407,12 @@ struct RAMState { uint64_t target_page_count; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; - /* Protects modification of the bitmap and migration dirty pages */ + /* + * Protects: + * - dirty/clear bitmap + * - migration_dirty_pages + * - pss structures + */ QemuMutex bitmap_mutex; /* The RAMBlock used in the last src_page_requests */ RAMBlock *last_req_rb; @@ -451,46 +501,6 @@ void dirty_sync_missed_zero_copy(void) ram_counters.dirty_sync_missed_zero_copy++; } =20 -/* used by the search for pages to send */ -struct PageSearchStatus { - /* The migration channel used for a specific host page */ - QEMUFile *pss_channel; - /* Current block being searched */ - RAMBlock *block; - /* Current page to search from */ - unsigned long page; - /* Set once we wrap around */ - bool complete_round; - /* - * [POSTCOPY-ONLY] Whether current page is explicitly requested by - * postcopy. When set, the request is "urgent" because the dest QEMU - * threads are waiting for us. - */ - bool postcopy_requested; - /* - * [POSTCOPY-ONLY] The target channel to use to send current page. - * - * Note: This may _not_ match with the value in postcopy_requested - * above. Let's imagine the case where the postcopy request is exactly - * the page that we're sending in progress during precopy. In this case - * we'll have postcopy_requested set to true but the target channel - * will be the precopy channel (so that we don't split brain on that - * specific page since the precopy channel already contains partial of - * that page data). - * - * Besides that specific use case, postcopy_target_channel should - * always be equal to postcopy_requested, because by default we send - * postcopy pages via postcopy preempt channel. - */ - bool postcopy_target_channel; - /* Whether we're sending a host page */ - bool host_page_sending; - /* The start/end of current host page. Only valid if host_page_sendin= g=3D=3Dtrue */ - unsigned long host_page_start; - unsigned long host_page_end; -}; -typedef struct PageSearchStatus PageSearchStatus; - CompressionStats compression_counters; =20 struct CompressParam { @@ -2637,7 +2647,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) */ static int ram_find_and_save_block(RAMState *rs) { - PageSearchStatus pss; + PageSearchStatus *pss =3D &rs->pss[RAM_CHANNEL_PRECOPY]; int pages =3D 0; bool again, found; =20 @@ -2658,11 +2668,11 @@ static int ram_find_and_save_block(RAMState *rs) rs->last_page =3D 0; } =20 - pss_init(&pss, rs->last_seen_block, rs->last_page); + pss_init(pss, rs->last_seen_block, rs->last_page); =20 do { again =3D true; - found =3D get_queued_page(rs, &pss); + found =3D get_queued_page(rs, pss); =20 if (!found) { /* @@ -2670,27 +2680,27 @@ static int ram_find_and_save_block(RAMState *rs) * preempted precopy. Otherwise find the next dirty bit. */ if (postcopy_preempt_triggered(rs)) { - postcopy_preempt_restore(rs, &pss, false); + postcopy_preempt_restore(rs, pss, false); found =3D true; } else { /* priority queue empty, so just search for something dirt= y */ - found =3D find_dirty_block(rs, &pss, &again); + found =3D find_dirty_block(rs, pss, &again); } } =20 if (found) { /* Update rs->f with correct channel */ if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, &pss); + postcopy_preempt_choose_channel(rs, pss); } /* Cache rs->f in pss_channel (TODO: remove rs->f) */ - pss.pss_channel =3D rs->f; - pages =3D ram_save_host_page(rs, &pss); + pss->pss_channel =3D rs->f; + pages =3D ram_save_host_page(rs, pss); } } while (!pages && again); =20 - rs->last_seen_block =3D pss.block; - rs->last_page =3D pss.page; + rs->last_seen_block =3D pss->block; + rs->last_page =3D pss->page; =20 return pages; } --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669037644; cv=none; d=zohomail.com; s=zohoarc; b=O1qf/+rYntVBzowKsgeJKIAkXaDH0zypynAHvqS30sTGYoOAq8WNilCglFgC5jgz3GMGG/fsojetmJ03hFP/2CpVBmYXP7UraTbD1L+USR6kpIxgmX4zm5WS1bsf7otsI4Q7oBcrbzNAHRr6nXxrhd+gpUbVOd9C9H5zhOCYdfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669037644; 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=7icidAgMmKsBG3F4fcNXQX7B0Cy+7eWT7Gq+EOY+DcU=; b=aYooPS/Dbtq0PXVRWdb3JwVbstP8BefNC5mXWFG3q4couf441nYbEKnIKyMHt1wdn5pYtl01+kNKMl9kmIOEV6Gd1FP/4EAQGh88KI8k5oVIb2xqhDus8NR4SGTYKuGTmJhTy1BuGy1fx2j/TfQRiJ5Uw6YWBMQV51GqneCNpbI= 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 1669037644573882.6118464841394; Mon, 21 Nov 2022 05:34:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rg-00019I-2r; Mon, 21 Nov 2022 08:29:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rG-0000fp-8p for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-00050v-F3 for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:09 -0500 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-672-Q_efWS23PjeXEJxFARdZRg-1; Mon, 21 Nov 2022 08:28:12 -0500 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 7EC2A3C0F66C; Mon, 21 Nov 2022 13:28:12 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id B08234B3FC6; Mon, 21 Nov 2022 13:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037294; 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=7icidAgMmKsBG3F4fcNXQX7B0Cy+7eWT7Gq+EOY+DcU=; b=F2bYT+cwJ1s7kIddFTZP+ccvkHMBhXJArlSVMBriQxnGUWW8hJB3AfJFT9N7f1Lf/p+9VS cSsWR77AxIF36aC2Jkeb2TAzjnjjxqAabtKcPAI2cwKM1ZLYLqDA6yMrUKMnuWv+Df7ucc potAs0ls+lTfKq6hYf+faKjmTHppclU= X-MC-Unique: Q_efWS23PjeXEJxFARdZRg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 16/19] migration: Move last_sent_block into PageSearchStatus Date: Mon, 21 Nov 2022 14:27:14 +0100 Message-Id: <20221121132717.63070-17-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669037645887100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Since we use PageSearchStatus to represent a channel, it makes perfect sense to keep last_sent_block (aka, leverage RAM_SAVE_FLAG_CONTINUE) to be per-channel rather than global because each channel can be sending different pages on ramblocks. Hence move it from RAMState into PageSearchStatus. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 71 ++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 3194997738..1233ff53ac 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -89,6 +89,8 @@ XBZRLECacheStats xbzrle_counters; struct PageSearchStatus { /* The migration channel used for a specific host page */ QEMUFile *pss_channel; + /* Last block from where we have sent data */ + RAMBlock *last_sent_block; /* Current block being searched */ RAMBlock *block; /* Current page to search from */ @@ -368,8 +370,6 @@ struct RAMState { int uffdio_fd; /* Last block that we have visited searching for dirty pages */ RAMBlock *last_seen_block; - /* Last block from where we have sent data */ - RAMBlock *last_sent_block; /* Last dirty target page we have sent */ ram_addr_t last_page; /* last ram version we have seen */ @@ -684,16 +684,17 @@ exit: * * Returns the number of bytes written * - * @f: QEMUFile where to send the data + * @pss: current PSS channel status * @block: block that contains the page we want to send * @offset: offset inside the block for the page * in the lower bits, it contains flags */ -static size_t save_page_header(RAMState *rs, QEMUFile *f, RAMBlock *block, +static size_t save_page_header(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { size_t size, len; - bool same_block =3D (block =3D=3D rs->last_sent_block); + bool same_block =3D (block =3D=3D pss->last_sent_block); + QEMUFile *f =3D pss->pss_channel; =20 if (same_block) { offset |=3D RAM_SAVE_FLAG_CONTINUE; @@ -706,7 +707,7 @@ static size_t save_page_header(RAMState *rs, QEMUFile *= f, RAMBlock *block, qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)block->idstr, len); size +=3D 1 + len; - rs->last_sent_block =3D block; + pss->last_sent_block =3D block; } return size; } @@ -790,17 +791,19 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_= addr_t current_addr) * -1 means that xbzrle would be longer than normal * * @rs: current RAM state + * @pss: current PSS channel * @current_data: pointer to the address of the page contents * @current_addr: addr of the page * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_xbzrle_page(RAMState *rs, QEMUFile *file, +static int save_xbzrle_page(RAMState *rs, PageSearchStatus *pss, uint8_t **current_data, ram_addr_t current_add= r, RAMBlock *block, ram_addr_t offset) { int encoded_len =3D 0, bytes_xbzrle; uint8_t *prev_cached_page; + QEMUFile *file =3D pss->pss_channel; =20 if (!cache_is_cached(XBZRLE.cache, current_addr, ram_counters.dirty_sync_count)) { @@ -865,7 +868,7 @@ static int save_xbzrle_page(RAMState *rs, QEMUFile *fil= e, } =20 /* Send XBZRLE based compressed page */ - bytes_xbzrle =3D save_page_header(rs, file, block, + bytes_xbzrle =3D save_page_header(pss, block, offset | RAM_SAVE_FLAG_XBZRLE); qemu_put_byte(file, ENCODING_FLAG_XBZRLE); qemu_put_be16(file, encoded_len); @@ -1296,19 +1299,19 @@ void ram_release_page(const char *rbname, uint64_t = offset) * Returns the size of data written to the file, 0 means the page is not * a zero page * - * @rs: current RAM state - * @file: the file where the data is saved + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page_to_file(RAMState *rs, QEMUFile *file, +static int save_zero_page_to_file(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { uint8_t *p =3D block->host + offset; + QEMUFile *file =3D pss->pss_channel; int len =3D 0; =20 if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { - len +=3D save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_= ZERO); + len +=3D save_page_header(pss, block, offset | RAM_SAVE_FLAG_ZERO); qemu_put_byte(file, 0); len +=3D 1; ram_release_page(block->idstr, offset); @@ -1321,14 +1324,14 @@ static int save_zero_page_to_file(RAMState *rs, QEM= UFile *file, * * Returns the number of pages written. * - * @rs: current RAM state + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(RAMState *rs, QEMUFile *file, RAMBlock *block, +static int save_zero_page(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { - int len =3D save_zero_page_to_file(rs, file, block, offset); + int len =3D save_zero_page_to_file(pss, block, offset); =20 if (len) { stat64_add(&ram_atomic_counters.duplicate, 1); @@ -1381,16 +1384,18 @@ static bool control_save_page(PageSearchStatus *pss= , RAMBlock *block, * * Returns the number of pages written. * - * @rs: current RAM state + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @buf: the page to be sent * @async: send to page asyncly */ -static int save_normal_page(RAMState *rs, QEMUFile *file, RAMBlock *block, +static int save_normal_page(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset, uint8_t *buf, bool async) { - ram_transferred_add(save_page_header(rs, file, block, + QEMUFile *file =3D pss->pss_channel; + + ram_transferred_add(save_page_header(pss, block, offset | RAM_SAVE_FLAG_PAGE)); if (async) { qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, @@ -1430,7 +1435,7 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 XBZRLE_cache_lock(); if (rs->xbzrle_enabled && !migration_in_postcopy()) { - pages =3D save_xbzrle_page(rs, pss->pss_channel, &p, current_addr, + pages =3D save_xbzrle_page(rs, pss, &p, current_addr, block, offset); if (!rs->last_stage) { /* Can't send this cached data async, since the cache page @@ -1442,8 +1447,7 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - pages =3D save_normal_page(rs, pss->pss_channel, block, offset, - p, send_async); + pages =3D save_normal_page(pss, block, offset, p, send_async); } =20 XBZRLE_cache_unlock(); @@ -1466,14 +1470,15 @@ static bool do_compress_ram_page(QEMUFile *f, z_str= eam *stream, RAMBlock *block, ram_addr_t offset, uint8_t *source_buf) { RAMState *rs =3D ram_state; + PageSearchStatus *pss =3D &rs->pss[RAM_CHANNEL_PRECOPY]; uint8_t *p =3D block->host + offset; int ret; =20 - if (save_zero_page_to_file(rs, f, block, offset)) { + if (save_zero_page_to_file(pss, block, offset)) { return true; } =20 - save_page_header(rs, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); + save_page_header(pss, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); =20 /* * copy it to a internal buffer to avoid it being modified by VM @@ -2293,7 +2298,8 @@ static bool save_page_use_compression(RAMState *rs) * has been properly handled by compression, otherwise needs other * paths to handle it */ -static bool save_compress_page(RAMState *rs, RAMBlock *block, ram_addr_t o= ffset) +static bool save_compress_page(RAMState *rs, PageSearchStatus *pss, + RAMBlock *block, ram_addr_t offset) { if (!save_page_use_compression(rs)) { return false; @@ -2309,7 +2315,7 @@ static bool save_compress_page(RAMState *rs, RAMBlock= *block, ram_addr_t offset) * We post the fist page as normal page as compression will take * much CPU resource. */ - if (block !=3D rs->last_sent_block) { + if (block !=3D pss->last_sent_block) { flush_compressed_data(rs); return false; } @@ -2340,11 +2346,11 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) return res; } =20 - if (save_compress_page(rs, block, offset)) { + if (save_compress_page(rs, pss, block, offset)) { return 1; } =20 - res =3D save_zero_page(rs, pss->pss_channel, block, offset); + res =3D save_zero_page(pss, block, offset); if (res > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale @@ -2475,7 +2481,7 @@ static void postcopy_preempt_choose_channel(RAMState = *rs, PageSearchStatus *pss) * If channel switched, reset last_sent_block since the old sent b= lock * may not be on the same channel. */ - rs->last_sent_block =3D NULL; + pss->last_sent_block =3D NULL; =20 trace_postcopy_preempt_switch_channel(channel); } @@ -2814,8 +2820,13 @@ static void ram_save_cleanup(void *opaque) =20 static void ram_state_reset(RAMState *rs) { + int i; + + for (i =3D 0; i < RAM_CHANNEL_MAX; i++) { + rs->pss[i].last_sent_block =3D NULL; + } + rs->last_seen_block =3D NULL; - rs->last_sent_block =3D NULL; rs->last_page =3D 0; rs->last_version =3D ram_list.version; rs->xbzrle_enabled =3D false; @@ -3009,8 +3020,8 @@ void ram_postcopy_send_discard_bitmap(MigrationState = *ms) migration_bitmap_sync(rs); =20 /* Easiest way to make sure we don't resume in the middle of a host-pa= ge */ + rs->pss[RAM_CHANNEL_PRECOPY].last_sent_block =3D NULL; rs->last_seen_block =3D NULL; - rs->last_sent_block =3D NULL; rs->last_page =3D 0; =20 postcopy_each_ram_send_discard(ms); --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669040349; cv=none; d=zohomail.com; s=zohoarc; b=apFG43rWv9RGvuh2U0Qj2WjlJtGDLbVi3LT7TO9mSA5WrSo7K+2vEaN8Zk+y2OH0Nk+TSxIbFsYvHY7GEeJkd83+ZyPwAP0MCNcqUBriGPbq4irImyBQtx0LrkncMvMVvVHF3KCc9Oj05VOHI9gANCaXM07ohF2OrrP8mClY5Uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669040349; 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=T/JPm5m9WNX1+QtcngXEAxrLV4M1X8iY9tKJjlFSJj4=; b=GEUAyXNQCBkZJeOIUTTi59xFr0D9OOFTUSHSpLtmKN6yEodWn2+nZZCRVqHTa6DOYm3SUYSreSzheIAtBU41c9VtNaytkDyQI52XIxBOodv8LOT6h4YM9FjxZ96+Kzq681SQRrfFflKlsM7U3v/gYuQZKm10poLNSw0w6UOhjBI= 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 1669040349406871.8818768114187; Mon, 21 Nov 2022 06:19:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rs-0001R2-SO; Mon, 21 Nov 2022 08:29:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rP-0000oK-2r for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qZ-00052O-Qy for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:16 -0500 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-94-FKdqcKRrOlCDm3EV3J3_1w-1; Mon, 21 Nov 2022 08:28:16 -0500 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 8F1E5800B23; Mon, 21 Nov 2022 13:28:15 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9AF74B3FC6; Mon, 21 Nov 2022 13:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037299; 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=T/JPm5m9WNX1+QtcngXEAxrLV4M1X8iY9tKJjlFSJj4=; b=Ai2pEMCzuVTlPSL845iEqaxJ/K7BOdqLzw7MvKmXwU81WCG5a2o4LszRTcGzpH8T9uRXsX I6MMTAjvZ5RsIMWECyR01QjNolpiI8ra5znCL43dhxZoeUUGODFGO6Ip0NEDbyGDiddevv GEie/aLhUvWk8Qtj0DwH6OzCpTwd3KI= X-MC-Unique: FKdqcKRrOlCDm3EV3J3_1w-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 17/19] migration: Send requested page directly in rp-return thread Date: Mon, 21 Nov 2022 14:27:15 +0100 Message-Id: <20221121132717.63070-18-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URG_BIZ=0.573 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669040351598100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu With all the facilities ready, send the requested page directly in the rp-return thread rather than queuing it in the request queue, if and only if postcopy preempt is enabled. It can achieve so because it uses separate channel for sending urgent pages. The only shared data is bitmap and it's protected by the bitmap_mutex. Note that since we're moving the ownership of the urgent channel from the migration thread to rp thread it also means the rp thread is responsible for managing the qemufile, e.g. properly close it when pausing migration happens. For this, let migration_release_from_dst_file to cover shutdown of the urgent channel too, renaming it as migration_release_dst_files() to better show what it does. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 35 +++++++------ migration/ram.c | 112 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 16 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index de83c50f51..c1d4d76d0c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2848,8 +2848,11 @@ static int migrate_handle_rp_resume_ack(MigrationSta= te *s, uint32_t value) return 0; } =20 -/* Release ms->rp_state.from_dst_file in a safe way */ -static void migration_release_from_dst_file(MigrationState *ms) +/* + * Release ms->rp_state.from_dst_file (and postcopy_qemufile_src if + * existed) in a safe way. + */ +static void migration_release_dst_files(MigrationState *ms) { QEMUFile *file; =20 @@ -2862,6 +2865,18 @@ static void migration_release_from_dst_file(Migratio= nState *ms) ms->rp_state.from_dst_file =3D NULL; } =20 + /* + * Do the same to postcopy fast path socket too if there is. No + * locking needed because this qemufile should only be managed by + * return path thread. + */ + if (ms->postcopy_qemufile_src) { + migration_ioc_unregister_yank_from_file(ms->postcopy_qemufile_src); + qemu_file_shutdown(ms->postcopy_qemufile_src); + qemu_fclose(ms->postcopy_qemufile_src); + ms->postcopy_qemufile_src =3D NULL; + } + qemu_fclose(file); } =20 @@ -3006,7 +3021,7 @@ out: * Maybe there is something we can do: it looks like a * network down issue, and we pause for a recovery. */ - migration_release_from_dst_file(ms); + migration_release_dst_files(ms); rp =3D NULL; if (postcopy_pause_return_path_thread(ms)) { /* @@ -3024,7 +3039,7 @@ out: } =20 trace_source_return_path_thread_end(); - migration_release_from_dst_file(ms); + migration_release_dst_files(ms); rcu_unregister_thread(); return NULL; } @@ -3547,18 +3562,6 @@ static MigThrError postcopy_pause(MigrationState *s) qemu_file_shutdown(file); qemu_fclose(file); =20 - /* - * Do the same to postcopy fast path socket too if there is. No - * locking needed because no racer as long as we do this before se= tting - * status to paused. - */ - if (s->postcopy_qemufile_src) { - migration_ioc_unregister_yank_from_file(s->postcopy_qemufile_s= rc); - qemu_file_shutdown(s->postcopy_qemufile_src); - qemu_fclose(s->postcopy_qemufile_src); - s->postcopy_qemufile_src =3D NULL; - } - migrate_set_state(&s->state, s->state, MIGRATION_STATUS_POSTCOPY_PAUSED); =20 diff --git a/migration/ram.c b/migration/ram.c index 1233ff53ac..16ade7cb70 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -546,6 +546,8 @@ static QemuThread *decompress_threads; static QemuMutex decomp_done_lock; static QemuCond decomp_done_cond; =20 +static int ram_save_host_page_urgent(PageSearchStatus *pss); + static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, ram_addr_t offset, uint8_t *source_buf); =20 @@ -560,6 +562,16 @@ static void pss_init(PageSearchStatus *pss, RAMBlock *= rb, ram_addr_t page) pss->complete_round =3D false; } =20 +/* + * Check whether two PSSs are actively sending the same page. Return true + * if it is, false otherwise. + */ +static bool pss_overlap(PageSearchStatus *pss1, PageSearchStatus *pss2) +{ + return pss1->host_page_sending && pss2->host_page_sending && + (pss1->host_page_start =3D=3D pss2->host_page_start); +} + static void *do_data_compress(void *opaque) { CompressParam *param =3D opaque; @@ -2260,6 +2272,57 @@ int ram_save_queue_pages(const char *rbname, ram_add= r_t start, ram_addr_t len) return -1; } =20 + /* + * When with postcopy preempt, we send back the page directly in the + * rp-return thread. + */ + if (postcopy_preempt_active()) { + ram_addr_t page_start =3D start >> TARGET_PAGE_BITS; + size_t page_size =3D qemu_ram_pagesize(ramblock); + PageSearchStatus *pss =3D &ram_state->pss[RAM_CHANNEL_POSTCOPY]; + int ret =3D 0; + + qemu_mutex_lock(&rs->bitmap_mutex); + + pss_init(pss, ramblock, page_start); + /* + * Always use the preempt channel, and make sure it's there. It's + * safe to access without lock, because when rp-thread is running + * we should be the only one who operates on the qemufile + */ + pss->pss_channel =3D migrate_get_current()->postcopy_qemufile_src; + pss->postcopy_requested =3D true; + assert(pss->pss_channel); + + /* + * It must be either one or multiple of host page size. Just + * assert; if something wrong we're mostly split brain anyway. + */ + assert(len % page_size =3D=3D 0); + while (len) { + if (ram_save_host_page_urgent(pss)) { + error_report("%s: ram_save_host_page_urgent() failed: " + "ramblock=3D%s, start_addr=3D0x"RAM_ADDR_FMT, + __func__, ramblock->idstr, start); + ret =3D -1; + break; + } + /* + * NOTE: after ram_save_host_page_urgent() succeeded, pss->page + * will automatically be moved and point to the next host page + * we're going to send, so no need to update here. + * + * Normally QEMU never sends >1 host page in requests, so + * logically we don't even need that as the loop should only + * run once, but just to be consistent. + */ + len -=3D page_size; + }; + qemu_mutex_unlock(&rs->bitmap_mutex); + + return ret; + } + struct RAMSrcPageRequest *new_entry =3D g_new0(struct RAMSrcPageRequest, 1); new_entry->rb =3D ramblock; @@ -2537,6 +2600,55 @@ static void pss_host_page_finish(PageSearchStatus *p= ss) pss->host_page_start =3D pss->host_page_end =3D 0; } =20 +/* + * Send an urgent host page specified by `pss'. Need to be called with + * bitmap_mutex held. + * + * Returns 0 if save host page succeeded, false otherwise. + */ +static int ram_save_host_page_urgent(PageSearchStatus *pss) +{ + bool page_dirty, sent =3D false; + RAMState *rs =3D ram_state; + int ret =3D 0; + + trace_postcopy_preempt_send_host_page(pss->block->idstr, pss->page); + pss_host_page_prepare(pss); + + /* + * If precopy is sending the same page, let it be done in precopy, or + * we could send the same page in two channels and none of them will + * receive the whole page. + */ + if (pss_overlap(pss, &ram_state->pss[RAM_CHANNEL_PRECOPY])) { + trace_postcopy_preempt_hit(pss->block->idstr, + pss->page << TARGET_PAGE_BITS); + return 0; + } + + do { + page_dirty =3D migration_bitmap_clear_dirty(rs, pss->block, pss->p= age); + + if (page_dirty) { + /* Be strict to return code; it must be 1, or what else? */ + if (ram_save_target_page(rs, pss) !=3D 1) { + error_report_once("%s: ram_save_target_page failed", __fun= c__); + ret =3D -1; + goto out; + } + sent =3D true; + } + pss_find_next_dirty(pss); + } while (pss_within_range(pss)); +out: + pss_host_page_finish(pss); + /* For urgent requests, flush immediately if sent */ + if (sent) { + qemu_fflush(pss->pss_channel); + } + return ret; +} + /** * ram_save_host_page: save a whole host page * --=20 2.38.1 From nobody Fri May 10 16:01:01 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=1669039044; cv=none; d=zohomail.com; s=zohoarc; b=b5C+US/ODcG4ljfVB0C9Vhvhy/7TXIQIeY05K3YvHUndddTZvgGWfeIju3slnyc8vWSlKpRx8mE3qp4pCiArkSA0J4JBbhEMhLaf/Mugeh9zWWzEPZWVT116zB85fZn6dMwyK6SH8X3Ug5tiifuFTwT3HNAFkR7uUn2ieUFeGg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669039044; 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=b3OaD6EmIOQmYblQD6JDebQ+SMMGjJtWN/jwPdmSW4w=; b=FW+r+lEzBtbrbFnNiuUeTMYHT/1rwVXPSI3J6eU7El2tV6MZNUMywiUOJj4ae9v0toBgfvTQDORpjUqK2en47ro8G62NWlcAq5FIYpMbuU20QmYE6XwYUS6qKnvvf4JyI4MfbY+KiTene8mwuQY+MdfEZsmYs6JEeuIR5qtSOMM= 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 1669039044556280.43672771005936; Mon, 21 Nov 2022 05:57:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rq-0001Kg-Hh; Mon, 21 Nov 2022 08:29:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rI-0000hp-Fb for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qY-00052p-JC for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:11 -0500 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-73-x5uhRCdiNJGoNkBTGzzYTw-1; Mon, 21 Nov 2022 08:28:19 -0500 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 BD080101A528; Mon, 21 Nov 2022 13:28:18 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCBE04B3FC6; Mon, 21 Nov 2022 13:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037303; 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=b3OaD6EmIOQmYblQD6JDebQ+SMMGjJtWN/jwPdmSW4w=; b=Njp6yDjs+vBQ8Jcy5p7BgUnRMXb3XkL8oNX+8uikt2idbXdu6VsMi+IRH1Tl41/hbgtI2X uzy5E42vupdlmxh5DO5uuFA0Pqgo5BHHG+pRSmdnxSU4v5xNnJ2xxg+ofLegbJz6j+EHhr cKdlVIjM1JmyxgmZ+7kKvQ2dutPB6i4= X-MC-Unique: x5uhRCdiNJGoNkBTGzzYTw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 18/19] migration: Remove old preempt code around state maintainance Date: Mon, 21 Nov 2022 14:27:16 +0100 Message-Id: <20221121132717.63070-19-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URG_BIZ=0.573 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669039046208100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu With the new code to send pages in rp-return thread, there's little help to keep lots of the old code on maintaining the preempt state in migration thread, because the new way should always be faster.. Then if we'll always send pages in the rp-return thread anyway, we don't need those logic to maintain preempt state anymore because now we serialize things using the mutex directly instead of using those fields. It's very unfortunate to have those code for a short period, but that's still one intermediate step that we noticed the next bottleneck on the migration thread. Now what we can do best is to drop unnecessary code as long as the new code is stable to reduce the burden. It's actually a good thing because the new "sending page in rp-return thread" model is (IMHO) even cleaner and with better performance. Remove the old code that was responsible for maintaining preempt states, at the meantime also remove x-postcopy-preempt-break-huge parameter because with concurrent sender threads we don't really need to break-huge anymore. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 7 - migration/migration.c | 2 - migration/ram.c | 291 +----------------------------------------- 3 files changed, 3 insertions(+), 297 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index cdad8aceaa..ae4ffd3454 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -340,13 +340,6 @@ struct MigrationState { bool send_configuration; /* Whether we send section footer during migration */ bool send_section_footer; - /* - * Whether we allow break sending huge pages when postcopy preempt is - * enabled. When disabled, we won't interrupt precopy within sending a - * host huge page, which is the old behavior of vanilla postcopy. - * NOTE: this parameter is ignored if postcopy preempt is not enabled. - */ - bool postcopy_preempt_break_huge; =20 /* Needed by postcopy-pause state */ QemuSemaphore postcopy_pause_sem; diff --git a/migration/migration.c b/migration/migration.c index c1d4d76d0c..c3490c495d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -4402,8 +4402,6 @@ static Property migration_properties[] =3D { DEFINE_PROP_SIZE("announce-step", MigrationState, parameters.announce_step, DEFAULT_MIGRATE_ANNOUNCE_STEP), - DEFINE_PROP_BOOL("x-postcopy-preempt-break-huge", MigrationState, - postcopy_preempt_break_huge, true), DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_host= name), DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), diff --git a/migration/ram.c b/migration/ram.c index 16ade7cb70..1ae093fb61 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -97,28 +97,6 @@ struct PageSearchStatus { unsigned long page; /* Set once we wrap around */ bool complete_round; - /* - * [POSTCOPY-ONLY] Whether current page is explicitly requested by - * postcopy. When set, the request is "urgent" because the dest QEMU - * threads are waiting for us. - */ - bool postcopy_requested; - /* - * [POSTCOPY-ONLY] The target channel to use to send current page. - * - * Note: This may _not_ match with the value in postcopy_requested - * above. Let's imagine the case where the postcopy request is exactly - * the page that we're sending in progress during precopy. In this case - * we'll have postcopy_requested set to true but the target channel - * will be the precopy channel (so that we don't split brain on that - * specific page since the precopy channel already contains partial of - * that page data). - * - * Besides that specific use case, postcopy_target_channel should - * always be equal to postcopy_requested, because by default we send - * postcopy pages via postcopy preempt channel. - */ - bool postcopy_target_channel; /* Whether we're sending a host page */ bool host_page_sending; /* The start/end of current host page. Invalid if host_page_sending= =3D=3Dfalse */ @@ -343,20 +321,6 @@ struct RAMSrcPageRequest { QSIMPLEQ_ENTRY(RAMSrcPageRequest) next_req; }; =20 -typedef struct { - /* - * Cached ramblock/offset values if preempted. They're only meaningfu= l if - * preempted=3D=3Dtrue below. - */ - RAMBlock *ram_block; - unsigned long ram_page; - /* - * Whether a postcopy preemption just happened. Will be reset after - * precopy recovered to background migration. - */ - bool preempted; -} PostcopyPreemptState; - /* State of RAM for migration */ struct RAMState { /* QEMUFile used for this migration */ @@ -419,14 +383,6 @@ struct RAMState { /* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests; - - /* Postcopy preemption informations */ - PostcopyPreemptState postcopy_preempt_state; - /* - * Current channel we're using on src VM. Only valid if postcopy-pree= mpt - * is enabled. - */ - unsigned int postcopy_channel; }; typedef struct RAMState RAMState; =20 @@ -434,11 +390,6 @@ static RAMState *ram_state; =20 static NotifierWithReturnList precopy_notifier_list; =20 -static void postcopy_preempt_reset(RAMState *rs) -{ - memset(&rs->postcopy_preempt_state, 0, sizeof(PostcopyPreemptState)); -} - /* Whether postcopy has queued requests? */ static bool postcopy_has_request(RAMState *rs) { @@ -551,9 +502,6 @@ static int ram_save_host_page_urgent(PageSearchStatus *= pss); static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, ram_addr_t offset, uint8_t *source_buf); =20 -static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss, - bool postcopy_requested); - /* NOTE: page is the PFN not real ram_addr_t. */ static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) { @@ -1612,13 +1560,6 @@ retry: */ static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss, bool *ag= ain) { - /* - * This is not a postcopy requested page, mark it "not urgent", and use - * precopy channel to send it. - */ - pss->postcopy_requested =3D false; - pss->postcopy_target_channel =3D RAM_CHANNEL_PRECOPY; - /* Update pss->page for the next dirty bit in ramblock */ pss_find_next_dirty(pss); =20 @@ -2069,55 +2010,6 @@ void ram_write_tracking_stop(void) } #endif /* defined(__linux__) */ =20 -/* - * Check whether two addr/offset of the ramblock falls onto the same host = huge - * page. Returns true if so, false otherwise. - */ -static bool offset_on_same_huge_page(RAMBlock *rb, uint64_t addr1, - uint64_t addr2) -{ - size_t page_size =3D qemu_ram_pagesize(rb); - - addr1 =3D ROUND_DOWN(addr1, page_size); - addr2 =3D ROUND_DOWN(addr2, page_size); - - return addr1 =3D=3D addr2; -} - -/* - * Whether a previous preempted precopy huge page contains current request= ed - * page? Returns true if so, false otherwise. - * - * This should really happen very rarely, because it means when we were se= nding - * during background migration for postcopy we're sending exactly the page= that - * some vcpu got faulted on on dest node. When it happens, we probably do= n't - * need to do much but drop the request, because we know right after we re= store - * the precopy stream it'll be serviced. It'll slightly affect the order = of - * postcopy requests to be serviced (e.g. it'll be the same as we move cur= rent - * request to the end of the queue) but it shouldn't be a big deal. The m= ost - * imporant thing is we can _never_ try to send a partial-sent huge page o= n the - * POSTCOPY channel again, otherwise that huge page will got "split brain"= on - * two channels (PRECOPY, POSTCOPY). - */ -static bool postcopy_preempted_contains(RAMState *rs, RAMBlock *block, - ram_addr_t offset) -{ - PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; - - /* No preemption at all? */ - if (!state->preempted) { - return false; - } - - /* Not even the same ramblock? */ - if (state->ram_block !=3D block) { - return false; - } - - return offset_on_same_huge_page(block, offset, - state->ram_page << TARGET_PAGE_BITS); -} - /** * get_queued_page: unqueue a page from the postcopy requests * @@ -2157,20 +2049,7 @@ static bool get_queued_page(RAMState *rs, PageSearch= Status *pss) =20 } while (block && !dirty); =20 - if (block) { - /* See comment above postcopy_preempted_contains() */ - if (postcopy_preempted_contains(rs, block, offset)) { - trace_postcopy_preempt_hit(block->idstr, offset); - /* - * If what we preempted previously was exactly what we're - * requesting right now, restore the preempted precopy - * immediately, boosting its priority as it's requested by - * postcopy. - */ - postcopy_preempt_restore(rs, pss, true); - return true; - } - } else { + if (!block) { /* * Poll write faults too if background snapshot is enabled; that's * when we have vcpus got blocked by the write protected pages. @@ -2192,9 +2071,6 @@ static bool get_queued_page(RAMState *rs, PageSearchS= tatus *pss) * really rare. */ pss->complete_round =3D false; - /* Mark it an urgent request, meanwhile using POSTCOPY channel */ - pss->postcopy_requested =3D true; - pss->postcopy_target_channel =3D RAM_CHANNEL_POSTCOPY; } =20 return !!block; @@ -2291,7 +2167,6 @@ int ram_save_queue_pages(const char *rbname, ram_addr= _t start, ram_addr_t len) * we should be the only one who operates on the qemufile */ pss->pss_channel =3D migrate_get_current()->postcopy_qemufile_src; - pss->postcopy_requested =3D true; assert(pss->pss_channel); =20 /* @@ -2439,129 +2314,6 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) return ram_save_page(rs, pss); } =20 -static bool postcopy_needs_preempt(RAMState *rs, PageSearchStatus *pss) -{ - MigrationState *ms =3D migrate_get_current(); - - /* Not enabled eager preempt? Then never do that. */ - if (!migrate_postcopy_preempt()) { - return false; - } - - /* If the user explicitly disabled breaking of huge page, skip */ - if (!ms->postcopy_preempt_break_huge) { - return false; - } - - /* If the ramblock we're sending is a small page? Never bother. */ - if (qemu_ram_pagesize(pss->block) =3D=3D TARGET_PAGE_SIZE) { - return false; - } - - /* Not in postcopy at all? */ - if (!migration_in_postcopy()) { - return false; - } - - /* - * If we're already handling a postcopy request, don't preempt as this= page - * has got the same high priority. - */ - if (pss->postcopy_requested) { - return false; - } - - /* If there's postcopy requests, then check it up! */ - return postcopy_has_request(rs); -} - -/* Returns true if we preempted precopy, false otherwise */ -static void postcopy_do_preempt(RAMState *rs, PageSearchStatus *pss) -{ - PostcopyPreemptState *p_state =3D &rs->postcopy_preempt_state; - - trace_postcopy_preempt_triggered(pss->block->idstr, pss->page); - - /* - * Time to preempt precopy. Cache current PSS into preempt state, so t= hat - * after handling the postcopy pages we can recover to it. We need to= do - * so because the dest VM will have partial of the precopy huge page k= ept - * over in its tmp huge page caches; better move on with it when we ca= n. - */ - p_state->ram_block =3D pss->block; - p_state->ram_page =3D pss->page; - p_state->preempted =3D true; -} - -/* Whether we're preempted by a postcopy request during sending a huge pag= e */ -static bool postcopy_preempt_triggered(RAMState *rs) -{ - return rs->postcopy_preempt_state.preempted; -} - -static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss, - bool postcopy_requested) -{ - PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; - - assert(state->preempted); - - pss->block =3D state->ram_block; - pss->page =3D state->ram_page; - - /* Whether this is a postcopy request? */ - pss->postcopy_requested =3D postcopy_requested; - /* - * When restoring a preempted page, the old data resides in PRECOPY - * slow channel, even if postcopy_requested is set. So always use - * PRECOPY channel here. - */ - pss->postcopy_target_channel =3D RAM_CHANNEL_PRECOPY; - - trace_postcopy_preempt_restored(pss->block->idstr, pss->page); - - /* Reset preempt state, most importantly, set preempted=3D=3Dfalse */ - postcopy_preempt_reset(rs); -} - -static void postcopy_preempt_choose_channel(RAMState *rs, PageSearchStatus= *pss) -{ - MigrationState *s =3D migrate_get_current(); - unsigned int channel =3D pss->postcopy_target_channel; - QEMUFile *next; - - if (channel !=3D rs->postcopy_channel) { - if (channel =3D=3D RAM_CHANNEL_PRECOPY) { - next =3D s->to_dst_file; - } else { - next =3D s->postcopy_qemufile_src; - } - /* Update and cache the current channel */ - rs->f =3D next; - rs->postcopy_channel =3D channel; - - /* - * If channel switched, reset last_sent_block since the old sent b= lock - * may not be on the same channel. - */ - pss->last_sent_block =3D NULL; - - trace_postcopy_preempt_switch_channel(channel); - } - - trace_postcopy_preempt_send_host_page(pss->block->idstr, pss->page); -} - -/* We need to make sure rs->f always points to the default channel elsewhe= re */ -static void postcopy_preempt_reset_channel(RAMState *rs) -{ - if (postcopy_preempt_active()) { - rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; - rs->f =3D migrate_get_current()->to_dst_file; - trace_postcopy_preempt_reset_channel(); - } -} - /* Should be called before sending a host page */ static void pss_host_page_prepare(PageSearchStatus *pss) { @@ -2688,11 +2440,6 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) pss_host_page_prepare(pss); =20 do { - if (postcopy_needs_preempt(rs, pss)) { - postcopy_do_preempt(rs, pss); - break; - } - page_dirty =3D migration_bitmap_clear_dirty(rs, pss->block, pss->p= age); =20 /* Check the pages is dirty and if it is send it */ @@ -2733,19 +2480,6 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) =20 pss_host_page_finish(pss); =20 - /* - * When with postcopy preempt mode, flush the data as soon as possible= for - * postcopy requests, because we've already sent a whole huge page, so= the - * dst node should already have enough resource to atomically filling = in - * the current missing page. - * - * More importantly, when using separate postcopy channel, we must do - * explicit flush or it won't flush until the buffer is full. - */ - if (migrate_postcopy_preempt() && pss->postcopy_requested) { - qemu_fflush(pss->pss_channel); - } - res =3D ram_save_release_protection(rs, pss, start_page); return (res < 0 ? res : pages); } @@ -2793,24 +2527,11 @@ static int ram_find_and_save_block(RAMState *rs) found =3D get_queued_page(rs, pss); =20 if (!found) { - /* - * Recover previous precopy ramblock/offset if postcopy has - * preempted precopy. Otherwise find the next dirty bit. - */ - if (postcopy_preempt_triggered(rs)) { - postcopy_preempt_restore(rs, pss, false); - found =3D true; - } else { - /* priority queue empty, so just search for something dirt= y */ - found =3D find_dirty_block(rs, pss, &again); - } + /* priority queue empty, so just search for something dirty */ + found =3D find_dirty_block(rs, pss, &again); } =20 if (found) { - /* Update rs->f with correct channel */ - if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, pss); - } /* Cache rs->f in pss_channel (TODO: remove rs->f) */ pss->pss_channel =3D rs->f; pages =3D ram_save_host_page(rs, pss); @@ -2942,8 +2663,6 @@ static void ram_state_reset(RAMState *rs) rs->last_page =3D 0; rs->last_version =3D ram_list.version; rs->xbzrle_enabled =3D false; - postcopy_preempt_reset(rs); - rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; } =20 #define MAX_WAIT 50 /* ms, half buffered_file limit */ @@ -3587,8 +3306,6 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } qemu_mutex_unlock(&rs->bitmap_mutex); =20 - postcopy_preempt_reset_channel(rs); - /* * Must occur before EOS (or any QEMUFile operation) * because of RDMA protocol. @@ -3668,8 +3385,6 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) return ret; } =20 - postcopy_preempt_reset_channel(rs); - ret =3D multifd_send_sync_main(rs->f); if (ret < 0) { return ret; --=20 2.38.1 From nobody Fri May 10 16:01:02 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=1669037534; cv=none; d=zohomail.com; s=zohoarc; b=NTHYWykLUAwcYEzoaUKYm16zNA3H9jlwsjzufQfE5T6hOVt21dt9AweOPNHxO3cnwdET3fs/1RnDKWS3Ah+ywSZiZSzR/3uoEHW5TT/+48haWBjha+D71NMAMwzSpl+SCAixnlorOoLRZ6dEdKdDLirnoovo0E+3onVx0U/A7/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669037534; 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=W+GlhHy1Aw+J2S/PdKkSiWceIYryK6JZft0nwXoxTSo=; b=PjtLgxmaRVOK2YPD9Sqqtn/VES5NyiGwJTd6WYepcbHhs9TDuPg+qkJhAbiCwNfV45+DVTgUDuEUoHaY9a1TJD2cV0dvFgsE+72/wc5pfMlY3nNjMwPS0racU+K+kIwRAmc2M+UGQ3sc052U3srTgTx8mP0WWdBpa3vmbyxgb8s= 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 1669037534670621.8167796085962; Mon, 21 Nov 2022 05:32:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6rv-0001Uw-7U; Mon, 21 Nov 2022 08:29:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6rQ-0000rb-Fa for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox6qa-00052u-El for qemu-devel@nongnu.org; Mon, 21 Nov 2022 08:29:20 -0500 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-232-pighrKX1NSiD0FgFp5gFiQ-1; Mon, 21 Nov 2022 08:28:22 -0500 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 3B8E91C0878C; Mon, 21 Nov 2022 13:28:22 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13C294B3FC6; Mon, 21 Nov 2022 13:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669037304; 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=W+GlhHy1Aw+J2S/PdKkSiWceIYryK6JZft0nwXoxTSo=; b=X+p4xc44L9eFeDG0ElkofstucFt5nBieiV7+1GASM0roguKDszjW6PR2EV5LM5n1yRtgvT Yj4FrLa8bX4LF2gFe5ou0Jiy9ZEeJfiqKQ/W7J5u7KxXmRgR2br8ihuSPQTMbR0mVMPelg muh/ygk8PFqVRXbnZ75QwYDqcAGonAU= X-MC-Unique: pighrKX1NSiD0FgFp5gFiQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Fam Zheng , Peter Xu , Michael Tokarev , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , qemu-trivial@nongnu.org, Laurent Vivier Subject: [PATCH 19/19] migration: Drop rs->f Date: Mon, 21 Nov 2022 14:27:17 +0100 Message-Id: <20221121132717.63070-20-quintela@redhat.com> In-Reply-To: <20221121132717.63070-1-quintela@redhat.com> References: <20221121132717.63070-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669037535329100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Now with rs->pss we can already cache channels in pss->pss_channels. That pss_channel contains more infromation than rs->f because it's per-channel. So rs->f could be replaced by rss->pss[RAM_CHANNEL_PRECOPY].pss_channel, while rs->f itself is a bit vague now. Note that vanilla postcopy still send pages via pss[RAM_CHANNEL_PRECOPY], that's slightly confusing but it reflects the reality. Then, after the replacement we can safely drop rs->f. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 1ae093fb61..334309f1c6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -323,8 +323,6 @@ struct RAMSrcPageRequest { =20 /* State of RAM for migration */ struct RAMState { - /* QEMUFile used for this migration */ - QEMUFile *f; /* * PageSearchStatus structures for the channels when send pages. * Protected by the bitmap_mutex. @@ -2532,8 +2530,6 @@ static int ram_find_and_save_block(RAMState *rs) } =20 if (found) { - /* Cache rs->f in pss_channel (TODO: remove rs->f) */ - pss->pss_channel =3D rs->f; pages =3D ram_save_host_page(rs, pss); } } while (!pages && again); @@ -3089,7 +3085,7 @@ static void ram_state_resume_prepare(RAMState *rs, QE= MUFile *out) ram_state_reset(rs); =20 /* Update RAMState cache of output QEMUFile */ - rs->f =3D out; + rs->pss[RAM_CHANNEL_PRECOPY].pss_channel =3D out; =20 trace_ram_state_resume_prepare(pages); } @@ -3180,7 +3176,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) return -1; } } - (*rsp)->f =3D f; + (*rsp)->pss[RAM_CHANNEL_PRECOPY].pss_channel =3D f; =20 WITH_RCU_READ_LOCK_GUARD() { qemu_put_be64(f, ram_bytes_total_common(true) | RAM_SAVE_FLAG_MEM_= SIZE); @@ -3315,7 +3311,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) out: if (ret >=3D 0 && migration_is_setup_or_active(migrate_get_current()->state)) { - ret =3D multifd_send_sync_main(rs->f); + ret =3D multifd_send_sync_main(rs->pss[RAM_CHANNEL_PRECOPY].pss_ch= annel); if (ret < 0) { return ret; } @@ -3385,7 +3381,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) return ret; } =20 - ret =3D multifd_send_sync_main(rs->f); + ret =3D multifd_send_sync_main(rs->pss[RAM_CHANNEL_PRECOPY].pss_channe= l); if (ret < 0) { return ret; } --=20 2.38.1