From nobody Tue Nov 26 08:49: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=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1709260290; cv=none; d=zohomail.com; s=zohoarc; b=SUwyamU/8AFq3pJCYus+gAp2zWgIC0iT+vuY4liU1LZ1MSk+nA9aqaQRmVywO4JRZSjnPQOuyHCm1M6lbcX8NuZ3uWtRSJiFP28fH2THub2GAxK4DW+IJ49eu4s3My10zt6sDDqgW84zTZJOrynjTFgS0a9uxaIY2G0DydTtY3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709260290; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PxHV8roC2fjNMfvMvdxuHI9CffnQMqXm91qkh+DJCQw=; b=guvUgpWUEKZ1xKK24nEuuGZfrOcT5gUTptneLi5VOERFI75b/Q8cYoqDJxAlxYwbUGoUiYkcu6I5Oh7FcqUTjww1O0SGHpM/bh9xFmPEkC/yVwhk9XjTqTOz524Oy07RK1z913m19am/HpAdyJXXZkF7GjiGdC65unT5Rqp1ut4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709260290312590.9263953486504; Thu, 29 Feb 2024 18:31:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfseR-0003y3-FI; Thu, 29 Feb 2024 21:29:31 -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 1rfseQ-0003xk-5j for qemu-devel@nongnu.org; Thu, 29 Feb 2024 21:29:30 -0500 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfseO-0005PA-K8 for qemu-devel@nongnu.org; Thu, 29 Feb 2024 21:29:29 -0500 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-68f571be9ddso12293036d6.0 for ; Thu, 29 Feb 2024 18:29:28 -0800 (PST) Received: from n231-230-216.byted.org ([130.44.212.120]) by smtp.gmail.com with ESMTPSA id qo13-20020a056214590d00b0068d11cf887bsm1384107qvb.55.2024.02.29.18.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 18:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1709260167; x=1709864967; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PxHV8roC2fjNMfvMvdxuHI9CffnQMqXm91qkh+DJCQw=; b=UeTX4wiNdcfn8fEk80jfmdJhGNCH2jkbWNAVQld0oEUHscr3ykVSR41go+1A6usqAE yXA7mPrz96t/u4AR/VEPI+OAL2rG5e6aHQWRssRd0QHDf2mzHg/fcHwJ/1gb7Oj58Qlv 3mL0mV9E0viy3eUlCWl0R2p5oSVSkEjRqp9o5FFth/7rFg/ugTThWjzb5Au4I9mJMn12 y98EAFKTxHnzphGRJVOqfHoLwj/xkE/RQYnv9i7a2I/cG2b6Q2PkiqfRcxTbXxPjG5L5 Uk2W0yyzorTWrfutPxe28UH7f/Th0AtK1MyWTBmsZqPhAUMBoqgaL7d2Raj28/piRGKP K5YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709260167; x=1709864967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PxHV8roC2fjNMfvMvdxuHI9CffnQMqXm91qkh+DJCQw=; b=ZtsR04A68xl22HXeRNfEN+q9ymOO/z1wyPvu49tOHHtyiCGxDR4W/kLOj27hgcyubv gWTaqD352HG3lC4wm7qaSJOr9Ur7FJLR1QUUk7pe6dtsOgOIQNp/MzEhHP8adkXYXQRk g5pvDP7zj3Zo2coP6WuQkOWUXswBC0KmNLAoE5O53lJAJbB8/hv7Armpz7KkyU9DJ4Kt wln9tEyTujTESOxEDvrP4tJQRz8j24rGzg9Z2+bdve8KHx7MZzpYnsr3Mi31YM2RjmY3 tx7sn3gYsyH7WXZo+FvGrXfrq2oXPJVJNmb3TmUsXHYvhPFUoA5LngXpcCtTsVz6+Cga JmtA== X-Forwarded-Encrypted: i=1; AJvYcCWfeS9Ck85ZcczGk+nAI3yFVDj9ft8CaxKFvTB0xOLK6KeDQbtCDsHHTy+sHZKLgeH1indkPCw10qE+UuzCKM2TgUVESg4= X-Gm-Message-State: AOJu0Yy09XusL8zhVUXAuEn9ZuEkOnKK0yCG2gOFiB9PMM2BRCrHzKGl 7hPqJ7vR3OjO25emmI1VX3jK2PUJILouWDfXGdvCz5bSSL6VBNoqNbUVDti4T3k= X-Google-Smtp-Source: AGHT+IEsvuwiDHIehYUztD4V9Y3AFzD+uUaCTByOxeGLhLo5VYfEnJbjvXFFqFAYYgVKvUkV2xUmtw== X-Received: by 2002:a0c:f50c:0:b0:690:50c5:4b72 with SMTP id j12-20020a0cf50c000000b0069050c54b72mr468754qvm.52.1709260167598; Thu, 29 Feb 2024 18:29:27 -0800 (PST) From: Hao Xiang To: pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, peterx@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, lvivier@redhat.com, jdenemar@redhat.com, marcel.apfelbaum@gmail.com, philmd@linaro.org, wangyanan55@huawei.com, qemu-devel@nongnu.org Cc: Hao Xiang Subject: [PATCH v4 3/7] migration/multifd: Implement ram_save_target_page_multifd to handle multifd version of MigrationOps::ram_save_target_page. Date: Fri, 1 Mar 2024 02:28:25 +0000 Message-Id: <20240301022829.3390548-4-hao.xiang@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240301022829.3390548-1-hao.xiang@bytedance.com> References: <20240301022829.3390548-1-hao.xiang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::f31; envelope-from=hao.xiang@bytedance.com; helo=mail-qv1-xf31.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1709260292053100001 Content-Type: text/plain; charset="utf-8" 1. Add a dedicated handler for MigrationOps::ram_save_target_page in multifd live migration. 2. Refactor ram_save_target_page_legacy so that the legacy and multifd handlers don't have internal functions calling into each other. Signed-off-by: Hao Xiang Reviewed-by: Fabiano Rosas Message-Id: <20240226195654.934709-4-hao.xiang@bytedance.com> --- migration/ram.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index e1fa229acf..f9d6ea65cc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1122,10 +1122,6 @@ static int save_zero_page(RAMState *rs, PageSearchSt= atus *pss, QEMUFile *file =3D pss->pss_channel; int len =3D 0; =20 - if (migrate_zero_page_detection() =3D=3D ZERO_PAGE_DETECTION_NONE) { - return 0; - } - if (!buffer_is_zero(p, TARGET_PAGE_SIZE)) { return 0; } @@ -2045,7 +2041,6 @@ static bool save_compress_page(RAMState *rs, PageSear= chStatus *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; int res; =20 @@ -2061,17 +2056,34 @@ static int ram_save_target_page_legacy(RAMState *rs= , PageSearchStatus *pss) return 1; } =20 + return ram_save_page(rs, pss); +} + +/** + * ram_save_target_page_multifd: send one target page to multifd workers + * + * Returns 1 if the page was queued, -1 otherwise. + * + * @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; + /* - * Do not use multifd in postcopy as one whole host page should be - * placed. Meanwhile postcopy requires atomic update of pages, so even - * if host page size =3D=3D guest page size the dest guest during run = may - * still see partially copied pages which is data corruption. + * Backward compatibility support. While using multifd live + * migration, we still need to handle zero page checking on the + * migration main thread. */ - if (migrate_multifd() && !migration_in_postcopy()) { - return ram_save_multifd_page(block, offset); + if (migrate_zero_page_detection() =3D=3D ZERO_PAGE_DETECTION_LEGACY) { + if (save_zero_page(rs, pss, offset)) { + return 1; + } } =20 - return ram_save_page(rs, pss); + return ram_save_multifd_page(block, offset); } =20 /* Should be called before sending a host page */ @@ -2983,7 +2995,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque) } =20 migration_ops =3D g_malloc0(sizeof(MigrationOps)); - migration_ops->ram_save_target_page =3D ram_save_target_page_legacy; + + if (migrate_multifd()) { + 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; + } =20 bql_unlock(); ret =3D multifd_send_sync_main(); --=20 2.30.2