From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066300; cv=none; d=zohomail.com; s=zohoarc; b=Ji3m0dGF/M7iMCcxAwStBkuPDFk4B2pmRtxhZkEFxohKT9o+xVFfLBWej9gdNmE68jXHuqHUpqCc4OZxpjhGepWP0pFkMY43TM3QRsfrFdmSt6B1og4jq0YAcdZD9dKxjV2CFGWKFlTUOCp3glIZbD+Agr9pJ7tBTH3esl84m08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066300; 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=7c+sD4OotUEqjVJcWorYvAM9vFbO0MI2eVVDySisLxU=; b=hmV0Un8CfDmWECb9ikew2AvXM7mz35EsEXOyKO9TNxwK6e8Zbd4+35z4PYQyWMs/OJ59eZ/2ymZCXMHysIFmoavc5bcMJCctycLDBxxUUkjnpFK+NbBskMsC862Fz2oJtVm6pqneJZJyJiuf/yeNBpeVr67AhAJV/ccBQv02sVY= 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+importer2=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 1675066300036654.2128789327026; Mon, 30 Jan 2023 00:11:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPEv-0000UP-0j; Mon, 30 Jan 2023 03:10:09 -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 1pMPEt-0000Qn-7O for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:07 -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 1pMPEr-0002Bm-Lk for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:06 -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-462-Tdk0YsWcPtqAE93LVo26Ew-1; Mon, 30 Jan 2023 03:10:00 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89B38858F09; Mon, 30 Jan 2023 08:10:00 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F4CD40C2064; Mon, 30 Jan 2023 08:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066204; 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=7c+sD4OotUEqjVJcWorYvAM9vFbO0MI2eVVDySisLxU=; b=Vaff9sx/r/bMZVXlwGVCRdcHjmmQ0CAASI0YsFKvLtwV4XBK4BRRu+g7osRj30A3zewGeW 2l6fBbmHvjppI+0gRqdzsFTZWVw2lAW6Mv6ynQiy4aGBe4ucuBYjG6wdmlPJX7Hsq8egOv ncrfSD+F2BwGiNxOSftjLo4XEJmo+xs= X-MC-Unique: Tdk0YsWcPtqAE93LVo26Ew-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 01/11] migration: Update atomic stats out of the mutex Date: Mon, 30 Jan 2023 09:09:46 +0100 Message-Id: <20230130080956.3047-2-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066300583100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela --- migration/multifd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 000ca4d4ec..20a81cd7f2 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -432,8 +432,8 @@ 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; + qemu_mutex_unlock(&p->mutex); stat64_add(&ram_atomic_counters.transferred, transferred); - qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 return 1; @@ -624,8 +624,8 @@ 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; + qemu_mutex_unlock(&p->mutex); stat64_add(&ram_atomic_counters.transferred, p->packet_len); - qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 if (flush_zero_copy && p->c && (multifd_zero_copy_flush(p->c) < 0)= ) { --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066225; cv=none; d=zohomail.com; s=zohoarc; b=Bu7rfK844mc+h6KKvwADYwAbron2Z/DV3bpLJ6S+odb9/KfgMoUsnZVCyC52ao7bjKeE9AkeiSalhX63IeqLHZgO/+FgvE5dOcg3yTLhRdLSmVB0ohvZ0SJYccgbbNUJoO+NjOauvLkV7SKEQgQPLuL+V+L0sUFZ6V8KGg7wgC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066225; 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=USGVnVFPX4fvPhmRZKGYBELqe2aLOfTeH6PH5QSb6JM=; b=kFKUxEQsem/jt68H7fLbuMscqJ15Nt15ChJcPPN163hh7JcRJ2/faZqIW6FQPpQJYAOKgsm2kgOMEex6ej7BVnooi6IAPkElza/WhfMxJNS4meNH6tiYjNHHMdavYTDjWZDFuWpl7gqhjkBRsgwCWL6WYhU9jRZP6kpsfu771OM= 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+importer2=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 1675066225262433.18002476489244; Mon, 30 Jan 2023 00:10:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPEy-0000Wz-6x; Mon, 30 Jan 2023 03:10:12 -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 1pMPEv-0000Uu-5G for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:09 -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 1pMPEt-0002C3-C7 for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:08 -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-577-yFdDRb_9MIWHI5kkLDTn-Q-1; Mon, 30 Jan 2023 03:10:02 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B4E83C0F660; Mon, 30 Jan 2023 08:10:02 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD34C40C2064; Mon, 30 Jan 2023 08:10:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066206; 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=USGVnVFPX4fvPhmRZKGYBELqe2aLOfTeH6PH5QSb6JM=; b=EOF0X63koEhtWDNc4YFaPOVOs8WBayN9ngfnlESxrCFKVjLicRzQ/AxiUMgHJZIITmmBWO AxADI7N2Ax4joz0Ps7T1culoT7dva9fOh9DD7XdtF2U6wM+FXsGrsVpO315OG1b/q0d12F Kyv/7T+W0OQQkBWE6DkpnZKm75HI070= X-MC-Unique: yFdDRb_9MIWHI5kkLDTn-Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 02/11] migration: Make multifd_bytes atomic Date: Mon, 30 Jan 2023 09:09:47 +0100 Message-Id: <20230130080956.3047-3-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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: -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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066226458100001 Content-Type: text/plain; charset="utf-8" In the spirit of: commit 394d323bc3451e4d07f13341cb8817fac8dfbadd Author: Peter Xu Date: Tue Oct 11 17:55:51 2022 -0400 migration: Use atomic ops properly for page accountings Signed-off-by: Juan Quintela --- migration/ram.h | 1 + migration/migration.c | 4 ++-- migration/multifd.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/migration/ram.h b/migration/ram.h index 81cbb0947c..3c1de6aedf 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -50,6 +50,7 @@ typedef struct { Stat64 duplicate; Stat64 normal; Stat64 postcopy_bytes; + Stat64 multifd_bytes; } MigrationAtomicStats; =20 extern MigrationAtomicStats ram_atomic_counters; diff --git a/migration/migration.c b/migration/migration.c index 644c61e91d..d261c7d16d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1058,7 +1058,7 @@ static void populate_ram_info(MigrationInfo *info, Mi= grationState *s) ram_counters.dirty_sync_missed_zero_copy; info->ram->postcopy_requests =3D ram_counters.postcopy_requests; info->ram->page_size =3D page_size; - info->ram->multifd_bytes =3D ram_counters.multifd_bytes; + info->ram->multifd_bytes =3D stat64_get(&ram_atomic_counters.multifd_b= ytes); 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; @@ -3659,7 +3659,7 @@ static MigThrError migration_detect_error(MigrationSt= ate *s) static uint64_t migration_total_bytes(MigrationState *s) { return qemu_file_total_transferred(s->to_dst_file) + - ram_counters.multifd_bytes; + stat64_get(&ram_atomic_counters.multifd_bytes); } =20 static void migration_calculate_complete(MigrationState *s) diff --git a/migration/multifd.c b/migration/multifd.c index 20a81cd7f2..49fa76e5e1 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -431,8 +431,8 @@ static int multifd_send_pages(QEMUFile *f) p->pages =3D pages; transferred =3D ((uint64_t) pages->num) * p->page_size + p->packet_len; qemu_file_acct_rate_limit(f, transferred); - ram_counters.multifd_bytes +=3D transferred; qemu_mutex_unlock(&p->mutex); + stat64_add(&ram_atomic_counters.multifd_bytes, transferred); stat64_add(&ram_atomic_counters.transferred, transferred); qemu_sem_post(&p->sem); =20 @@ -623,8 +623,8 @@ int multifd_send_sync_main(QEMUFile *f) p->flags |=3D MULTIFD_FLAG_SYNC; p->pending_job++; qemu_file_acct_rate_limit(f, p->packet_len); - ram_counters.multifd_bytes +=3D p->packet_len; qemu_mutex_unlock(&p->mutex); + stat64_add(&ram_atomic_counters.multifd_bytes, p->packet_len); stat64_add(&ram_atomic_counters.transferred, p->packet_len); qemu_sem_post(&p->sem); =20 --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066266; cv=none; d=zohomail.com; s=zohoarc; b=GMTUF6nkY7hBtDj502IA1FNFSEvdfFdmdfdjBThd4k/WuolrrXeSJqD+STZOvEgNIxr/TN35XOCXLezIRf0Gj0ogccCazttZ4T3FOY3I7xEZW3cI21MGNmdG6udY2WGzX5/OVU4hA41IMVxS1rjww4NB+i5EWZBN0q3aBtNO0bw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066266; 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=n9ddVPFq1kOyG/KjUimdELcX9rIUvg2jduKqRKDVUQs=; b=Oa4fDX/1VNI0qhoVLcXjxvGbdMBi6xqsWuqVyjewv39G6c4hcYKJ/d99c1gIOZOrU5MwMMP4RqZgSs7SDBzy7E/oeKsm6R6GxObH4rf0w3s/Rrv2RA9/mb9WX6zHGnTZO42aV0x4i9+gQDClkICvQkKYM8tcq/qMA3NBSVwogQU= 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+importer2=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 1675066266124670.3173802382483; Mon, 30 Jan 2023 00:11:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPF0-0000Zz-DE; Mon, 30 Jan 2023 03:10:14 -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 1pMPEx-0000WC-0G for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:11 -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 1pMPEu-0002DU-Ra for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:10 -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-204-mrTs1JVbN7OSfNvDaEZGMQ-1; Mon, 30 Jan 2023 03:10:04 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B3DF3802B8D; Mon, 30 Jan 2023 08:10:04 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F52040C2064; Mon, 30 Jan 2023 08:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066208; 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=n9ddVPFq1kOyG/KjUimdELcX9rIUvg2jduKqRKDVUQs=; b=jGnw48dXxon0bFkgsy6+FIG8y0dCucXR/VmJ/BOlfmvfG/kk7aUE9BF0Oyfwx10cRJPP7z vA2n4BqWXCKxvCnf8y7eGEM43HzCZUiyuyGhm2uZG2UPp+fr8BxxViCymsVTW+23Ud9De+ myuFSZSFDOgmkb5tWox8KyMceNHKaqk= X-MC-Unique: mrTs1JVbN7OSfNvDaEZGMQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 03/11] multifd: We already account for this packet on the multifd thread Date: Mon, 30 Jan 2023 09:09:48 +0100 Message-Id: <20230130080956.3047-4-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066266434100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela --- migration/multifd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 49fa76e5e1..61cafe4c76 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -622,10 +622,7 @@ int multifd_send_sync_main(QEMUFile *f) p->packet_num =3D multifd_send_state->packet_num++; p->flags |=3D MULTIFD_FLAG_SYNC; p->pending_job++; - qemu_file_acct_rate_limit(f, p->packet_len); qemu_mutex_unlock(&p->mutex); - stat64_add(&ram_atomic_counters.multifd_bytes, p->packet_len); - stat64_add(&ram_atomic_counters.transferred, p->packet_len); qemu_sem_post(&p->sem); =20 if (flush_zero_copy && p->c && (multifd_zero_copy_flush(p->c) < 0)= ) { --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066260; cv=none; d=zohomail.com; s=zohoarc; b=RnN05dpPZ5Lr0YfjyNVUKXj2CJphFfF9W/qVuUSpx3yhl9n7ZLib6vNLzUNPqRq5+8nDJIF06/pvD71u3nGMXcfjxg8LTD0e7hzE5LDvrZagIBxH3jyH2crv/8QuAuf3qDTKEnRQprbQCusNGpP6kXU0R1V9j7xPZf8ykxKasIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066260; 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=QBvuV85geefUsLm7HibkPjeR/8VvUsMI8xHmFfLOmHY=; b=F85P7dm1Gl/7TgMOUUu4dtzvH4rwsk3AIndtqmrQGMdSUAo5gtw/kTdNaHRGDYFnQDlX7BACUFL97mQiDXC8Oo3W+f3ufepc4brk9w0o1cE/OhqJWCu/5KYyE1uD05iDeZNSgkmqVpj7Z5eqFffV5vAMHh5h2tnjPuPsMRK3m84= 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+importer2=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 1675066260669901.2098499278914; Mon, 30 Jan 2023 00:11:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPF2-0000c2-AU; Mon, 30 Jan 2023 03:10:16 -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 1pMPEz-0000Yg-5i for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:13 -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 1pMPEx-0002Du-G2 for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10: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-284-yU-nXSauMlesSP12s0aRBg-1; Mon, 30 Jan 2023 03:10:06 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFF2F101A55E; Mon, 30 Jan 2023 08:10:05 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F14440C2004; Mon, 30 Jan 2023 08:10:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066210; 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=QBvuV85geefUsLm7HibkPjeR/8VvUsMI8xHmFfLOmHY=; b=BbOuvT4uE57JfEi6MZNXFHa1syw/b7+K2VMaFb4KaR6CKvLgqu+FxHdQlHcUqbRJht6nV2 IYMSvmpM7ntq01wVBmS4kUaMCBRt1/7pagTL30Y/GBY8Fm8xyKpskDB1AFR9cSlySR3I17 qI7WvURH5xhNvHN8TybLs5+RWEntTEU= X-MC-Unique: yU-nXSauMlesSP12s0aRBg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 04/11] multifd: Count the number of bytes sent correctly Date: Mon, 30 Jan 2023 09:09:49 +0100 Message-Id: <20230130080956.3047-5-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066262437100009 Content-Type: text/plain; charset="utf-8" Current code asumes that all pages are whole. That is not true for example for compression already. Fix it for creating a new field ->sent_bytes that includes it. All ram_counters are used only from the migration thread, so we have two options: - put a mutex and fill everything when we sent it (not only ram_counters, also qemu_file->xfer_bytes). - Create a local variable that implements how much has been sent through each channel. And when we push another packet, we "add" the previous stats. I choose two due to less changes overall. On the previous code we increase transferred and then we sent. Current code goes the other way around. It sents the data, and after the fact, it updates the counters. Notice that each channel can have a maximum of half a megabyte of data without counting, so it is not very important. Signed-off-by: Juan Quintela --- migration/multifd.h | 2 ++ migration/multifd.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index e2802a9ce2..36f899c56f 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -102,6 +102,8 @@ typedef struct { uint32_t flags; /* global number of generated multifd packets */ uint64_t packet_num; + /* How many bytes have we sent on the last packet */ + uint64_t sent_bytes; /* thread has work to do */ int pending_job; /* array of pages to sent. diff --git a/migration/multifd.c b/migration/multifd.c index 61cafe4c76..cd26b2fda9 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -394,7 +394,6 @@ static int multifd_send_pages(QEMUFile *f) static int next_channel; MultiFDSendParams *p =3D NULL; /* make happy gcc */ MultiFDPages_t *pages =3D multifd_send_state->pages; - uint64_t transferred; =20 if (qatomic_read(&multifd_send_state->exiting)) { return -1; @@ -429,7 +428,8 @@ static int multifd_send_pages(QEMUFile *f) p->packet_num =3D multifd_send_state->packet_num++; multifd_send_state->pages =3D p->pages; p->pages =3D pages; - transferred =3D ((uint64_t) pages->num) * p->page_size + p->packet_len; + uint64_t transferred =3D p->sent_bytes; + p->sent_bytes =3D 0; qemu_file_acct_rate_limit(f, transferred); qemu_mutex_unlock(&p->mutex); stat64_add(&ram_atomic_counters.multifd_bytes, transferred); @@ -719,6 +719,8 @@ static void *multifd_send_thread(void *opaque) } =20 qemu_mutex_lock(&p->mutex); + p->sent_bytes +=3D p->packet_len; + p->sent_bytes +=3D p->next_packet_size; p->pending_job--; qemu_mutex_unlock(&p->mutex); =20 --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066299; cv=none; d=zohomail.com; s=zohoarc; b=a9fbq0CgxChCgUBjkPmBELr4cSi5YuoK3H7sRySHOfAlQPBPHMCkLwrLy2o9kdIyi9VNY4WC+xc1whg7Pym1/3OXNFJdCxhrRYfgtSoLrHIR5RxgJeNHbn3CQpD0pSr3YAB5e++u0Fm/CrBoWhcAUQ32p/3BYT0WXRXXLNRDqE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066299; 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=6O4OvNOjVX8E1ma9PGuGDqk+ew+RduD3biRsujIKu/Y=; b=h9gc2A9nADrpojil+AoI6sZdeBDE/epvun/o5PZIPwlytxqk9hPbpH1HoZb7qryEwaNg1HPFGGcDfwi+M8kRBCGON7kaibMHSROaESefTnYprVV+Rv/oCT1KDR2aUuWnlhp/nJyB4EUWIy0k/4c0iPGjtiqriI6jVOgu8T5uiFI= 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+importer2=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 1675066299927586.8085756222501; Mon, 30 Jan 2023 00:11:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPF7-0000cP-Rg; Mon, 30 Jan 2023 03:10:22 -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 1pMPF0-0000bG-R7 for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:14 -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 1pMPEz-0002EB-1o for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:14 -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-512-Y1KXsbPOMriE9rqeTj5HUQ-1; Mon, 30 Jan 2023 03:10:08 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AB6D11C07584; Mon, 30 Jan 2023 08:10:07 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13E0940C2004; Mon, 30 Jan 2023 08:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066212; 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=6O4OvNOjVX8E1ma9PGuGDqk+ew+RduD3biRsujIKu/Y=; b=RwwO87m6HhotPUq4h/H70V/wZOWNpt5YLOMHf2vSaNNERSQfPkabRkbfs/hKqh37g5XQyq WABdVS33aUELC7Dx3BvP6gHe83glTX3aezZ43zNqVQRhuRH+Jsky+w0LzDveZSc9tXPGvZ /bMz3t6tW0p/Ha3/VkO2xrFXKYBc5is= X-MC-Unique: Y1KXsbPOMriE9rqeTj5HUQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 05/11] migration: Make ram_save_target_page() a pointer Date: Mon, 30 Jan 2023 09:09:50 +0100 Message-Id: <20230130080956.3047-6-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066300592100002 Content-Type: text/plain; charset="utf-8" We are going to create a new function for multifd latest in the series. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 885d7dbf23..04e1093cdc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -450,6 +450,13 @@ void dirty_sync_missed_zero_copy(void) ram_counters.dirty_sync_missed_zero_copy++; } =20 +struct MigrationOps { + int (*ram_save_target_page)(RAMState *rs, PageSearchStatus *pss); +}; +typedef struct MigrationOps MigrationOps; + +MigrationOps *migration_ops; + CompressionStats compression_counters; =20 struct CompressParam { @@ -2265,14 +2272,14 @@ static bool save_compress_page(RAMState *rs, PageSe= archStatus *pss, } =20 /** - * ram_save_target_page: save one target page + * ram_save_target_page_legacy: save one target page * * Returns the number of pages written * * @rs: current RAM state * @pss: data about the page we want to send */ -static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss) +static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss) { RAMBlock *block =3D pss->block; ram_addr_t offset =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; @@ -2398,7 +2405,7 @@ static int ram_save_host_page_urgent(PageSearchStatus= *pss) =20 if (page_dirty) { /* Be strict to return code; it must be 1, or what else? */ - if (ram_save_target_page(rs, pss) !=3D 1) { + if (migration_ops->ram_save_target_page(rs, pss) !=3D 1) { error_report_once("%s: ram_save_target_page failed", __fun= c__); ret =3D -1; goto out; @@ -2467,7 +2474,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) if (preempt_active) { qemu_mutex_unlock(&rs->bitmap_mutex); } - tmppages =3D ram_save_target_page(rs, pss); + tmppages =3D migration_ops->ram_save_target_page(rs, pss); if (tmppages >=3D 0) { pages +=3D tmppages; /* @@ -2662,6 +2669,8 @@ static void ram_save_cleanup(void *opaque) xbzrle_cleanup(); compress_threads_save_cleanup(); ram_state_cleanup(rsp); + g_free(migration_ops); + migration_ops =3D NULL; } =20 static void ram_state_reset(RAMState *rs) @@ -3215,6 +3224,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque) ram_control_before_iterate(f, RAM_CONTROL_SETUP); ram_control_after_iterate(f, RAM_CONTROL_SETUP); =20 + migration_ops =3D g_malloc0(sizeof(MigrationOps)); + migration_ops->ram_save_target_page =3D ram_save_target_page_legacy; ret =3D multifd_send_sync_main(f); if (ret < 0) { return ret; --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066282; cv=none; d=zohomail.com; s=zohoarc; b=SrlRs7UiUHAj4uKAaIKQGg1qK4ASFMcev4YNLAJEv+sz5PXW86a4QABAgfY2wT2tBogSoIXDfEihgWCv6LDhRMkOJg6FW1FL2NdmEq/RZddVHGleVnH0h+Cb6yV5x+FJmLAm4k5O/rNgeVQ9/9UnZSg51sqvZYqvEAi6WjmXWLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066282; 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=zJYG+euecEOLkjHsVWd7eJ4oTpdiHzIhC6SxjtzvC3I=; b=fIu38ZMiw69xgrSs+1628faCICYP5fhZZ4rk5YFVTJmMQKJC1yuG8RqXjLWB8IEtXxZE2JJighr34JSZZIMrEI7P+PL2LFDOnugbd7WBnS2c50r+5mzBUQAcUB/hoLc1GF0XkjoYMQ4LLK46GYSsdWGrRLeFf9btcWH2/HL/yyA= 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+importer2=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 1675066282625623.6776827220514; Mon, 30 Jan 2023 00:11:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPFD-0000fj-81; Mon, 30 Jan 2023 03:10:27 -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 1pMPF9-0000cw-DD for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:23 -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 1pMPF7-0002HF-SJ for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:23 -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-616-0FwSQKAKNIKTWrUX5cftlg-1; Mon, 30 Jan 2023 03:10:15 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7EB1D802D19; Mon, 30 Jan 2023 08:10:15 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id F07FA40C2064; Mon, 30 Jan 2023 08:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066221; 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=zJYG+euecEOLkjHsVWd7eJ4oTpdiHzIhC6SxjtzvC3I=; b=B0elRf8JKOU+YtHHsyWgPFG8EdehJdhqxNISP/FCeK39oGwYRdPaPOCf/1smJYe9NCHu5y Val1PeocVGXFM00v/+ZdGWW0eXI67HtNRg3MXvy+/LjsGM8ymMxsLTSQoaZ7KbrKLARyU1 R+NEi6Ml5o3nlymUcEtQkoAMMQ9RlVk= X-MC-Unique: 0FwSQKAKNIKTWrUX5cftlg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 06/11] multifd: Make flags field thread local Date: Mon, 30 Jan 2023 09:09:51 +0100 Message-Id: <20230130080956.3047-7-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066284655100005 Content-Type: text/plain; charset="utf-8" Use of flags with respect to locking was incensistant. For the sending side: - it was set to 0 with mutex held on the multifd channel. - MULTIFD_FLAG_SYNC was set with mutex held on the migration thread. - Everything else was done without the mutex held on the multifd channel. On the reception side, it is not used on the migration thread, only on the multifd channels threads. So we move it to the multifd channels thread only variables, and we introduce a new bool sync_needed on the send side to pass that information. Signed-off-by: Juan Quintela --- migration/multifd.h | 10 ++++++---- migration/multifd.c | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 36f899c56f..a67cefc0a2 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -98,12 +98,12 @@ typedef struct { bool running; /* should this thread finish */ bool quit; - /* multifd flags for each packet */ - uint32_t flags; /* global number of generated multifd packets */ uint64_t packet_num; /* How many bytes have we sent on the last packet */ uint64_t sent_bytes; + /* Do we need to do an iteration sync */ + bool sync_needed; /* thread has work to do */ int pending_job; /* array of pages to sent. @@ -117,6 +117,8 @@ typedef struct { =20 /* pointer to the packet */ MultiFDPacket_t *packet; + /* multifd flags for each packet */ + uint32_t flags; /* size of the next packet that contains pages */ uint32_t next_packet_size; /* packets sent through this channel */ @@ -163,8 +165,6 @@ typedef struct { bool running; /* should this thread finish */ bool quit; - /* multifd flags for each packet */ - uint32_t flags; /* global number of generated multifd packets */ uint64_t packet_num; =20 @@ -172,6 +172,8 @@ typedef struct { =20 /* pointer to the packet */ MultiFDPacket_t *packet; + /* multifd flags for each packet */ + uint32_t flags; /* size of the next packet that contains pages */ uint32_t next_packet_size; /* packets sent through this channel */ diff --git a/migration/multifd.c b/migration/multifd.c index cd26b2fda9..77196a55b4 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -620,7 +620,7 @@ int multifd_send_sync_main(QEMUFile *f) } =20 p->packet_num =3D multifd_send_state->packet_num++; - p->flags |=3D MULTIFD_FLAG_SYNC; + p->sync_needed =3D true; p->pending_job++; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); @@ -667,7 +667,11 @@ static void *multifd_send_thread(void *opaque) =20 if (p->pending_job) { uint64_t packet_num =3D p->packet_num; - uint32_t flags =3D p->flags; + p->flags =3D 0; + if (p->sync_needed) { + p->flags |=3D MULTIFD_FLAG_SYNC; + p->sync_needed =3D false; + } p->normal_num =3D 0; =20 if (use_zero_copy_send) { @@ -689,14 +693,13 @@ static void *multifd_send_thread(void *opaque) } } multifd_send_fill_packet(p); - p->flags =3D 0; p->num_packets++; p->total_normal_pages +=3D p->normal_num; p->pages->num =3D 0; p->pages->block =3D NULL; qemu_mutex_unlock(&p->mutex); =20 - trace_multifd_send(p->id, packet_num, p->normal_num, flags, + trace_multifd_send(p->id, packet_num, p->normal_num, p->flags, p->next_packet_size); =20 if (use_zero_copy_send) { @@ -724,7 +727,7 @@ static void *multifd_send_thread(void *opaque) p->pending_job--; qemu_mutex_unlock(&p->mutex); =20 - if (flags & MULTIFD_FLAG_SYNC) { + if (p->flags & MULTIFD_FLAG_SYNC) { qemu_sem_post(&p->sem_sync); } qemu_sem_post(&multifd_send_state->channels_ready); @@ -1099,7 +1102,7 @@ static void *multifd_recv_thread(void *opaque) rcu_register_thread(); =20 while (true) { - uint32_t flags; + bool sync_needed =3D false; =20 if (p->quit) { break; @@ -1121,11 +1124,11 @@ static void *multifd_recv_thread(void *opaque) break; } =20 - flags =3D p->flags; + trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags, + p->next_packet_size); + sync_needed =3D p->flags & MULTIFD_FLAG_SYNC; /* recv methods don't know how to handle the SYNC flag */ p->flags &=3D ~MULTIFD_FLAG_SYNC; - trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags, - p->next_packet_size); p->num_packets++; p->total_normal_pages +=3D p->normal_num; qemu_mutex_unlock(&p->mutex); @@ -1137,7 +1140,7 @@ static void *multifd_recv_thread(void *opaque) } } =20 - if (flags & MULTIFD_FLAG_SYNC) { + if (sync_needed) { qemu_sem_post(&multifd_recv_state->sem_sync); qemu_sem_wait(&p->sem_sync); } --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066286; cv=none; d=zohomail.com; s=zohoarc; b=jR0mdX/4BevRTnNAQzGjRJKuqYp1wM6rKW3hquJcZ71W3SlxIuBRXFPGqEz33G6DwnsPZTxaIX33wdF25V2l9i4/ro1MRek/RqLHrrm+pZq6srM9VVFRyApG+v4WslU2KLKZf6UJw48Izj9jLzjMJ6yAMhoMjmm5T0J8qTrWMhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066286; 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=jsrXu9wL6HcpTtqw1FtRK4iQ5uaKV2xOq9pWRRptEL8=; b=ZbeuRpf4yIj6PjxauiiSvsWFYk20Pqlrn3bAr+FaCzZS0975ra8asT9y4dnvKDPVjTgFa8NtDYtHTknxjnrYxekrLoQ9tKbpyvKyNvSzYAWHY1BKQsQy6GCYQ6LzpRX2UEhwPebtobTk86DtfSlVnZRrZdi5eRK4/u90u3Cw6ow= 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+importer2=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 1675066286181206.9604388559792; Mon, 30 Jan 2023 00:11:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPFK-0000rC-Pm; Mon, 30 Jan 2023 03:10:34 -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 1pMPFE-0000l6-Hp for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:33 -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 1pMPFD-0002J9-2O for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:28 -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-457-j1CYt137MTmZ5Tzto6LhuQ-1; Mon, 30 Jan 2023 03:10:23 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8ADC32A5955C; Mon, 30 Jan 2023 08:10:22 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id C319140C2064; Mon, 30 Jan 2023 08:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066226; 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=jsrXu9wL6HcpTtqw1FtRK4iQ5uaKV2xOq9pWRRptEL8=; b=CzmQQrkKgHDHN3U7qZDSzB+sXYHDj4UCiMIRPFp7mAtQyBI0sTGtWOb87vzFwaWUacT7TO 42WncNale9q6hnnGSom3OqeG+cFUJ7fSfLSvHnxpQuvfQmG/5/FEQCnsy6ZAh46kAYNVn1 MyAi2UIZXuLMQxhWKKXBRKuIjHQIIAM= X-MC-Unique: j1CYt137MTmZ5Tzto6LhuQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 07/11] multifd: Prepare to send a packet without the mutex held Date: Mon, 30 Jan 2023 09:09:52 +0100 Message-Id: <20230130080956.3047-8-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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: -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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066286520100009 Content-Type: text/plain; charset="utf-8" We do the send_prepare() and the fill of the head packet without the mutex held. It will help a lot for compression and later in the series for zero pages. Notice that we can use p->pages without holding p->mutex because p->pending_job =3D=3D 1. Signed-off-by: Juan Quintela --- migration/multifd.h | 2 ++ migration/multifd.c | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index a67cefc0a2..cd389d18d2 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -109,7 +109,9 @@ typedef struct { /* array of pages to sent. * The owner of 'pages' depends of 'pending_job' value: * pending_job =3D=3D 0 -> migration_thread can use it. + * No need for mutex lock. * pending_job !=3D 0 -> multifd_channel can use it. + * No need for mutex lock. */ MultiFDPages_t *pages; =20 diff --git a/migration/multifd.c b/migration/multifd.c index 77196a55b4..7ebaca6e55 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -672,6 +672,8 @@ static void *multifd_send_thread(void *opaque) p->flags |=3D MULTIFD_FLAG_SYNC; p->sync_needed =3D false; } + qemu_mutex_unlock(&p->mutex); + p->normal_num =3D 0; =20 if (use_zero_copy_send) { @@ -688,16 +690,10 @@ static void *multifd_send_thread(void *opaque) if (p->normal_num) { ret =3D multifd_send_state->ops->send_prepare(p, &local_er= r); if (ret !=3D 0) { - qemu_mutex_unlock(&p->mutex); break; } } multifd_send_fill_packet(p); - p->num_packets++; - p->total_normal_pages +=3D p->normal_num; - p->pages->num =3D 0; - p->pages->block =3D NULL; - qemu_mutex_unlock(&p->mutex); =20 trace_multifd_send(p->id, packet_num, p->normal_num, p->flags, p->next_packet_size); @@ -722,6 +718,10 @@ static void *multifd_send_thread(void *opaque) } =20 qemu_mutex_lock(&p->mutex); + p->num_packets++; + p->total_normal_pages +=3D p->normal_num; + p->pages->num =3D 0; + p->pages->block =3D NULL; p->sent_bytes +=3D p->packet_len; p->sent_bytes +=3D p->next_packet_size; p->pending_job--; --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066282; cv=none; d=zohomail.com; s=zohoarc; b=L1g7OGkzigHgBEBAwtAswCGgsZ/nmfI9vVXnDfs4kTczLjdF687bi0dU8PZwgHT+0aEmIznqKcdj5RpDUixMgWJ9sYCBCkuDXYIcGBIPSCPNzhEuRjOKajf0fBmAkora2eQDvnOjI63pbxEEwhD60EziYJ2zTvjPBB3SGnf+qR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066282; 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=EwKAI/fpX8Q7yfr7M5xi5v2RQmqe+X0CoZ3j9DbhF08=; b=iLuUpyJ+9MOJ2Y5EruX4aGyTNDwC04rnX2Yr6FElyRSBRJ77BYV+eCbcXfoEaIJlDDv/MxhlTcD59hPOc/14pYuXmuS6nIKxuMHrTbwmlVPwUDq9MBd1dZr0CCsMUQkoHFGWAeD+LEJhD3vqchYMZxZvCHQcuvKouGZyYN18aw0= 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+importer2=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 1675066282452984.0383867630718; Mon, 30 Jan 2023 00:11:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPFL-0000vL-L2; Mon, 30 Jan 2023 03:10:35 -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 1pMPFJ-0000oL-HQ for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:33 -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 1pMPFH-0002Mv-Ow for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:33 -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-325-UfhRoTVtPwqRJBOa_Sv9Gg-1; Mon, 30 Jan 2023 03:10:24 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 73A7B1C07584; Mon, 30 Jan 2023 08:10:24 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFBF140C2064; Mon, 30 Jan 2023 08:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066231; 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=EwKAI/fpX8Q7yfr7M5xi5v2RQmqe+X0CoZ3j9DbhF08=; b=Mi0gfw8KHR4jBnMuah5dxc5INZi7lokVMWyzyHnAFk26PgHyVhW5opUNWu1/kumIkVBjV6 hv/4rbpwLEHhwdZNoufK+cyvF0ejs+1Z4PtY5xNLKSYiRU1CA9iouz/UawpO48OInI6R5r WqDcREoPPy3UQy5AddGNmWiGyG5WNbk= X-MC-Unique: UfhRoTVtPwqRJBOa_Sv9Gg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 08/11] multifd: Add capability to enable/disable zero_page Date: Mon, 30 Jan 2023 09:09:53 +0100 Message-Id: <20230130080956.3047-9-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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: -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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066284660100006 Content-Type: text/plain; charset="utf-8" We have to enable it by default until we introduce the new code. Signed-off-by: Juan Quintela --- Change it to a capability. As capabilities are off by default, have to change MULTIFD_ZERO_PAGE to MAIN_ZERO_PAGE, so it is false for default, and true for older versions. --- qapi/migration.json | 8 +++++++- migration/migration.h | 1 + hw/core/machine.c | 1 + migration/migration.c | 13 ++++++++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 88ecf86ac8..ac5bc071a9 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -472,12 +472,18 @@ # Requires that QEMU be permitted to use locked memory # for guest RAM pages. # (since 7.1) +# # @postcopy-preempt: If enabled, the migration process will allow postcopy # requests to preempt precopy stream, so postcopy reque= sts # will be handled faster. This is a performance featur= e and # should not affect the correctness of postcopy migrati= on. # (since 7.1) # +# @main-zero-page: If enabled, the detection of zero pages will be +# done on the main thread. Otherwise it is done on +# the multifd threads. +# (since 8.0) +# # Features: # @unstable: Members @x-colo and @x-ignore-shared are experimental. # @@ -492,7 +498,7 @@ 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', - 'zero-copy-send', 'postcopy-preempt'] } + 'zero-copy-send', 'postcopy-preempt', 'main-zero-page'] } =20 ## # @MigrationCapabilityStatus: diff --git a/migration/migration.h b/migration/migration.h index ae4ffd3454..c38a0baf10 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -408,6 +408,7 @@ int migrate_multifd_channels(void); MultiFDCompression migrate_multifd_compression(void); int migrate_multifd_zlib_level(void); int migrate_multifd_zstd_level(void); +bool migrate_use_main_zero_page(void); =20 #ifdef CONFIG_LINUX bool migrate_use_zero_copy_send(void); diff --git a/hw/core/machine.c b/hw/core/machine.c index 616f3a207c..97149e2de3 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -52,6 +52,7 @@ const size_t hw_compat_7_1_len =3D G_N_ELEMENTS(hw_compat= _7_1); GlobalProperty hw_compat_7_0[] =3D { { "arm-gicv3-common", "force-8-bit-prio", "on" }, { "nvme-ns", "eui64-default", "on"}, + { "migration", "main-zero-page", "true" }, }; const size_t hw_compat_7_0_len =3D G_N_ELEMENTS(hw_compat_7_0); =20 diff --git a/migration/migration.c b/migration/migration.c index d261c7d16d..ab86c6601d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -164,7 +164,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snaps= hot, MIGRATION_CAPABILITY_XBZRLE, MIGRATION_CAPABILITY_X_COLO, MIGRATION_CAPABILITY_VALIDATE_UUID, - MIGRATION_CAPABILITY_ZERO_COPY_SEND); + MIGRATION_CAPABILITY_ZERO_COPY_SEND, + MIGRATION_CAPABILITY_MAIN_ZERO_PAGE); =20 /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add @@ -2603,6 +2604,14 @@ bool migrate_use_multifd(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_MULTIFD]; } =20 +bool migrate_use_main_zero_page(void) +{ + MigrationState *s =3D migrate_get_current(); + + /* We will enable this when we add the right code. */ + return true || s->enabled_capabilities[MIGRATION_CAPABILITY_MAIN_ZERO_= PAGE]; +} + bool migrate_pause_before_switchover(void) { MigrationState *s; @@ -4425,6 +4434,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-zero-copy-send", MIGRATION_CAPABILITY_ZERO_COPY_SEND), #endif + DEFINE_PROP_MIG_CAP("main-zero-page", + MIGRATION_CAPABILITY_MAIN_ZERO_PAGE), =20 DEFINE_PROP_END_OF_LIST(), }; --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066301; cv=none; d=zohomail.com; s=zohoarc; b=cztjL0ilQAgJNg3dfQ/UjRFswOTL8p62b4GBwu74tJvdqZGEPtwKqrqtsJQ0aObZ3X8jfEhea78ITzTxBSGwa+bily+lNBouhpJNpxshaOrUBPy+bK/HWT0hOZAv/6gSEQcmDlpIVzwNLbvNosJP44eEHxIF9EsJ9MQZu68kjOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066301; 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=as5MwBatsU7CS8sKYgJmkcVR8XfOAFljHNVz+6YSA4g=; b=IImQ/bHsimnX9786u2XZD5e1WzKuDfqiDv7mLMqZRB1q8sPaJdjzfWff+6Wm02UMECyeYU4JAKqwyN0YABNi3lbroUlotmGnVSz8cp7L2eEmHXK1lk5wJFCgcrWOmH5QTHGafaX8p48nz78zwSYrGCpa0M6kX6Dz6yDLATwBI/U= 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+importer2=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 167506630136359.703149471194024; Mon, 30 Jan 2023 00:11:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPFO-000129-1C; Mon, 30 Jan 2023 03:10:38 -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 1pMPFL-0000wm-T9 for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:35 -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 1pMPFJ-0002Nh-TE for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:35 -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-221-d9rKwEfqMniVnPnMWPOJog-1; Mon, 30 Jan 2023 03:10:26 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C1A480006E; Mon, 30 Jan 2023 08:10:26 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id BADA640C2064; Mon, 30 Jan 2023 08:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066233; 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=as5MwBatsU7CS8sKYgJmkcVR8XfOAFljHNVz+6YSA4g=; b=Oh9cdgEMR3JaxMn/VczynrOWH6vDsQVFaQoVDjvURQILuljSyKYYUwDtBcaduNWwMNAMdA sYqbU7Hsh142l0pFcQTkkZA101jsOtijEcGP8LEJoptmurPWq2spadh0TWpqH7D6fzoiPe O3IYKCHsZqwHS4+blsW2ZXSypQCNZIU= X-MC-Unique: d9rKwEfqMniVnPnMWPOJog-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 09/11] multifd: Support for zero pages transmission Date: Mon, 30 Jan 2023 09:09:54 +0100 Message-Id: <20230130080956.3047-10-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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: -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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066302636100009 Content-Type: text/plain; charset="utf-8" This patch adds counters and similar. Logic will be added on the following patch. Signed-off-by: Juan Quintela --- Added counters for duplicated/non duplicated pages. Removed reviewed by from David. Add total_zero_pages --- migration/multifd.h | 17 ++++++++++++++++- migration/multifd.c | 36 +++++++++++++++++++++++++++++------- migration/ram.c | 2 -- migration/trace-events | 8 ++++---- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index cd389d18d2..a1b852200d 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -47,7 +47,10 @@ typedef struct { /* size of the next packet that contains pages */ uint32_t next_packet_size; uint64_t packet_num; - uint64_t unused[4]; /* Reserved for future use */ + /* zero pages */ + uint32_t zero_pages; + uint32_t unused32[1]; /* Reserved for future use */ + uint64_t unused64[3]; /* Reserved for future use */ char ramblock[256]; uint64_t offset[]; } __attribute__((packed)) MultiFDPacket_t; @@ -127,6 +130,8 @@ typedef struct { uint64_t num_packets; /* non zero pages sent through this channel */ uint64_t total_normal_pages; + /* zero pages sent through this channel */ + uint64_t total_zero_pages; /* buffers to send */ struct iovec *iov; /* number of iovs used */ @@ -135,6 +140,10 @@ typedef struct { ram_addr_t *normal; /* num of non zero pages */ uint32_t normal_num; + /* Pages that are zero */ + ram_addr_t *zero; + /* num of zero pages */ + uint32_t zero_num; /* used for compression methods */ void *data; } MultiFDSendParams; @@ -184,12 +193,18 @@ typedef struct { uint8_t *host; /* non zero pages recv through this channel */ uint64_t total_normal_pages; + /* zero pages recv through this channel */ + uint64_t total_zero_pages; /* buffers to recv */ struct iovec *iov; /* Pages that are not zero */ ram_addr_t *normal; /* num of non zero pages */ uint32_t normal_num; + /* Pages that are zero */ + ram_addr_t *zero; + /* num of zero pages */ + uint32_t zero_num; /* used for de-compression methods */ void *data; } MultiFDRecvParams; diff --git a/migration/multifd.c b/migration/multifd.c index 7ebaca6e55..30cc206190 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -263,6 +263,7 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) packet->normal_pages =3D cpu_to_be32(p->normal_num); packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); packet->packet_num =3D cpu_to_be64(p->packet_num); + packet->zero_pages =3D cpu_to_be32(p->zero_num); =20 if (p->pages->block) { strncpy(packet->ramblock, p->pages->block->idstr, 256); @@ -323,7 +324,15 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); p->packet_num =3D be64_to_cpu(packet->packet_num); =20 - if (p->normal_num =3D=3D 0) { + p->zero_num =3D be32_to_cpu(packet->zero_pages); + if (p->zero_num > packet->pages_alloc - p->normal_num) { + error_setg(errp, "multifd: received packet " + "with %u zero pages and expected maximum pages are %u", + p->zero_num, packet->pages_alloc - p->normal_num) ; + return -1; + } + + if (p->normal_num =3D=3D 0 && p->zero_num =3D=3D 0) { return 0; } =20 @@ -428,6 +437,8 @@ 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; + stat64_add(&ram_atomic_counters.normal, p->normal_num); + stat64_add(&ram_atomic_counters.duplicate, p->zero_num); uint64_t transferred =3D p->sent_bytes; p->sent_bytes =3D 0; qemu_file_acct_rate_limit(f, transferred); @@ -546,6 +557,8 @@ void multifd_save_cleanup(void) p->iov =3D NULL; g_free(p->normal); p->normal =3D NULL; + g_free(p->zero); + p->zero =3D NULL; multifd_send_state->ops->send_cleanup(p, &local_err); if (local_err) { migrate_set_error(migrate_get_current(), local_err); @@ -675,6 +688,7 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(&p->mutex); =20 p->normal_num =3D 0; + p->zero_num =3D 0; =20 if (use_zero_copy_send) { p->iovs_num =3D 0; @@ -695,8 +709,8 @@ static void *multifd_send_thread(void *opaque) } multifd_send_fill_packet(p); =20 - trace_multifd_send(p->id, packet_num, p->normal_num, p->flags, - p->next_packet_size); + trace_multifd_send(p->id, packet_num, p->normal_num, p->zero_n= um, + p->flags, p->next_packet_size); =20 if (use_zero_copy_send) { /* Send header first, without zerocopy */ @@ -720,6 +734,7 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(&p->mutex); p->num_packets++; p->total_normal_pages +=3D p->normal_num; + p->total_zero_pages +=3D p->zero_num; p->pages->num =3D 0; p->pages->block =3D NULL; p->sent_bytes +=3D p->packet_len; @@ -761,7 +776,8 @@ out: qemu_mutex_unlock(&p->mutex); =20 rcu_unregister_thread(); - trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_p= ages); + trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_p= ages, + p->total_zero_pages); =20 return NULL; } @@ -946,6 +962,7 @@ int multifd_save_setup(Error **errp) p->normal =3D g_new0(ram_addr_t, page_count); p->page_size =3D qemu_target_page_size(); p->page_count =3D page_count; + p->zero =3D g_new0(ram_addr_t, page_count); =20 if (migrate_use_zero_copy_send()) { p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; @@ -1054,6 +1071,8 @@ int multifd_load_cleanup(Error **errp) p->iov =3D NULL; g_free(p->normal); p->normal =3D NULL; + g_free(p->zero); + p->zero =3D NULL; multifd_recv_state->ops->recv_cleanup(p); } qemu_sem_destroy(&multifd_recv_state->sem_sync); @@ -1124,13 +1143,14 @@ static void *multifd_recv_thread(void *opaque) break; } =20 - trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags, - p->next_packet_size); + trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->zero_nu= m, + p->flags, p->next_packet_size); sync_needed =3D p->flags & MULTIFD_FLAG_SYNC; /* recv methods don't know how to handle the SYNC flag */ p->flags &=3D ~MULTIFD_FLAG_SYNC; p->num_packets++; p->total_normal_pages +=3D p->normal_num; + p->total_normal_pages +=3D p->zero_num; qemu_mutex_unlock(&p->mutex); =20 if (p->normal_num) { @@ -1155,7 +1175,8 @@ static void *multifd_recv_thread(void *opaque) qemu_mutex_unlock(&p->mutex); =20 rcu_unregister_thread(); - trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_p= ages); + trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_p= ages, + p->total_zero_pages); =20 return NULL; } @@ -1195,6 +1216,7 @@ int multifd_load_setup(Error **errp) p->normal =3D g_new0(ram_addr_t, page_count); p->page_count =3D page_count; p->page_size =3D qemu_target_page_size(); + p->zero =3D g_new0(ram_addr_t, page_count); } =20 for (i =3D 0; i < thread_count; i++) { diff --git a/migration/ram.c b/migration/ram.c index 04e1093cdc..c70cc25169 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1426,8 +1426,6 @@ static int ram_save_multifd_page(QEMUFile *file, RAMB= lock *block, if (multifd_queue_page(file, block, offset) < 0) { return -1; } - stat64_add(&ram_atomic_counters.normal, 1); - return 1; } =20 diff --git a/migration/trace-events b/migration/trace-events index 67b65a70ff..3e85354dd1 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -121,21 +121,21 @@ postcopy_preempt_reset_channel(void) "" =20 # multifd.c multifd_new_send_channel_async(uint8_t id) "channel %u" -multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flag= s, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " pages %u f= lags 0x%x next packet size %u" +multifd_recv(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t ze= ro, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PR= Iu64 " normal pages %u zero pages %u flags 0x%x next packet size %u" multifd_recv_new_channel(uint8_t id) "channel %u" multifd_recv_sync_main(long packet_num) "packet num %ld" multifd_recv_sync_main_signal(uint8_t id) "channel %u" multifd_recv_sync_main_wait(uint8_t id) "channel %u" multifd_recv_terminate_threads(bool error) "error %d" -multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "cha= nnel %u packets %" PRIu64 " pages %" PRIu64 +multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t normal_page= s, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRI= u64 " zero pages %" PRIu64 multifd_recv_thread_start(uint8_t id) "%u" -multifd_send(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t fl= ags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal p= ages %u flags 0x%x next packet size %u" +multifd_send(uint8_t id, uint64_t packet_num, uint32_t normalpages, uint32= _t zero_pages, uint32_t flags, uint32_t next_packet_size) "channel %u packe= t_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet size= %u" multifd_send_error(uint8_t id) "channel %u" multifd_send_sync_main(long packet_num) "packet num %ld" multifd_send_sync_main_signal(uint8_t id) "channel %u" multifd_send_sync_main_wait(uint8_t id) "channel %u" multifd_send_terminate_threads(bool error) "error %d" -multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_page= s) "channel %u packets %" PRIu64 " normal pages %" PRIu64 +multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_page= s, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PR= Iu64 " zero pages %" PRIu64 multifd_send_thread_start(uint8_t id) "%u" multifd_tls_outgoing_handshake_start(void *ioc, void *tioc, const char *ho= stname) "ioc=3D%p tioc=3D%p hostname=3D%s" multifd_tls_outgoing_handshake_error(void *ioc, const char *err) "ioc=3D%p= err=3D%s" --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066261; cv=none; d=zohomail.com; s=zohoarc; b=UYGiR2lqQBpRP/w8nKvu/JfHzVgsnOl8bTPjJvHYKiMMv8gYIihQd1n8T+hl5m3PvZ0hjZ6rq/3m/orU3Y55ExilqbFl+oUGLnAr+NPgeg8/qHg3E2k8ePRtE/NO4xN6rFE+uu1coYiOq7PRRyEtlcTKYCWfND/602EglF4TjDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066261; 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=WWPXW0LXzfzhIjq4t7aMZbVP9GD0FY1VbevOWELLEBo=; b=cxnF+47Z6GRSe/FmkWIzxsXQuelFbptyHFDrbuuXMpumzktT9nlKR5Dr9NM51/QbMvKcfZ3jCPJ4rEB7G7czZk/tX0lTcjwS8LBTTSgBAhLSfbjYRab++8qEcjPeqniX/unLASJ7hrOPebiODzDUmxYCLaZBNWWUeIsKIIkD4Bc= 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+importer2=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 1675066261057847.6976998037635; Mon, 30 Jan 2023 00:11:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPFM-0000zJ-M8; Mon, 30 Jan 2023 03:10: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 1pMPFJ-0000oM-K7 for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:33 -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 1pMPFH-0002Mn-Hz for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:32 -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-344-Urgl6NKzPbqPeq5n-rMatA-1; Mon, 30 Jan 2023 03:10:28 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B0FF3C0F661; Mon, 30 Jan 2023 08:10:28 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id A42D940C2064; Mon, 30 Jan 2023 08:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066231; 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=WWPXW0LXzfzhIjq4t7aMZbVP9GD0FY1VbevOWELLEBo=; b=Nhqt2yfh2FyFqAxj1+HxEaKbS00g8pMh0X0VW2txPmRV7YjHNUXgbFdm8wypbvgi6tPmry E7lD6ryv8cSQ0RnxRNoClIzvO60vWpsjhuWiJP/iwlhDGEWpfG4608hJu3wMdss5dEKgZ3 zkLC94UJyacDZ2b/5C+8w/fWdbsykX8= X-MC-Unique: Urgl6NKzPbqPeq5n-rMatA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 10/11] multifd: Zero pages transmission Date: Mon, 30 Jan 2023 09:09:55 +0100 Message-Id: <20230130080956.3047-11-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066262427100007 Content-Type: text/plain; charset="utf-8" This implements the zero page dection and handling. Signed-off-by: Juan Quintela --- Add comment for offset (dave) Use local variables for offset/block to have shorter lines --- migration/multifd.h | 5 +++++ migration/multifd.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index a1b852200d..5931de6f86 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -52,6 +52,11 @@ typedef struct { uint32_t unused32[1]; /* Reserved for future use */ uint64_t unused64[3]; /* Reserved for future use */ char ramblock[256]; + /* + * This array contains the pointers to: + * - normal pages (initial normal_pages entries) + * - zero pages (following zero_pages entries) + */ uint64_t offset[]; } __attribute__((packed)) MultiFDPacket_t; =20 diff --git a/migration/multifd.c b/migration/multifd.c index 30cc206190..d3f82dad8a 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -11,6 +11,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/rcu.h" #include "exec/target_page.h" #include "sysemu/sysemu.h" @@ -275,6 +276,12 @@ static void multifd_send_fill_packet(MultiFDSendParams= *p) =20 packet->offset[i] =3D cpu_to_be64(temp); } + for (i =3D 0; i < p->zero_num; i++) { + /* there are architectures where ram_addr_t is 32 bit */ + uint64_t temp =3D p->zero[i]; + + packet->offset[p->normal_num + i] =3D cpu_to_be64(temp); + } } =20 static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) @@ -358,6 +365,18 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) p->normal[i] =3D offset; } =20 + for (i =3D 0; i < p->zero_num; i++) { + uint64_t offset =3D be64_to_cpu(packet->offset[p->normal_num + i]); + + if (offset > (block->used_length - p->page_size)) { + error_setg(errp, "multifd: offset too long %" PRIu64 + " (max " RAM_ADDR_FMT ")", + offset, block->used_length); + return -1; + } + p->zero[i] =3D offset; + } + return 0; } =20 @@ -657,6 +676,12 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; + /* + * older qemu don't understand zero page on multifd channel. To + * have capabilities "false" by default, we need to name it this + * way. + */ + bool use_multifd_zero_page =3D !migrate_use_main_zero_page(); int ret =3D 0; bool use_zero_copy_send =3D migrate_use_zero_copy_send(); =20 @@ -679,6 +704,7 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(&p->mutex); =20 if (p->pending_job) { + RAMBlock *rb =3D p->pages->block; uint64_t packet_num =3D p->packet_num; p->flags =3D 0; if (p->sync_needed) { @@ -697,8 +723,16 @@ static void *multifd_send_thread(void *opaque) } =20 for (int i =3D 0; i < p->pages->num; i++) { - p->normal[p->normal_num] =3D p->pages->offset[i]; - p->normal_num++; + uint64_t offset =3D p->pages->offset[i]; + if (use_multifd_zero_page && + buffer_is_zero(rb->host + offset, p->page_size)) { + p->zero[p->zero_num] =3D offset; + p->zero_num++; + ram_release_page(rb->idstr, offset); + } else { + p->normal[p->normal_num] =3D offset; + p->normal_num++; + } } =20 if (p->normal_num) { @@ -1160,6 +1194,13 @@ static void *multifd_recv_thread(void *opaque) } } =20 + for (int i =3D 0; i < p->zero_num; i++) { + void *page =3D p->host + p->zero[i]; + if (!buffer_is_zero(page, p->page_size)) { + memset(page, 0, p->page_size); + } + } + if (sync_needed) { qemu_sem_post(&multifd_recv_state->sem_sync); qemu_sem_wait(&p->sem_sync); --=20 2.39.1 From nobody Wed May 1 22:40:41 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675066303; cv=none; d=zohomail.com; s=zohoarc; b=h0yo+TiECN3gwHdGyNRhpzgPVAYbIcjjNk3dZqLn0OV8Qt/X5tXMcgnMWXYSAegROvyJtd1r/Opue17r6r/GGuSrwtrAjoVIil3DBB4erYVn97cLqlYip7aUZXlzm5KBVxLahBFKG8WHgwNgTk4clf+W2inZBjFwrU2GagtiYF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675066303; 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=WDr0yZWgH492HQiQBW1pbdsWGAijKkarILqKzc5p6lI=; b=ZLlWBFH4J1n2Q+bnAAaU+0yx3oR4NztGz0KrEV3z8QKqpIihxn0dWiugOdyF4KTzazYTv4s2aDpgijg5CwnCPVmR8BloDdFOwQkQ9RaBj3f1X/psLYkXxOIxdq3dzLh6kD9IgRH49c0HvS1ppSf8BVxk/b/BD70fuKefBEMz2bE= 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+importer2=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 1675066303168992.7984424758109; Mon, 30 Jan 2023 00:11:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMPFQ-00017x-4O; Mon, 30 Jan 2023 03:10:40 -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 1pMPFO-00014D-Ny for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:38 -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 1pMPFN-0002Nx-1I for qemu-devel@nongnu.org; Mon, 30 Jan 2023 03:10:38 -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-146-d865x8o0OqC7-ub9PZlnsQ-1; Mon, 30 Jan 2023 03:10:30 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF1871871D94; Mon, 30 Jan 2023 08:10:29 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7001440C2064; Mon, 30 Jan 2023 08:10:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675066236; 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=WDr0yZWgH492HQiQBW1pbdsWGAijKkarILqKzc5p6lI=; b=an3VGeeMIXuPCjYhsp5fhwoNn36gBEL6NblNh/6GE3Y032ZwjQWpY+HGqoWAqslSGdalob 2kvJrdWDAuR3lUrzHasM7346EPv4Wfo8IQpZWOGhaTu8ccHBNWc7+wXaOInItkzF1RSidi cdL1uctbm6/ga4YMM6u4Ijg4aMve9hc= X-MC-Unique: d865x8o0OqC7-ub9PZlnsQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , Marcel Apfelbaum , Yanan Wang , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Eduardo Habkost , Eric Blake Subject: [PATCH v2 11/11] So we use multifd to transmit zero pages. Date: Mon, 30 Jan 2023 09:09:56 +0100 Message-Id: <20230130080956.3047-12-quintela@redhat.com> In-Reply-To: <20230130080956.3047-1-quintela@redhat.com> References: <20230130080956.3047-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=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=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675066304599100013 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela --- - Check zero_page property before using new code (Dave) --- migration/migration.c | 3 +-- migration/ram.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index ab86c6601d..6293dee983 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2608,8 +2608,7 @@ bool migrate_use_main_zero_page(void) { MigrationState *s =3D migrate_get_current(); =20 - /* We will enable this when we add the right code. */ - return true || s->enabled_capabilities[MIGRATION_CAPABILITY_MAIN_ZERO_= PAGE]; + return s->enabled_capabilities[MIGRATION_CAPABILITY_MAIN_ZERO_PAGE]; } =20 bool migrate_pause_before_switchover(void) diff --git a/migration/ram.c b/migration/ram.c index c70cc25169..d375f2ccde 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2421,6 +2421,31 @@ out: return ret; } =20 +/** + * ram_save_target_page_multifd: save one target page + * + * Returns the number of pages written + * + * @rs: current RAM state + * @pss: data about the page we want to send + */ +static int ram_save_target_page_multifd(RAMState *rs, PageSearchStatus *ps= s) +{ + RAMBlock *block =3D pss->block; + ram_addr_t offset =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; + + if (!migration_in_postcopy()) { + return ram_save_multifd_page(pss->pss_channel, block, offset); + } + + int res =3D save_zero_page(pss, block, offset); + if (res > 0) { + return res; + } + + return ram_save_page(rs, pss); +} + /** * ram_save_host_page: save a whole host page * @@ -3223,7 +3248,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque) ram_control_after_iterate(f, RAM_CONTROL_SETUP); =20 migration_ops =3D g_malloc0(sizeof(MigrationOps)); - migration_ops->ram_save_target_page =3D ram_save_target_page_legacy; + if (migrate_use_multifd() && !migrate_use_main_zero_page()) { + migration_ops->ram_save_target_page =3D ram_save_target_page_multi= fd; + } else { + migration_ops->ram_save_target_page =3D ram_save_target_page_legac= y; + } + ret =3D multifd_send_sync_main(f); if (ret < 0) { return ret; --=20 2.39.1