From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515998; cv=none; d=zohomail.com; s=zohoarc; b=FgorIaqRdcvYwqL/Z1sDwcpKSfzA+os9jTfP7wqwDfketjLcBH64ADTcIYGJxc53tirK5Hhd5wdC2Bz8HC6oxIiHs51Q5z8fHyguFKmzYzU0kU40BBUP+8E0xq5dGDOW4tMEZPmaz6eS5mLAJQu1e46fGDX4AbQLfqjvHGh192c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515998; 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=xtr1ul5ovyW20vpLM4Cci52AvWBkmI6LBuM6z6QgBA4=; b=kz4dJcqIh9HE3mUOteneNtvEF1OixyrHW5vY5u5JWdTpabPYH8zrvWnlMgpLTtOihGfwi0El+7a31uEaztfKj0Vlu5eI3mjcAcqWu3pIpy2nX3OI5S5SewZg+fx/jd1EP5Dgq2t7RqCZfJ2djDLA/b9lG2VBS8e+Kc1ouzjrJ8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515998679559.84160339993; Thu, 1 Aug 2024 05:39:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV25-0000DH-2U; Thu, 01 Aug 2024 08:35:49 -0400 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 1sZV1p-0008Pv-IN for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:34 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1h-0000jf-MN for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:31 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8A41A21A07; Thu, 1 Aug 2024 12:35:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 570AF13946; Thu, 1 Aug 2024 12:35:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IOPMBwiBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515721; h=from:from:reply-to: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=xtr1ul5ovyW20vpLM4Cci52AvWBkmI6LBuM6z6QgBA4=; b=sRzsZzur6MB0yQKJLItZSAAUtPVHyYBQ7eE3EdvzRrnrEPfjA1UgN1SxiNl27wiwxi9/eB +J3YFsj0/8cKUrd0xx8FMUc9MuDJ78FbR2do2GAHkABoBhsS6qGku4WClNe1TE3TR7uM5b gl4HqCZLoDdmOF93xjI26jGBj5eGbYc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515721; h=from:from:reply-to: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=xtr1ul5ovyW20vpLM4Cci52AvWBkmI6LBuM6z6QgBA4=; b=y85dVLy53hXuT8Mre4lrbhK1K09QwC62FLho8agulz4rMDO89OTsN+4aQgo1KK3DN2XlOo nTyA2yYwPeOVk+Bg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=sRzsZzur; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=y85dVLy5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515721; h=from:from:reply-to: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=xtr1ul5ovyW20vpLM4Cci52AvWBkmI6LBuM6z6QgBA4=; b=sRzsZzur6MB0yQKJLItZSAAUtPVHyYBQ7eE3EdvzRrnrEPfjA1UgN1SxiNl27wiwxi9/eB +J3YFsj0/8cKUrd0xx8FMUc9MuDJ78FbR2do2GAHkABoBhsS6qGku4WClNe1TE3TR7uM5b gl4HqCZLoDdmOF93xjI26jGBj5eGbYc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515721; h=from:from:reply-to: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=xtr1ul5ovyW20vpLM4Cci52AvWBkmI6LBuM6z6QgBA4=; b=y85dVLy53hXuT8Mre4lrbhK1K09QwC62FLho8agulz4rMDO89OTsN+4aQgo1KK3DN2XlOo nTyA2yYwPeOVk+Bg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 01/14] migration/multifd: Reduce access to p->pages Date: Thu, 1 Aug 2024 09:35:03 -0300 Message-Id: <20240801123516.4498-2-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Rspamd-Queue-Id: 8A41A21A07 X-Spam-Score: -2.81 X-Spamd-Result: default: False [-2.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515999886116600 Content-Type: text/plain; charset="utf-8" I'm about to replace the p->pages pointer with an opaque pointer, so do a cleanup now to reduce direct accesses to p->page, which makes the next diffs cleaner. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd-qpl.c | 8 +++++--- migration/multifd-uadk.c | 9 +++++---- migration/multifd-zlib.c | 2 +- migration/multifd-zstd.c | 2 +- migration/multifd.c | 13 +++++++------ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/migration/multifd-qpl.c b/migration/multifd-qpl.c index 9265098ee7..f8c84c52cf 100644 --- a/migration/multifd-qpl.c +++ b/migration/multifd-qpl.c @@ -404,13 +404,14 @@ retry: static void multifd_qpl_compress_pages_slow_path(MultiFDSendParams *p) { QplData *qpl =3D p->compress_data; + MultiFDPages_t *pages =3D p->pages; uint32_t size =3D p->page_size; qpl_job *job =3D qpl->sw_job; uint8_t *zbuf =3D qpl->zbuf; uint8_t *buf; =20 - for (int i =3D 0; i < p->pages->normal_num; i++) { - buf =3D p->pages->block->host + p->pages->offset[i]; + for (int i =3D 0; i < pages->normal_num; i++) { + buf =3D pages->block->host + pages->offset[i]; multifd_qpl_prepare_comp_job(job, buf, zbuf, size); if (qpl_execute_job(job) =3D=3D QPL_STS_OK) { multifd_qpl_fill_packet(i, p, zbuf, job->total_out); @@ -498,6 +499,7 @@ static void multifd_qpl_compress_pages(MultiFDSendParam= s *p) static int multifd_qpl_send_prepare(MultiFDSendParams *p, Error **errp) { QplData *qpl =3D p->compress_data; + MultiFDPages_t *pages =3D p->pages; uint32_t len =3D 0; =20 if (!multifd_send_prepare_common(p)) { @@ -505,7 +507,7 @@ static int multifd_qpl_send_prepare(MultiFDSendParams *= p, Error **errp) } =20 /* The first IOV is used to store the compressed page lengths */ - len =3D p->pages->normal_num * sizeof(uint32_t); + len =3D pages->normal_num * sizeof(uint32_t); multifd_qpl_fill_iov(p, (uint8_t *) qpl->zlen, len); if (qpl->hw_avail) { multifd_qpl_compress_pages(p); diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c index d12353fb21..b8ba3cd9c1 100644 --- a/migration/multifd-uadk.c +++ b/migration/multifd-uadk.c @@ -174,19 +174,20 @@ static int multifd_uadk_send_prepare(MultiFDSendParam= s *p, Error **errp) uint32_t hdr_size; uint8_t *buf =3D uadk_data->buf; int ret =3D 0; + MultiFDPages_t *pages =3D p->pages; =20 if (!multifd_send_prepare_common(p)) { goto out; } =20 - hdr_size =3D p->pages->normal_num * sizeof(uint32_t); + hdr_size =3D pages->normal_num * sizeof(uint32_t); /* prepare the header that stores the lengths of all compressed data */ prepare_next_iov(p, uadk_data->buf_hdr, hdr_size); =20 - for (int i =3D 0; i < p->pages->normal_num; i++) { + for (int i =3D 0; i < pages->normal_num; i++) { struct wd_comp_req creq =3D { .op_type =3D WD_DIR_COMPRESS, - .src =3D p->pages->block->host + p->pages->offset[i], + .src =3D pages->block->host + pages->offset[i], .src_len =3D p->page_size, .dst =3D buf, /* Set dst_len to double the src in case compressed out >=3D p= age_size */ @@ -214,7 +215,7 @@ static int multifd_uadk_send_prepare(MultiFDSendParams = *p, Error **errp) */ if (!uadk_data->handle || creq.dst_len >=3D p->page_size) { uadk_data->buf_hdr[i] =3D cpu_to_be32(p->page_size); - prepare_next_iov(p, p->pages->block->host + p->pages->offset[i= ], + prepare_next_iov(p, pages->block->host + pages->offset[i], p->page_size); buf +=3D p->page_size; } diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 2ced69487e..65f8aba5c8 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -147,7 +147,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) * with compression. zlib does not guarantee that this is safe, * therefore copy the page before calling deflate(). */ - memcpy(z->buf, p->pages->block->host + pages->offset[i], p->page_s= ize); + memcpy(z->buf, pages->block->host + pages->offset[i], p->page_size= ); zs->avail_in =3D p->page_size; zs->next_in =3D z->buf; =20 diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index ca17b7e310..cb6075a9a5 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -138,7 +138,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Erro= r **errp) if (i =3D=3D pages->normal_num - 1) { flush =3D ZSTD_e_flush; } - z->in.src =3D p->pages->block->host + pages->offset[i]; + z->in.src =3D pages->block->host + pages->offset[i]; z->in.size =3D p->page_size; z->in.pos =3D 0; =20 diff --git a/migration/multifd.c b/migration/multifd.c index 0b4cbaddfe..c95fce2222 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -114,11 +114,11 @@ static void multifd_set_file_bitmap(MultiFDSendParams= *p) =20 assert(pages->block); =20 - for (int i =3D 0; i < p->pages->normal_num; i++) { + for (int i =3D 0; i < pages->normal_num; i++) { ramblock_set_file_bmap_atomic(pages->block, pages->offset[i], true= ); } =20 - for (int i =3D p->pages->normal_num; i < p->pages->num; i++) { + for (int i =3D pages->normal_num; i < pages->num; i++) { ramblock_set_file_bmap_atomic(pages->block, pages->offset[i], fals= e); } } @@ -417,7 +417,7 @@ void multifd_send_fill_packet(MultiFDSendParams *p) int i; =20 packet->flags =3D cpu_to_be32(p->flags); - packet->pages_alloc =3D cpu_to_be32(p->pages->allocated); + packet->pages_alloc =3D cpu_to_be32(pages->allocated); packet->normal_pages =3D cpu_to_be32(pages->normal_num); packet->zero_pages =3D cpu_to_be32(zero_num); packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); @@ -953,7 +953,7 @@ static void *multifd_send_thread(void *opaque) =20 if (migrate_mapped_ram()) { ret =3D file_write_ramblock_iov(p->c, p->iov, p->iovs_num, - p->pages->block, &local_err); + pages->block, &local_err); } else { ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_= num, NULL, 0, p->write_flags, @@ -969,7 +969,7 @@ static void *multifd_send_thread(void *opaque) stat64_add(&mig_stats.normal_pages, pages->normal_num); stat64_add(&mig_stats.zero_pages, pages->num - pages->normal_n= um); =20 - multifd_pages_reset(p->pages); + multifd_pages_reset(pages); p->next_packet_size =3D 0; =20 /* @@ -1684,9 +1684,10 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error= **errp) =20 bool multifd_send_prepare_common(MultiFDSendParams *p) { + MultiFDPages_t *pages =3D p->pages; multifd_send_zero_page_detect(p); =20 - if (!p->pages->normal_num) { + if (!pages->normal_num) { p->next_packet_size =3D 0; return false; } --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515861; cv=none; d=zohomail.com; s=zohoarc; b=IGbd6Bi0ATGRh1cVTFX1jQKJH7hA3sOc1S4mCW2Z3EQalrJTp3pW+lpYdHSOcz+i/YVLOk9Y3ZvAGBK+KGCH0HdvIQEgkpjrNQ5jCl63WkdjSKuzhzP+Ul/TZ1JBtggxmmV98B9xTvJgZS+llL6PI35SlG51LJzr/avaYOawE6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515861; 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=xUfQd9R2IW77UUYsNK2Qc+20byTBl/3Mi82Hb8/lU4k=; b=RKQ0pW1PQ0mcgok0cFfzkpGZ54UHBNaTvQDAm9eJXD3Abx56+CTM3hJVJuPtbXKzR7ULN02QOMJJJfvacwpblMaThx/LC58AxNJS3QSxHSTg5vHrG+xnBryVxKqS/n/ASHU9/cJD1VCOB9wBqJkDU4k5ovRVJ7VTaahlfunlClc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515861896809.1836940427072; Thu, 1 Aug 2024 05:37:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV26-0000Jv-GD; Thu, 01 Aug 2024 08:35:50 -0400 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 1sZV1p-0008Pt-GV for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:34 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1h-0000jv-Ie for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:29 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 30E961FB4F; Thu, 1 Aug 2024 12:35:23 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0812F13946; Thu, 1 Aug 2024 12:35:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0BrCLwmBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515723; h=from:from:reply-to: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=xUfQd9R2IW77UUYsNK2Qc+20byTBl/3Mi82Hb8/lU4k=; b=r7Y8jR6Gm+DOwzDlYp8Q4idUQmM7d22SmHZcCcbEO8mqv0xH0pAqor6wimuwDaP2uCiO1+ MQ/ZmqLLkPZOoe0aT9jcm29ar17A2j1DAzCOLrhGhgitxqaiyW8DvZQcihhYml0xyghOYC 4DTnSkzxAgBeZXIJGD8BjtwatvUdx9U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515723; h=from:from:reply-to: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=xUfQd9R2IW77UUYsNK2Qc+20byTBl/3Mi82Hb8/lU4k=; b=CIJXQi5zWw6RXWCzlvAUr2/9l0wRoYCak0XWxjS9GuYM5pUbXsTqo3fATyhM4Ksx/Hy5ZD Og7WLieiBwAhy/Aw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=r7Y8jR6G; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CIJXQi5z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515723; h=from:from:reply-to: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=xUfQd9R2IW77UUYsNK2Qc+20byTBl/3Mi82Hb8/lU4k=; b=r7Y8jR6Gm+DOwzDlYp8Q4idUQmM7d22SmHZcCcbEO8mqv0xH0pAqor6wimuwDaP2uCiO1+ MQ/ZmqLLkPZOoe0aT9jcm29ar17A2j1DAzCOLrhGhgitxqaiyW8DvZQcihhYml0xyghOYC 4DTnSkzxAgBeZXIJGD8BjtwatvUdx9U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515723; h=from:from:reply-to: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=xUfQd9R2IW77UUYsNK2Qc+20byTBl/3Mi82Hb8/lU4k=; b=CIJXQi5zWw6RXWCzlvAUr2/9l0wRoYCak0XWxjS9GuYM5pUbXsTqo3fATyhM4Ksx/Hy5ZD Og7WLieiBwAhy/Aw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 02/14] migration/multifd: Inline page_size and page_count Date: Thu, 1 Aug 2024 09:35:04 -0300 Message-Id: <20240801123516.4498-3-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Spam-Score: -4.81 X-Rspamd-Queue-Id: 30E961FB4F 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515863368116600 Content-Type: text/plain; charset="utf-8" The MultiFD*Params structures are for per-channel data. Constant values should not be there because that needlessly wastes cycles and storage. The page_size and page_count fall into this category so move them inline in multifd.h. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd-qpl.c | 10 +++++++--- migration/multifd-uadk.c | 36 ++++++++++++++++++++--------------- migration/multifd-zero-page.c | 4 ++-- migration/multifd-zlib.c | 14 ++++++++------ migration/multifd-zstd.c | 11 ++++++----- migration/multifd.c | 33 ++++++++++++++++---------------- migration/multifd.h | 18 ++++++++++-------- 7 files changed, 71 insertions(+), 55 deletions(-) diff --git a/migration/multifd-qpl.c b/migration/multifd-qpl.c index f8c84c52cf..db60c05795 100644 --- a/migration/multifd-qpl.c +++ b/migration/multifd-qpl.c @@ -233,8 +233,10 @@ static void multifd_qpl_deinit(QplData *qpl) static int multifd_qpl_send_setup(MultiFDSendParams *p, Error **errp) { QplData *qpl; + uint32_t page_size =3D multifd_ram_page_size(); + uint32_t page_count =3D multifd_ram_page_count(); =20 - qpl =3D multifd_qpl_init(p->page_count, p->page_size, errp); + qpl =3D multifd_qpl_init(page_count, page_size, errp); if (!qpl) { return -1; } @@ -245,7 +247,7 @@ static int multifd_qpl_send_setup(MultiFDSendParams *p,= Error **errp) * additional two IOVs are used to store packet header and compressed = data * length */ - p->iov =3D g_new0(struct iovec, p->page_count + 2); + p->iov =3D g_new0(struct iovec, page_count + 2); return 0; } =20 @@ -534,8 +536,10 @@ out: static int multifd_qpl_recv_setup(MultiFDRecvParams *p, Error **errp) { QplData *qpl; + uint32_t page_size =3D multifd_ram_page_size(); + uint32_t page_count =3D multifd_ram_page_count(); =20 - qpl =3D multifd_qpl_init(p->page_count, p->page_size, errp); + qpl =3D multifd_qpl_init(page_count, page_size, errp); if (!qpl) { return -1; } diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c index b8ba3cd9c1..1ed1c6afe6 100644 --- a/migration/multifd-uadk.c +++ b/migration/multifd-uadk.c @@ -114,8 +114,10 @@ static void multifd_uadk_uninit_sess(struct wd_data *w= d) static int multifd_uadk_send_setup(MultiFDSendParams *p, Error **errp) { struct wd_data *wd; + uint32_t page_size =3D multifd_ram_page_size(); + uint32_t page_count =3D multifd_ram_page_count(); =20 - wd =3D multifd_uadk_init_sess(p->page_count, p->page_size, true, errp); + wd =3D multifd_uadk_init_sess(page_count, page_size, true, errp); if (!wd) { return -1; } @@ -128,7 +130,7 @@ static int multifd_uadk_send_setup(MultiFDSendParams *p= , Error **errp) * length */ =20 - p->iov =3D g_new0(struct iovec, p->page_count + 2); + p->iov =3D g_new0(struct iovec, page_count + 2); return 0; } =20 @@ -172,6 +174,7 @@ static int multifd_uadk_send_prepare(MultiFDSendParams = *p, Error **errp) { struct wd_data *uadk_data =3D p->compress_data; uint32_t hdr_size; + uint32_t page_size =3D multifd_ram_page_size(); uint8_t *buf =3D uadk_data->buf; int ret =3D 0; MultiFDPages_t *pages =3D p->pages; @@ -188,7 +191,7 @@ static int multifd_uadk_send_prepare(MultiFDSendParams = *p, Error **errp) struct wd_comp_req creq =3D { .op_type =3D WD_DIR_COMPRESS, .src =3D pages->block->host + pages->offset[i], - .src_len =3D p->page_size, + .src_len =3D page_size, .dst =3D buf, /* Set dst_len to double the src in case compressed out >=3D p= age_size */ .dst_len =3D p->page_size * 2, @@ -201,7 +204,7 @@ static int multifd_uadk_send_prepare(MultiFDSendParams = *p, Error **errp) p->id, ret, creq.status); return -1; } - if (creq.dst_len < p->page_size) { + if (creq.dst_len < page_size) { uadk_data->buf_hdr[i] =3D cpu_to_be32(creq.dst_len); prepare_next_iov(p, buf, creq.dst_len); buf +=3D creq.dst_len; @@ -213,11 +216,11 @@ static int multifd_uadk_send_prepare(MultiFDSendParam= s *p, Error **errp) * than page_size as well because at the receive end we can skip t= he * decompression. But it is tricky to find the right number here. */ - if (!uadk_data->handle || creq.dst_len >=3D p->page_size) { - uadk_data->buf_hdr[i] =3D cpu_to_be32(p->page_size); + if (!uadk_data->handle || creq.dst_len >=3D page_size) { + uadk_data->buf_hdr[i] =3D cpu_to_be32(page_size); prepare_next_iov(p, pages->block->host + pages->offset[i], - p->page_size); - buf +=3D p->page_size; + page_size); + buf +=3D page_size; } } out: @@ -239,8 +242,10 @@ out: static int multifd_uadk_recv_setup(MultiFDRecvParams *p, Error **errp) { struct wd_data *wd; + uint32_t page_size =3D multifd_ram_page_size(); + uint32_t page_count =3D multifd_ram_page_count(); =20 - wd =3D multifd_uadk_init_sess(p->page_count, p->page_size, false, errp= ); + wd =3D multifd_uadk_init_sess(page_count, page_size, false, errp); if (!wd) { return -1; } @@ -281,6 +286,7 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Erro= r **errp) uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; uint32_t hdr_len =3D p->normal_num * sizeof(uint32_t); uint32_t data_len =3D 0; + uint32_t page_size =3D multifd_ram_page_size(); uint8_t *buf =3D uadk_data->buf; int ret =3D 0; =20 @@ -307,7 +313,7 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Erro= r **errp) for (int i =3D 0; i < p->normal_num; i++) { uadk_data->buf_hdr[i] =3D be32_to_cpu(uadk_data->buf_hdr[i]); data_len +=3D uadk_data->buf_hdr[i]; - assert(uadk_data->buf_hdr[i] <=3D p->page_size); + assert(uadk_data->buf_hdr[i] <=3D page_size); } =20 /* read compressed data */ @@ -323,12 +329,12 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Er= ror **errp) .src =3D buf, .src_len =3D uadk_data->buf_hdr[i], .dst =3D p->host + p->normal[i], - .dst_len =3D p->page_size, + .dst_len =3D page_size, }; =20 - if (uadk_data->buf_hdr[i] =3D=3D p->page_size) { - memcpy(p->host + p->normal[i], buf, p->page_size); - buf +=3D p->page_size; + if (uadk_data->buf_hdr[i] =3D=3D page_size) { + memcpy(p->host + p->normal[i], buf, page_size); + buf +=3D page_size; continue; } =20 @@ -344,7 +350,7 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Erro= r **errp) p->id, ret, creq.status); return -1; } - if (creq.dst_len !=3D p->page_size) { + if (creq.dst_len !=3D page_size) { error_setg(errp, "multifd %u: decompressed length error", p->i= d); return -1; } diff --git a/migration/multifd-zero-page.c b/migration/multifd-zero-page.c index e1b8370f88..cc624e36b3 100644 --- a/migration/multifd-zero-page.c +++ b/migration/multifd-zero-page.c @@ -63,7 +63,7 @@ void multifd_send_zero_page_detect(MultiFDSendParams *p) while (i <=3D j) { uint64_t offset =3D pages->offset[i]; =20 - if (!buffer_is_zero(rb->host + offset, p->page_size)) { + if (!buffer_is_zero(rb->host + offset, multifd_ram_page_size())) { i++; continue; } @@ -81,7 +81,7 @@ void multifd_recv_zero_page_process(MultiFDRecvParams *p) for (int i =3D 0; i < p->zero_num; i++) { void *page =3D p->host + p->zero[i]; if (ramblock_recv_bitmap_test_byte_offset(p->block, p->zero[i])) { - memset(page, 0, p->page_size); + memset(page, 0, multifd_ram_page_size()); } else { ramblock_recv_bitmap_set_offset(p->block, p->zero[i]); } diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 65f8aba5c8..e47d7f70dc 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -127,6 +127,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) struct zlib_data *z =3D p->compress_data; z_stream *zs =3D &z->zs; uint32_t out_size =3D 0; + uint32_t page_size =3D multifd_ram_page_size(); int ret; uint32_t i; =20 @@ -147,8 +148,8 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) * with compression. zlib does not guarantee that this is safe, * therefore copy the page before calling deflate(). */ - memcpy(z->buf, pages->block->host + pages->offset[i], p->page_size= ); - zs->avail_in =3D p->page_size; + memcpy(z->buf, pages->block->host + pages->offset[i], page_size); + zs->avail_in =3D page_size; zs->next_in =3D z->buf; =20 zs->avail_out =3D available; @@ -260,7 +261,8 @@ static int zlib_recv(MultiFDRecvParams *p, Error **errp) uint32_t in_size =3D p->next_packet_size; /* we measure the change of total_out */ uint32_t out_size =3D zs->total_out; - uint32_t expected_size =3D p->normal_num * p->page_size; + uint32_t page_size =3D multifd_ram_page_size(); + uint32_t expected_size =3D p->normal_num * page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; int ret; int i; @@ -296,7 +298,7 @@ static int zlib_recv(MultiFDRecvParams *p, Error **errp) flush =3D Z_SYNC_FLUSH; } =20 - zs->avail_out =3D p->page_size; + zs->avail_out =3D page_size; zs->next_out =3D p->host + p->normal[i]; =20 /* @@ -310,8 +312,8 @@ static int zlib_recv(MultiFDRecvParams *p, Error **errp) do { ret =3D inflate(zs, flush); } while (ret =3D=3D Z_OK && zs->avail_in - && (zs->total_out - start) < p->page_size); - if (ret =3D=3D Z_OK && (zs->total_out - start) < p->page_size) { + && (zs->total_out - start) < page_size); + if (ret =3D=3D Z_OK && (zs->total_out - start) < page_size) { error_setg(errp, "multifd %u: inflate generated too few output= ", p->id); return -1; diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index cb6075a9a5..1812fd1b48 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -139,7 +139,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Erro= r **errp) flush =3D ZSTD_e_flush; } z->in.src =3D pages->block->host + pages->offset[i]; - z->in.size =3D p->page_size; + z->in.size =3D multifd_ram_page_size(); z->in.pos =3D 0; =20 /* @@ -254,7 +254,8 @@ static int zstd_recv(MultiFDRecvParams *p, Error **errp) { uint32_t in_size =3D p->next_packet_size; uint32_t out_size =3D 0; - uint32_t expected_size =3D p->normal_num * p->page_size; + uint32_t page_size =3D multifd_ram_page_size(); + uint32_t expected_size =3D p->normal_num * page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; struct zstd_data *z =3D p->compress_data; int ret; @@ -286,7 +287,7 @@ static int zstd_recv(MultiFDRecvParams *p, Error **errp) for (i =3D 0; i < p->normal_num; i++) { ramblock_recv_bitmap_set_offset(p->block, p->normal[i]); z->out.dst =3D p->host + p->normal[i]; - z->out.size =3D p->page_size; + z->out.size =3D page_size; z->out.pos =3D 0; =20 /* @@ -300,8 +301,8 @@ static int zstd_recv(MultiFDRecvParams *p, Error **errp) do { ret =3D ZSTD_decompressStream(z->zds, &z->out, &z->in); } while (ret > 0 && (z->in.size - z->in.pos > 0) - && (z->out.pos < p->page_size)); - if (ret > 0 && (z->out.pos < p->page_size)) { + && (z->out.pos < page_size)); + if (ret > 0 && (z->out.pos < page_size)) { error_setg(errp, "multifd %u: decompressStream buffer too smal= l", p->id); return -1; diff --git a/migration/multifd.c b/migration/multifd.c index c95fce2222..33f91c9561 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -133,15 +133,17 @@ static void multifd_set_file_bitmap(MultiFDSendParams= *p) */ static int nocomp_send_setup(MultiFDSendParams *p, Error **errp) { + uint32_t page_count =3D multifd_ram_page_count(); + if (migrate_zero_copy_send()) { p->write_flags |=3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; } =20 if (multifd_use_packets()) { /* We need one extra place for the packet header */ - p->iov =3D g_new0(struct iovec, p->page_count + 1); + p->iov =3D g_new0(struct iovec, page_count + 1); } else { - p->iov =3D g_new0(struct iovec, p->page_count); + p->iov =3D g_new0(struct iovec, page_count); } =20 return 0; @@ -165,14 +167,15 @@ static void nocomp_send_cleanup(MultiFDSendParams *p,= Error **errp) static void multifd_send_prepare_iovs(MultiFDSendParams *p) { MultiFDPages_t *pages =3D p->pages; + uint32_t page_size =3D multifd_ram_page_size(); =20 for (int i =3D 0; i < pages->normal_num; i++) { p->iov[p->iovs_num].iov_base =3D pages->block->host + pages->offse= t[i]; - p->iov[p->iovs_num].iov_len =3D p->page_size; + p->iov[p->iovs_num].iov_len =3D page_size; p->iovs_num++; } =20 - p->next_packet_size =3D pages->normal_num * p->page_size; + p->next_packet_size =3D pages->normal_num * page_size; } =20 /** @@ -237,7 +240,7 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Er= ror **errp) */ static int nocomp_recv_setup(MultiFDRecvParams *p, Error **errp) { - p->iov =3D g_new0(struct iovec, p->page_count); + p->iov =3D g_new0(struct iovec, multifd_ram_page_count()); return 0; } =20 @@ -288,7 +291,7 @@ static int nocomp_recv(MultiFDRecvParams *p, Error **er= rp) =20 for (int i =3D 0; i < p->normal_num; i++) { p->iov[i].iov_base =3D p->host + p->normal[i]; - p->iov[i].iov_len =3D p->page_size; + p->iov[i].iov_len =3D multifd_ram_page_size(); ramblock_recv_bitmap_set_offset(p->block, p->normal[i]); } return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); @@ -447,6 +450,8 @@ void multifd_send_fill_packet(MultiFDSendParams *p) static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) { MultiFDPacket_t *packet =3D p->packet; + uint32_t page_count =3D multifd_ram_page_count(); + uint32_t page_size =3D multifd_ram_page_size(); int i; =20 packet->magic =3D be32_to_cpu(packet->magic); @@ -472,10 +477,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvPara= ms *p, Error **errp) * If we received a packet that is 100 times bigger than expected * just stop migration. It is a magic number. */ - if (packet->pages_alloc > p->page_count) { + if (packet->pages_alloc > page_count) { error_setg(errp, "multifd: received packet " "with size %u and expected a size of %u", - packet->pages_alloc, p->page_count) ; + packet->pages_alloc, page_count) ; return -1; } =20 @@ -521,7 +526,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) for (i =3D 0; i < p->normal_num; i++) { uint64_t offset =3D be64_to_cpu(packet->offset[i]); =20 - if (offset > (p->block->used_length - p->page_size)) { + if (offset > (p->block->used_length - page_size)) { error_setg(errp, "multifd: offset too long %" PRIu64 " (max " RAM_ADDR_FMT ")", offset, p->block->used_length); @@ -533,7 +538,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) for (i =3D 0; i < p->zero_num; i++) { uint64_t offset =3D be64_to_cpu(packet->offset[p->normal_num + i]); =20 - if (offset > (p->block->used_length - p->page_size)) { + if (offset > (p->block->used_length - page_size)) { error_setg(errp, "multifd: offset too long %" PRIu64 " (max " RAM_ADDR_FMT ")", offset, p->block->used_length); @@ -1158,7 +1163,7 @@ bool multifd_send_setup(void) MigrationState *s =3D migrate_get_current(); Error *local_err =3D NULL; int thread_count, ret =3D 0; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + uint32_t page_count =3D multifd_ram_page_count(); bool use_packets =3D multifd_use_packets(); uint8_t i; =20 @@ -1191,8 +1196,6 @@ bool multifd_send_setup(void) p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); } p->name =3D g_strdup_printf("mig/src/send_%d", i); - p->page_size =3D qemu_target_page_size(); - p->page_count =3D page_count; p->write_flags =3D 0; =20 if (!multifd_new_send_channel_create(p, &local_err)) { @@ -1563,7 +1566,7 @@ static void *multifd_recv_thread(void *opaque) int multifd_recv_setup(Error **errp) { int thread_count; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + uint32_t page_count =3D multifd_ram_page_count(); bool use_packets =3D multifd_use_packets(); uint8_t i; =20 @@ -1607,8 +1610,6 @@ int multifd_recv_setup(Error **errp) p->name =3D g_strdup_printf("mig/dst/recv_%d", i); p->normal =3D g_new0(ram_addr_t, page_count); p->zero =3D g_new0(ram_addr_t, page_count); - p->page_count =3D page_count; - p->page_size =3D qemu_target_page_size(); } =20 for (i =3D 0; i < thread_count; i++) { diff --git a/migration/multifd.h b/migration/multifd.h index 0ecd6f47d7..a2bba23af9 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -13,6 +13,7 @@ #ifndef QEMU_MIGRATION_MULTIFD_H #define QEMU_MIGRATION_MULTIFD_H =20 +#include "exec/target_page.h" #include "ram.h" =20 typedef struct MultiFDRecvData MultiFDRecvData; @@ -106,10 +107,6 @@ typedef struct { QIOChannel *c; /* packet allocated len */ uint32_t packet_len; - /* guest page size */ - uint32_t page_size; - /* number of pages in a full packet */ - uint32_t page_count; /* multifd flags for sending ram */ int write_flags; =20 @@ -173,10 +170,6 @@ typedef struct { QIOChannel *c; /* packet allocated len */ uint32_t packet_len; - /* guest page size */ - uint32_t page_size; - /* number of pages in a full packet */ - uint32_t page_count; =20 /* syncs main thread and channels */ QemuSemaphore sem_sync; @@ -254,4 +247,13 @@ static inline void multifd_send_prepare_header(MultiFD= SendParams *p) =20 void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc); =20 +static inline uint32_t multifd_ram_page_size(void) +{ + return qemu_target_page_size(); +} + +static inline uint32_t multifd_ram_page_count(void) +{ + return MULTIFD_PACKET_SIZE / qemu_target_page_size(); +} #endif --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515787; cv=none; d=zohomail.com; s=zohoarc; b=kq3J3Ei0MM/JcMBkZS7wOgzUkR5/b2p2sh2eog0RLmeQ+9nuIsAcvyEqRqbg3nyGPKN3piC8NflLrp6H7671jiclrhzsIIkCHjRbffCa5ZNYXCDEnBhnscxyVubLnrrk7EfvHDWn2G1rKoCs2WsEIriSV9fz5Zlo/MgLdUeyFzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515787; 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=nlbdlyS3wD1Vr1zi5TCYT5nsVT27+ZPER/70Lu/RqYE=; b=bRKXZTD/6SpCzOX2uBmCcR+46byFNTVEQRoTTyDj9EBuroEH6Tq/LYrQ+CT4vh8EkUierkNRRjoAbwgVNk+pZ3Nb0alDMSCsWIc+DbSU+HwD/6Wpwwmz2Z/BMy6gLRkmGp4VpxPjsUhHqLmfqpMdgy9XPbNDocs4kDvKuRMMMWs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515787047455.3397733660196; Thu, 1 Aug 2024 05:36:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV1w-0008UG-Mv; Thu, 01 Aug 2024 08:35:40 -0400 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 1sZV1p-0008Pr-FW for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:34 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1j-0000kU-EU for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:31 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CECD81FB53; Thu, 1 Aug 2024 12:35:24 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A566213946; Thu, 1 Aug 2024 12:35:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sBLhGguBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515724; h=from:from:reply-to: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=nlbdlyS3wD1Vr1zi5TCYT5nsVT27+ZPER/70Lu/RqYE=; b=Nz4pkc+HY1fm6o63I0dN6DlmF97dLc0+7KO94zJ3VPssfaiL4vflKe1uoQqaDyoKZESxIX WSRQzjC3OLEq8ZieQVKfOgoC12LMru6l9K+Mn8KIkwOfBEbP9rDsy3ChKEuRTKjhOMu/Kt g4MpqhSN6EriyXK7q3GqRv+mEf1eeFw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515724; h=from:from:reply-to: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=nlbdlyS3wD1Vr1zi5TCYT5nsVT27+ZPER/70Lu/RqYE=; b=grqDKXBlbERGyf4oWybYPPcYJJTHz2pfVE+/zR69O83F3YAMg7Sss4/tBs++Oq58vbfDYs T/uF5RLX6eue2TDg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Nz4pkc+H; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=grqDKXBl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515724; h=from:from:reply-to: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=nlbdlyS3wD1Vr1zi5TCYT5nsVT27+ZPER/70Lu/RqYE=; b=Nz4pkc+HY1fm6o63I0dN6DlmF97dLc0+7KO94zJ3VPssfaiL4vflKe1uoQqaDyoKZESxIX WSRQzjC3OLEq8ZieQVKfOgoC12LMru6l9K+Mn8KIkwOfBEbP9rDsy3ChKEuRTKjhOMu/Kt g4MpqhSN6EriyXK7q3GqRv+mEf1eeFw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515724; h=from:from:reply-to: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=nlbdlyS3wD1Vr1zi5TCYT5nsVT27+ZPER/70Lu/RqYE=; b=grqDKXBlbERGyf4oWybYPPcYJJTHz2pfVE+/zR69O83F3YAMg7Sss4/tBs++Oq58vbfDYs T/uF5RLX6eue2TDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 03/14] migration/multifd: Remove pages->allocated Date: Thu, 1 Aug 2024 09:35:05 -0300 Message-Id: <20240801123516.4498-4-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Spam-Score: -4.81 X-Rspamd-Queue-Id: CECD81FB53 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515789545116600 Content-Type: text/plain; charset="utf-8" This value never changes and is always the same as page_count. We don't need a copy of it per-channel plus one in the extra slot. Remove it. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd.c | 6 ++---- migration/multifd.h | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 33f91c9561..b4ca135b47 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -396,7 +396,6 @@ static MultiFDPages_t *multifd_pages_init(uint32_t n) { MultiFDPages_t *pages =3D g_new0(MultiFDPages_t, 1); =20 - pages->allocated =3D n; pages->offset =3D g_new0(ram_addr_t, n); =20 return pages; @@ -405,7 +404,6 @@ static MultiFDPages_t *multifd_pages_init(uint32_t n) static void multifd_pages_clear(MultiFDPages_t *pages) { multifd_pages_reset(pages); - pages->allocated =3D 0; g_free(pages->offset); pages->offset =3D NULL; g_free(pages); @@ -420,7 +418,7 @@ void multifd_send_fill_packet(MultiFDSendParams *p) int i; =20 packet->flags =3D cpu_to_be32(p->flags); - packet->pages_alloc =3D cpu_to_be32(pages->allocated); + packet->pages_alloc =3D cpu_to_be32(multifd_ram_page_count()); packet->normal_pages =3D cpu_to_be32(pages->normal_num); packet->zero_pages =3D cpu_to_be32(zero_num); packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); @@ -651,7 +649,7 @@ static inline bool multifd_queue_empty(MultiFDPages_t *= pages) =20 static inline bool multifd_queue_full(MultiFDPages_t *pages) { - return pages->num =3D=3D pages->allocated; + return pages->num =3D=3D multifd_ram_page_count(); } =20 static inline void multifd_enqueue(MultiFDPages_t *pages, ram_addr_t offse= t) diff --git a/migration/multifd.h b/migration/multifd.h index a2bba23af9..660a9882c2 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -76,8 +76,6 @@ typedef struct { uint32_t num; /* number of normal pages */ uint32_t normal_num; - /* number of allocated pages */ - uint32_t allocated; /* offset of each page */ ram_addr_t *offset; RAMBlock *block; --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515982; cv=none; d=zohomail.com; s=zohoarc; b=HJtV4sRI1KB2raaW4veNzikj7jMBlMUVoTcwAcekrhDRKjW5DQB3giXW2AvDHwL/MEf+zG6xLSk+e2dRl9jIFmnQwG9UqggzqqEe+AXjL/S7g7PdKGrLumoHKG4xgH8p4jt1pdnae6tR0EzzXRpeXJviCTUbatAYsxtS9Jo/Wi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515982; 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=dITPiGdDARDaPeWT8xSF5kMPl3PJ9+CE1b0/hu08aQk=; b=c6pbmszC9+GyM4m8iS1EkIDHk4fO56b1h0FeuhM3ZOTqCRAfb+eKxbwpI9yKDbtTw+Uwcy92qdMERz1PN6nrY9MCFim5y5tS3E1QtrYj64UPn7YMaNMeTc5aZmHb8eoILfrcIalfyk47V5/iDDAebbtuFllTF3vzuYGquHl5oW8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515982295267.979100022789; Thu, 1 Aug 2024 05:39:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV27-0000Nf-8U; Thu, 01 Aug 2024 08:35:51 -0400 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 1sZV1r-0008Q4-4O for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:36 -0400 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1l-0000kk-Fd for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:34 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 75C2421A39; Thu, 1 Aug 2024 12:35:26 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4D9AB13946; Thu, 1 Aug 2024 12:35:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IMtfBQ2Bq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515726; h=from:from:reply-to: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=dITPiGdDARDaPeWT8xSF5kMPl3PJ9+CE1b0/hu08aQk=; b=YWQosb+yzZE46guSKGBN1BEepMvSEnJ8eWIq1Mq6VwmL+Ic9sUI3GpLswDWBOzJKqGn7kI 3wgTDbIRPP0ikVC/sIXK7wElj1lF1eXUmgIeEsxxYvgTcN/L6Y+mYu7A3v1e403N5Oy+Xc sgo7EPxdFcWxLnqseF6Ln938kC18Zf0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515726; h=from:from:reply-to: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=dITPiGdDARDaPeWT8xSF5kMPl3PJ9+CE1b0/hu08aQk=; b=wpGdIlAboCbWmpAeLjBsg7b4pRzx3A7JKcApngYFPKN/wGFbpXsR9uM+0Llq+7R0fQtMjU ssiLXWU+Np0As0CA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=YWQosb+y; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=wpGdIlAb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515726; h=from:from:reply-to: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=dITPiGdDARDaPeWT8xSF5kMPl3PJ9+CE1b0/hu08aQk=; b=YWQosb+yzZE46guSKGBN1BEepMvSEnJ8eWIq1Mq6VwmL+Ic9sUI3GpLswDWBOzJKqGn7kI 3wgTDbIRPP0ikVC/sIXK7wElj1lF1eXUmgIeEsxxYvgTcN/L6Y+mYu7A3v1e403N5Oy+Xc sgo7EPxdFcWxLnqseF6Ln938kC18Zf0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515726; h=from:from:reply-to: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=dITPiGdDARDaPeWT8xSF5kMPl3PJ9+CE1b0/hu08aQk=; b=wpGdIlAboCbWmpAeLjBsg7b4pRzx3A7JKcApngYFPKN/wGFbpXsR9uM+0Llq+7R0fQtMjU ssiLXWU+Np0As0CA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 04/14] migration/multifd: Pass in MultiFDPages_t to file_write_ramblock_iov Date: Thu, 1 Aug 2024 09:35:06 -0300 Message-Id: <20240801123516.4498-5-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Spam-Score: -4.81 X-Rspamd-Queue-Id: 75C2421A39 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515983933116600 Content-Type: text/plain; charset="utf-8" We want to stop dereferencing 'pages' so it can be replaced by an opaque pointer in the next patches. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/file.c | 3 ++- migration/file.h | 2 +- migration/multifd.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/migration/file.c b/migration/file.c index db870f2cf0..7a8c9e3957 100644 --- a/migration/file.c +++ b/migration/file.c @@ -198,12 +198,13 @@ void file_start_incoming_migration(FileMigrationArgs = *file_args, Error **errp) } =20 int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, - int niov, RAMBlock *block, Error **errp) + int niov, MultiFDPages_t *pages, Error **errp) { ssize_t ret =3D 0; int i, slice_idx, slice_num; uintptr_t base, next, offset; size_t len; + RAMBlock *block =3D pages->block; =20 slice_idx =3D 0; slice_num =3D 1; diff --git a/migration/file.h b/migration/file.h index 9f71e87f74..1a1115f7f1 100644 --- a/migration/file.h +++ b/migration/file.h @@ -21,6 +21,6 @@ int file_parse_offset(char *filespec, uint64_t *offsetp, = Error **errp); void file_cleanup_outgoing_migration(void); bool file_send_channel_create(gpointer opaque, Error **errp); int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, - int niov, RAMBlock *block, Error **errp); + int niov, MultiFDPages_t *pages, Error **errp); int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp); #endif diff --git a/migration/multifd.c b/migration/multifd.c index b4ca135b47..44d4c3ca11 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -956,7 +956,7 @@ static void *multifd_send_thread(void *opaque) =20 if (migrate_mapped_ram()) { ret =3D file_write_ramblock_iov(p->c, p->iov, p->iovs_num, - pages->block, &local_err); + pages, &local_err); } else { ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_= num, NULL, 0, p->write_flags, --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515881; cv=none; d=zohomail.com; s=zohoarc; b=SAwggvUzlAotILurFz9l8xzZCJFh9LVcQGCItp+Upv6dnmfdqnaxrNIpvn1vd+kOk8c7eZ0CzqOHFOLC8mnDtQal+l6rLSgVzw24+qVpmdSg3vd8G9V5cEZHTOpEH6PL0yK8mg6bMh0gnCUnuoqhdGxNAz7uDIDbKsctMnX7BKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515881; 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=zBNH5hoMByRQw4O6EKyHHEbwBKscWoD9zGn8eAJCu0A=; b=WB+/cvR27JKZax+ZwxZnFVknyHX3kKz+EHS7E3x0PIo7/ngeP3/DLkHQebqhIk9abZuAsrySJKe8GjrXrWF30MQMJaXfoNs7UZX6d/zmSwbqMr2kigryACsJCodI3/g8epNoZsUDbGCqh6109Ghe/Qu2CVHU7l0cUo/bwmb5upc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515881383627.8866916314378; Thu, 1 Aug 2024 05:38:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV1y-0008VX-PI; Thu, 01 Aug 2024 08:35:44 -0400 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 1sZV1r-0008Q5-4V for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:36 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1o-0000l6-HE for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:34 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1BD1421A09; Thu, 1 Aug 2024 12:35:28 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E6D3813946; Thu, 1 Aug 2024 12:35:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WFjZKg6Bq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515728; h=from:from:reply-to: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=zBNH5hoMByRQw4O6EKyHHEbwBKscWoD9zGn8eAJCu0A=; b=AD7UoHPmpHQSl2VFVTjuTR46eXsa0sAJ41BFtjVmwbqrrlOjVkwclsFYIx9qJMw31fCkvu yWnsiezNoXBC6QcW2WjTnN5HWUajaM+hybCg2xe029RFjvHvts4v6+gXzZvjX8JrXKAz5g tcZM3gChpd2lIhtxesfkjxvezyK9tqY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515728; h=from:from:reply-to: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=zBNH5hoMByRQw4O6EKyHHEbwBKscWoD9zGn8eAJCu0A=; b=jkQJoubIGHw6IhJkXb6SyQPb/1xV1O+1NWJ0dl8SpmXl14KzClrn+lzWVEuEFxh7rWVQ5y VMRK2dhdtml0+IDg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=AD7UoHPm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jkQJoubI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515728; h=from:from:reply-to: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=zBNH5hoMByRQw4O6EKyHHEbwBKscWoD9zGn8eAJCu0A=; b=AD7UoHPmpHQSl2VFVTjuTR46eXsa0sAJ41BFtjVmwbqrrlOjVkwclsFYIx9qJMw31fCkvu yWnsiezNoXBC6QcW2WjTnN5HWUajaM+hybCg2xe029RFjvHvts4v6+gXzZvjX8JrXKAz5g tcZM3gChpd2lIhtxesfkjxvezyK9tqY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515728; h=from:from:reply-to: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=zBNH5hoMByRQw4O6EKyHHEbwBKscWoD9zGn8eAJCu0A=; b=jkQJoubIGHw6IhJkXb6SyQPb/1xV1O+1NWJ0dl8SpmXl14KzClrn+lzWVEuEFxh7rWVQ5y VMRK2dhdtml0+IDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 05/14] migration/multifd: Introduce MultiFDSendData Date: Thu, 1 Aug 2024 09:35:07 -0300 Message-Id: <20240801123516.4498-6-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Rspamd-Queue-Id: 1BD1421A09 X-Spam-Score: -2.81 X-Spamd-Result: default: False [-2.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515883438116600 Content-Type: text/plain; charset="utf-8" Add a new data structure to replace p->pages in the multifd channel. This new structure will hide the multifd payload type behind an union, so we don't need to add a new field to the channel each time we want to handle a different data type. This also allow us to keep multifd_send_pages() as is, without needing to complicate the pointer switching. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/multifd.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/migration/multifd.h b/migration/multifd.h index 660a9882c2..7bb4a2cbc4 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -17,6 +17,7 @@ #include "ram.h" =20 typedef struct MultiFDRecvData MultiFDRecvData; +typedef struct MultiFDSendData MultiFDSendData; =20 bool multifd_send_setup(void); void multifd_send_shutdown(void); @@ -88,6 +89,31 @@ struct MultiFDRecvData { off_t file_offset; }; =20 +typedef enum { + MULTIFD_PAYLOAD_NONE, + MULTIFD_PAYLOAD_RAM, +} MultiFDPayloadType; + +typedef union MultiFDPayload { + MultiFDPages_t ram; +} MultiFDPayload; + +struct MultiFDSendData { + MultiFDPayloadType type; + MultiFDPayload u; +}; + +static inline bool multifd_payload_empty(MultiFDSendData *data) +{ + return data->type =3D=3D MULTIFD_PAYLOAD_NONE; +} + +static inline void multifd_set_payload_type(MultiFDSendData *data, + MultiFDPayloadType type) +{ + data->type =3D type; +} + typedef struct { /* Fields are only written at creating/deletion time */ /* No lock required for them, they are read only */ --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515992; cv=none; d=zohomail.com; s=zohoarc; b=U9V6c+89pE0LJK8OF6E6LfvtNbiD1F2ruoH/5i5h5z23wq748JP8BJ5G0RntcH1pO3RQ5/wSfxN1mMPxFz35j6AsnvTELTaT7WSwkNphUq/UT89hGZSK4bhgjHDY5HOl1jm8BtUq4Y+tNdwBaXjX9SXEzzE9hIc10bMY8nSl7ZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515992; 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=3KWc8AJ9kE6+egRDbn4USsW4ht1En2jjurtWWE4Cko0=; b=dGIGS810wlI9oOeuJdMgTDGLY6U4xfLQz3QxFbdgu0aa9P0nCuPmBV8HhPujdNPVAJ+YUwu5ztAmXADJruc7yLf3fV5/SNnzNUz/APwHm563RyNc286kkrCcm0QoIZ8WpOqsz8yJZSrht5G15T3L4hzhCDsUqbkG4hrAJbQnpmo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515992838979.8140318851114; Thu, 1 Aug 2024 05:39:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV25-0000Ep-Cb; Thu, 01 Aug 2024 08:35:49 -0400 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 1sZV1s-0008Q8-6u for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:36 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1p-0000mU-5T for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:35 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B6CA31FB52; Thu, 1 Aug 2024 12:35:29 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8EEDC13946; Thu, 1 Aug 2024 12:35:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id aMV7FRCBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515729; h=from:from:reply-to: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=3KWc8AJ9kE6+egRDbn4USsW4ht1En2jjurtWWE4Cko0=; b=1HQyiTFr9lyIX0k7xeKucFqnpuyijD4L/XfxlaI7mukHugPAahRCgsnOztKcYqDcAUsCcS HG69nkPAPpa4F1gPGs6WTsNhuwSD3yB2fmdx8eyZ3I7w+9Xk4vrpwW784lxcK+c7tNMCIS +fN3lNu8hJ6K+oVErKI4zRg65E6xrMM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515729; h=from:from:reply-to: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=3KWc8AJ9kE6+egRDbn4USsW4ht1En2jjurtWWE4Cko0=; b=9U4aF56u4vXS49mbarI6uNk43YpL9KZO/zIvkq2BFNSfEIm63RuwoQ4JZuiB89O0lAyFVV iPZpRVPkObwGLoBw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515729; h=from:from:reply-to: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=3KWc8AJ9kE6+egRDbn4USsW4ht1En2jjurtWWE4Cko0=; b=1HQyiTFr9lyIX0k7xeKucFqnpuyijD4L/XfxlaI7mukHugPAahRCgsnOztKcYqDcAUsCcS HG69nkPAPpa4F1gPGs6WTsNhuwSD3yB2fmdx8eyZ3I7w+9Xk4vrpwW784lxcK+c7tNMCIS +fN3lNu8hJ6K+oVErKI4zRg65E6xrMM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515729; h=from:from:reply-to: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=3KWc8AJ9kE6+egRDbn4USsW4ht1En2jjurtWWE4Cko0=; b=9U4aF56u4vXS49mbarI6uNk43YpL9KZO/zIvkq2BFNSfEIm63RuwoQ4JZuiB89O0lAyFVV iPZpRVPkObwGLoBw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 06/14] migration/multifd: Make MultiFDPages_t:offset a flexible array member Date: Thu, 1 Aug 2024 09:35:08 -0300 Message-Id: <20240801123516.4498-7-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.60 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email] X-Spam-Score: -2.60 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515993885116600 Content-Type: text/plain; charset="utf-8" We're about to use MultiFDPages_t from inside the MultiFDSendData payload union, which means we cannot have pointers to allocated data inside the pages structure, otherwise we'd lose the reference to that memory once another payload type touches the union. Move the offset array into the end of the structure and turn it into a flexible array member, so it is allocated along with the rest of MultiFDSendData in the next patches. Note that other pointers, such as the ramblock pointer are still fine as long as the storage for them is not owned by the migration code and can be correctly released at some point. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd.c | 18 ++++++++++++------ migration/multifd.h | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 44d4c3ca11..64503604cf 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -98,6 +98,17 @@ struct { MultiFDMethods *ops; } *multifd_recv_state; =20 +static size_t multifd_ram_payload_size(void) +{ + uint32_t n =3D multifd_ram_page_count(); + + /* + * We keep an array of page offsets at the end of MultiFDPages_t, + * add space for it in the allocation. + */ + return sizeof(MultiFDPages_t) + n * sizeof(ram_addr_t); +} + static bool multifd_use_packets(void) { return !migrate_mapped_ram(); @@ -394,9 +405,7 @@ static int multifd_recv_initial_packet(QIOChannel *c, E= rror **errp) =20 static MultiFDPages_t *multifd_pages_init(uint32_t n) { - MultiFDPages_t *pages =3D g_new0(MultiFDPages_t, 1); - - pages->offset =3D g_new0(ram_addr_t, n); + MultiFDPages_t *pages =3D g_malloc0(multifd_ram_payload_size()); =20 return pages; } @@ -404,8 +413,6 @@ static MultiFDPages_t *multifd_pages_init(uint32_t n) static void multifd_pages_clear(MultiFDPages_t *pages) { multifd_pages_reset(pages); - g_free(pages->offset); - pages->offset =3D NULL; g_free(pages); } =20 @@ -1185,7 +1192,6 @@ bool multifd_send_setup(void) qemu_sem_init(&p->sem_sync, 0); p->id =3D i; p->pages =3D multifd_pages_init(page_count); - if (use_packets) { p->packet_len =3D sizeof(MultiFDPacket_t) + sizeof(uint64_t) * page_count; diff --git a/migration/multifd.h b/migration/multifd.h index 7bb4a2cbc4..a7fdd97f70 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -77,9 +77,9 @@ typedef struct { uint32_t num; /* number of normal pages */ uint32_t normal_num; + RAMBlock *block; /* offset of each page */ - ram_addr_t *offset; - RAMBlock *block; + ram_addr_t offset[]; } MultiFDPages_t; =20 struct MultiFDRecvData { --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515907; cv=none; d=zohomail.com; s=zohoarc; b=THCKgAjpSj558wRTM3maHWEK8s1RjVRY6gmjYApMZ6ciUZ0n0i5cGNhSh9iP0/Iqh12fZmekOgotxrY6EVAyNFYhkaxmumFOdLAwLD8LToeO6pe6dU7a+5gadG7qjVZYskiivn83qMtDKZkKxktxs7RRzAo7D4RcNFQfcwRP624= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515907; 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=SgdSRFnlWTtNiSumu+iZyWAuJkmmLA3KfLmioRH9SYI=; b=FgdoYX4cVThChpg1YFWcJQnT95FelWpV9rF1pLSBeJXr6URU5qj2us1gxXNmm96KXXA2ThLaY/Zvwh5QQLaBjaOr0F68Q3H/PPHgbAy/h5B7iaK7gT+Ek701/K+T0v/IDPe8Hu0RGL66LKGUkMmjrCguP1p8XlcuEHMhE0yOBfc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515907542580.2825533685473; Thu, 1 Aug 2024 05:38:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV28-0000QZ-1t; Thu, 01 Aug 2024 08:35:52 -0400 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 1sZV1s-0008Ra-Ui for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:38 -0400 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1p-0000nl-7X for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:36 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6644221A5E; Thu, 1 Aug 2024 12:35:31 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3D5A013946; Thu, 1 Aug 2024 12:35:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8A5uARKBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515731; h=from:from:reply-to: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=SgdSRFnlWTtNiSumu+iZyWAuJkmmLA3KfLmioRH9SYI=; b=Tb/CNjcF6BXgSBNTq3E7AXpde3TmLRGi5Ne2DOpoWp2tCEECkjoN4PpfGa8+/JXckZ9TAQ EyQ3GCzZ3yyF1wy8pMy9hP+8YN2RfPgeoZxNgJCALbZmNqNnw1Umo2PmURVFaAMWMpaHpJ d+36SJjWkZAgrqYBKmnuF7xAQwaB2OM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515731; h=from:from:reply-to: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=SgdSRFnlWTtNiSumu+iZyWAuJkmmLA3KfLmioRH9SYI=; b=pJxPxNMTVNqPles8Zdx+Rr40aPUUZx+dG5hdR3vaAMxRM98TQmAuVAwlq1BLIPZWBO4LIh ceujzvN+qeqH8bBA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515731; h=from:from:reply-to: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=SgdSRFnlWTtNiSumu+iZyWAuJkmmLA3KfLmioRH9SYI=; b=Tb/CNjcF6BXgSBNTq3E7AXpde3TmLRGi5Ne2DOpoWp2tCEECkjoN4PpfGa8+/JXckZ9TAQ EyQ3GCzZ3yyF1wy8pMy9hP+8YN2RfPgeoZxNgJCALbZmNqNnw1Umo2PmURVFaAMWMpaHpJ d+36SJjWkZAgrqYBKmnuF7xAQwaB2OM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515731; h=from:from:reply-to: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=SgdSRFnlWTtNiSumu+iZyWAuJkmmLA3KfLmioRH9SYI=; b=pJxPxNMTVNqPles8Zdx+Rr40aPUUZx+dG5hdR3vaAMxRM98TQmAuVAwlq1BLIPZWBO4LIh ceujzvN+qeqH8bBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 07/14] migration/multifd: Replace p->pages with an union pointer Date: Thu, 1 Aug 2024 09:35:09 -0300 Message-Id: <20240801123516.4498-8-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.60 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.60 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515909624116600 Content-Type: text/plain; charset="utf-8" We want multifd to be able to handle more types of data than just ram pages. To start decoupling multifd from pages, replace p->pages (MultiFDPages_t) with the new type MultiFDSendData that hides the client payload inside an union. The general idea here is to isolate functions that *need* to handle MultiFDPages_t and move them in the future to multifd-ram.c, while multifd.c will stay with only the core functions that handle MultiFDSendData/MultiFDRecvData. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd-qpl.c | 6 +-- migration/multifd-uadk.c | 2 +- migration/multifd-zero-page.c | 2 +- migration/multifd-zlib.c | 2 +- migration/multifd-zstd.c | 2 +- migration/multifd.c | 85 ++++++++++++++++++++--------------- migration/multifd.h | 7 +-- 7 files changed, 57 insertions(+), 49 deletions(-) diff --git a/migration/multifd-qpl.c b/migration/multifd-qpl.c index db60c05795..21153f1987 100644 --- a/migration/multifd-qpl.c +++ b/migration/multifd-qpl.c @@ -406,7 +406,7 @@ retry: static void multifd_qpl_compress_pages_slow_path(MultiFDSendParams *p) { QplData *qpl =3D p->compress_data; - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; uint32_t size =3D p->page_size; qpl_job *job =3D qpl->sw_job; uint8_t *zbuf =3D qpl->zbuf; @@ -437,7 +437,7 @@ static void multifd_qpl_compress_pages_slow_path(MultiF= DSendParams *p) static void multifd_qpl_compress_pages(MultiFDSendParams *p) { QplData *qpl =3D p->compress_data; - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; uint32_t size =3D p->page_size; QplHwJob *hw_job; uint8_t *buf; @@ -501,7 +501,7 @@ static void multifd_qpl_compress_pages(MultiFDSendParam= s *p) static int multifd_qpl_send_prepare(MultiFDSendParams *p, Error **errp) { QplData *qpl =3D p->compress_data; - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; uint32_t len =3D 0; =20 if (!multifd_send_prepare_common(p)) { diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c index 1ed1c6afe6..9d99807af5 100644 --- a/migration/multifd-uadk.c +++ b/migration/multifd-uadk.c @@ -177,7 +177,7 @@ static int multifd_uadk_send_prepare(MultiFDSendParams = *p, Error **errp) uint32_t page_size =3D multifd_ram_page_size(); uint8_t *buf =3D uadk_data->buf; int ret =3D 0; - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; =20 if (!multifd_send_prepare_common(p)) { goto out; diff --git a/migration/multifd-zero-page.c b/migration/multifd-zero-page.c index cc624e36b3..6506a4aa89 100644 --- a/migration/multifd-zero-page.c +++ b/migration/multifd-zero-page.c @@ -46,7 +46,7 @@ static void swap_page_offset(ram_addr_t *pages_offset, in= t a, int b) */ void multifd_send_zero_page_detect(MultiFDSendParams *p) { - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; RAMBlock *rb =3D pages->block; int i =3D 0; int j =3D pages->num - 1; diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index e47d7f70dc..66517c1067 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -123,7 +123,7 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Err= or **errp) */ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) { - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; struct zlib_data *z =3D p->compress_data; z_stream *zs =3D &z->zs; uint32_t out_size =3D 0; diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index 1812fd1b48..04ac711cf4 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -119,7 +119,7 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Err= or **errp) */ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) { - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; struct zstd_data *z =3D p->compress_data; int ret; uint32_t i; diff --git a/migration/multifd.c b/migration/multifd.c index 64503604cf..8771cda734 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -49,8 +49,7 @@ typedef struct { =20 struct { MultiFDSendParams *params; - /* array of pages to sent */ - MultiFDPages_t *pages; + MultiFDSendData *data; /* * Global number of generated multifd packets. * @@ -109,6 +108,28 @@ static size_t multifd_ram_payload_size(void) return sizeof(MultiFDPages_t) + n * sizeof(ram_addr_t); } =20 +static MultiFDSendData *multifd_send_data_alloc(void) +{ + size_t max_payload_size, size_minus_payload; + + /* + * MultiFDPages_t has a flexible array at the end, account for it + * when allocating MultiFDSendData. Use max() in case other types + * added to the union in the future are larger than + * (MultiFDPages_t + flex array). + */ + max_payload_size =3D MAX(multifd_ram_payload_size(), sizeof(MultiFDPay= load)); + + /* + * Account for any holes the compiler might insert. We can't pack + * the structure because that misaligns the members and triggers + * Waddress-of-packed-member. + */ + size_minus_payload =3D sizeof(MultiFDSendData) - sizeof(MultiFDPayload= ); + + return g_malloc0(size_minus_payload + max_payload_size); +} + static bool multifd_use_packets(void) { return !migrate_mapped_ram(); @@ -121,7 +142,7 @@ void multifd_send_channel_created(void) =20 static void multifd_set_file_bitmap(MultiFDSendParams *p) { - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; =20 assert(pages->block); =20 @@ -177,7 +198,7 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, E= rror **errp) =20 static void multifd_send_prepare_iovs(MultiFDSendParams *p) { - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; uint32_t page_size =3D multifd_ram_page_size(); =20 for (int i =3D 0; i < pages->normal_num; i++) { @@ -403,23 +424,10 @@ static int multifd_recv_initial_packet(QIOChannel *c,= Error **errp) return msg.id; } =20 -static MultiFDPages_t *multifd_pages_init(uint32_t n) -{ - MultiFDPages_t *pages =3D g_malloc0(multifd_ram_payload_size()); - - return pages; -} - -static void multifd_pages_clear(MultiFDPages_t *pages) -{ - multifd_pages_reset(pages); - g_free(pages); -} - void multifd_send_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; uint64_t packet_num; uint32_t zero_num =3D pages->num - pages->normal_num; int i; @@ -601,7 +609,7 @@ static bool multifd_send_pages(void) int i; static int next_channel; MultiFDSendParams *p =3D NULL; /* make happy gcc */ - MultiFDPages_t *pages =3D multifd_send_state->pages; + MultiFDSendData *tmp; =20 if (multifd_send_should_exit()) { return false; @@ -636,11 +644,14 @@ static bool multifd_send_pages(void) * qatomic_store_release() in multifd_send_thread(). */ smp_mb_acquire(); - assert(!p->pages->num); - multifd_send_state->pages =3D p->pages; - p->pages =3D pages; + + assert(!p->data->u.ram.num); + + tmp =3D multifd_send_state->data; + multifd_send_state->data =3D p->data; + p->data =3D tmp; /* - * Making sure p->pages is setup before marking pending_job=3Dtrue. Pa= irs + * Making sure p->data is setup before marking pending_job=3Dtrue. Pai= rs * with the qatomic_load_acquire() in multifd_send_thread(). */ qatomic_store_release(&p->pending_job, true); @@ -670,7 +681,7 @@ bool multifd_queue_page(RAMBlock *block, ram_addr_t off= set) MultiFDPages_t *pages; =20 retry: - pages =3D multifd_send_state->pages; + pages =3D &multifd_send_state->data->u.ram; =20 /* If the queue is empty, we can already enqueue now */ if (multifd_queue_empty(pages)) { @@ -800,8 +811,8 @@ static bool multifd_send_cleanup_channel(MultiFDSendPar= ams *p, Error **errp) qemu_sem_destroy(&p->sem_sync); g_free(p->name); p->name =3D NULL; - multifd_pages_clear(p->pages); - p->pages =3D NULL; + g_free(p->data); + p->data =3D NULL; p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; @@ -818,8 +829,8 @@ static void multifd_send_cleanup_state(void) qemu_sem_destroy(&multifd_send_state->channels_ready); g_free(multifd_send_state->params); multifd_send_state->params =3D NULL; - multifd_pages_clear(multifd_send_state->pages); - multifd_send_state->pages =3D NULL; + g_free(multifd_send_state->data); + multifd_send_state->data =3D NULL; g_free(multifd_send_state); multifd_send_state =3D NULL; } @@ -868,11 +879,13 @@ int multifd_send_sync_main(void) { int i; bool flush_zero_copy; + MultiFDPages_t *pages; =20 if (!migrate_multifd()) { return 0; } - if (multifd_send_state->pages->num) { + pages =3D &multifd_send_state->data->u.ram; + if (pages->num) { if (!multifd_send_pages()) { error_report("%s: multifd_send_pages fail", __func__); return -1; @@ -947,11 +960,11 @@ static void *multifd_send_thread(void *opaque) } =20 /* - * Read pending_job flag before p->pages. Pairs with the + * Read pending_job flag before p->data. Pairs with the * qatomic_store_release() in multifd_send_pages(). */ if (qatomic_load_acquire(&p->pending_job)) { - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; =20 p->iovs_num =3D 0; assert(pages->num); @@ -963,7 +976,7 @@ static void *multifd_send_thread(void *opaque) =20 if (migrate_mapped_ram()) { ret =3D file_write_ramblock_iov(p->c, p->iov, p->iovs_num, - pages, &local_err); + &p->data->u.ram, &local_err); } else { ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_= num, NULL, 0, p->write_flags, @@ -983,7 +996,7 @@ static void *multifd_send_thread(void *opaque) p->next_packet_size =3D 0; =20 /* - * Making sure p->pages is published before saying "we're + * Making sure p->data is published before saying "we're * free". Pairs with the smp_mb_acquire() in * multifd_send_pages(). */ @@ -1179,7 +1192,7 @@ bool multifd_send_setup(void) thread_count =3D migrate_multifd_channels(); multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); - multifd_send_state->pages =3D multifd_pages_init(page_count); + multifd_send_state->data =3D multifd_send_data_alloc(); qemu_sem_init(&multifd_send_state->channels_created, 0); qemu_sem_init(&multifd_send_state->channels_ready, 0); qatomic_set(&multifd_send_state->exiting, 0); @@ -1191,7 +1204,7 @@ bool multifd_send_setup(void) qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->sem_sync, 0); p->id =3D i; - p->pages =3D multifd_pages_init(page_count); + p->data =3D multifd_send_data_alloc(); if (use_packets) { p->packet_len =3D sizeof(MultiFDPacket_t) + sizeof(uint64_t) * page_count; @@ -1689,7 +1702,7 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) =20 bool multifd_send_prepare_common(MultiFDSendParams *p) { - MultiFDPages_t *pages =3D p->pages; + MultiFDPages_t *pages =3D &p->data->u.ram; multifd_send_zero_page_detect(p); =20 if (!pages->normal_num) { diff --git a/migration/multifd.h b/migration/multifd.h index a7fdd97f70..c2ba4cad13 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -152,12 +152,7 @@ typedef struct { */ bool pending_job; bool pending_sync; - /* array of pages to sent. - * The owner of 'pages' depends of 'pending_job' value: - * pending_job =3D=3D 0 -> migration_thread can use it. - * pending_job !=3D 0 -> multifd_channel can use it. - */ - MultiFDPages_t *pages; + MultiFDSendData *data; =20 /* thread local variables. No locking required */ =20 --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515787; cv=none; d=zohomail.com; s=zohoarc; b=T4fIWgLsmsfVqgua0CxbBHGQVdND0/bNBivsvcL+iuLc9cPEmKYq2ej7nuchYxuiF+oyNVtL39zi6w1fqnF8RUGUT0h/h76QApDLgs2nBD8MSZocOH9SYEg44oPTuSBUxd9z2aFpBGeTBP/dYp8q/CGypiN0C6ZHHk1uMqaKy7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515787; 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=bxWq+o7bWaqdadyYAQNcjpxnX1mtvtOvLr2PLY76EE4=; b=B/9gHaJrGPhfmAcf2/PRR3ebkgMzrDGRUFsGZeqdiUdh874+0O+z13FmuEQB9Q49D93Fi7tejfji9tgx0Y1wvup67amqhNSa9MVJxwwm/dCcjU5DV7hww+8ySpcl5qLB412uvxRMG8VB4Ya9zCbP3Bt0f44Kg0LFYOQRuC6pFT4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515787218445.153263110499; Thu, 1 Aug 2024 05:36:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV22-00006L-NA; Thu, 01 Aug 2024 08:35:48 -0400 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 1sZV1s-0008Rh-VT for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:38 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1q-0000oW-T8 for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:36 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0F9EC1FB54; Thu, 1 Aug 2024 12:35:33 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DA40C13946; Thu, 1 Aug 2024 12:35:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uP+OJxOBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515733; h=from:from:reply-to: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=bxWq+o7bWaqdadyYAQNcjpxnX1mtvtOvLr2PLY76EE4=; b=LDfbFAFu2px3b2OqSG5uY+Lk7sJ+hVSZ4Qr+mCcethZSFQb0ufydKCbKrDZPtkF7UoQiWT ZnXToSGGbR32zzXL6BnbGX3prE3QpWclF0WjJJgSihEVYkSbrARZyHIaPFagrD6UAeRV4g tW0+fObwa+RvGMgH1C5lMjePaupZULc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515733; h=from:from:reply-to: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=bxWq+o7bWaqdadyYAQNcjpxnX1mtvtOvLr2PLY76EE4=; b=WuTMwghtXoOS0xB2e0m2768ZVJ0pUWmqZydbpfNGqCjX5anfXofO9NxqnElRoqD4yXr2Zl hTVfmlGNwOYEcPBQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=LDfbFAFu; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=WuTMwght DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515733; h=from:from:reply-to: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=bxWq+o7bWaqdadyYAQNcjpxnX1mtvtOvLr2PLY76EE4=; b=LDfbFAFu2px3b2OqSG5uY+Lk7sJ+hVSZ4Qr+mCcethZSFQb0ufydKCbKrDZPtkF7UoQiWT ZnXToSGGbR32zzXL6BnbGX3prE3QpWclF0WjJJgSihEVYkSbrARZyHIaPFagrD6UAeRV4g tW0+fObwa+RvGMgH1C5lMjePaupZULc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515733; h=from:from:reply-to: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=bxWq+o7bWaqdadyYAQNcjpxnX1mtvtOvLr2PLY76EE4=; b=WuTMwghtXoOS0xB2e0m2768ZVJ0pUWmqZydbpfNGqCjX5anfXofO9NxqnElRoqD4yXr2Zl hTVfmlGNwOYEcPBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 08/14] migration/multifd: Move pages accounting into multifd_send_zero_page_detect() Date: Thu, 1 Aug 2024 09:35:10 -0300 Message-Id: <20240801123516.4498-9-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Rspamd-Queue-Id: 0F9EC1FB54 X-Spam-Score: -2.81 X-Spamd-Result: default: False [-2.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515789548116600 Content-Type: text/plain; charset="utf-8" All references to pages are being removed from the multifd worker threads in order to allow multifd to deal with different payload types. multifd_send_zero_page_detect() is called by all multifd migration paths that deal with pages and is the last spot where zero pages and normal page amounts are adjusted. Move the pages accounting into that function. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/multifd-zero-page.c | 7 ++++++- migration/multifd.c | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/migration/multifd-zero-page.c b/migration/multifd-zero-page.c index 6506a4aa89..f1e988a959 100644 --- a/migration/multifd-zero-page.c +++ b/migration/multifd-zero-page.c @@ -14,6 +14,7 @@ #include "qemu/cutils.h" #include "exec/ramblock.h" #include "migration.h" +#include "migration-stats.h" #include "multifd.h" #include "options.h" #include "ram.h" @@ -53,7 +54,7 @@ void multifd_send_zero_page_detect(MultiFDSendParams *p) =20 if (!multifd_zero_page_enabled()) { pages->normal_num =3D pages->num; - return; + goto out; } =20 /* @@ -74,6 +75,10 @@ void multifd_send_zero_page_detect(MultiFDSendParams *p) } =20 pages->normal_num =3D i; + +out: + stat64_add(&mig_stats.normal_pages, pages->normal_num); + stat64_add(&mig_stats.zero_pages, pages->num - pages->normal_num); } =20 void multifd_recv_zero_page_process(MultiFDRecvParams *p) diff --git a/migration/multifd.c b/migration/multifd.c index 8771cda734..739fc01cbe 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -989,8 +989,6 @@ static void *multifd_send_thread(void *opaque) =20 stat64_add(&mig_stats.multifd_bytes, p->next_packet_size + p->packet_len); - stat64_add(&mig_stats.normal_pages, pages->normal_num); - stat64_add(&mig_stats.zero_pages, pages->num - pages->normal_n= um); =20 multifd_pages_reset(pages); p->next_packet_size =3D 0; --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515908; cv=none; d=zohomail.com; s=zohoarc; b=Na3zGl5hciBNsNr+asXxLpmd0hrOzewwW3SKg2HQYDZo+m34UI8Fxwkm5fKyHUWHdU+Tj8SXTbA0QV9O9TkLVWzszYX1x2rxPRL59Squahuc6KSD504PvfWhpTJ+APDQ6SdDytDy+YAyXvHJupwe7ftWLOav/JOkueLnbAmsntM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515908; 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=/RO1ANbUWtLgMfI4xmyfLz/MPDC09eAq86YwDkWgYnU=; b=b+7H3ik/brzWtsL3lMmu70bzU2JnJE8V8KjzfewsVlRQ3zx3ZFjOm6TZqX2wn/WsRS0/TtCJIdRPsQHoWRKqM9ZcUgo8+LHko5KepGjJI5aqhPOY5o3udPgd85rWBYPfFEbkfZPYP5OuJXSzMqJJiFsoMzWhsHdkML2DLQdBrFQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515908391925.7536140321777; Thu, 1 Aug 2024 05:38:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV28-0000Tg-NJ; Thu, 01 Aug 2024 08:35:52 -0400 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 1sZV1u-0008TT-TX for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:40 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1s-0000pW-L6 for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:38 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B217021A07; Thu, 1 Aug 2024 12:35:34 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 82C8F13946; Thu, 1 Aug 2024 12:35:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id YBBfEhWBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515734; h=from:from:reply-to: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=/RO1ANbUWtLgMfI4xmyfLz/MPDC09eAq86YwDkWgYnU=; b=Ky/F2JMQexpKd9hcAJfLRz8q6WJoip3exznfucnVEekpEPSoNXShf19QYFV6RS8K9B+tJ2 qpsx1FH9dR633hS3Q8tBfTjfzGxnfizAcc7nk3iI0kLsritvcSYkpiJKQvJEqUrXaK86Ih AW/wMllbp1/Hid4ZqErfwL6XGE0C0tA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515734; h=from:from:reply-to: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=/RO1ANbUWtLgMfI4xmyfLz/MPDC09eAq86YwDkWgYnU=; b=a5PLUG8fPs+S9YTfH8BRYRXYbko3PMUX57cRzf8n3sLLPlP3DbxkSpoMOvDXj2pakAT20z 4YvpeCMyjdukTmBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515734; h=from:from:reply-to: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=/RO1ANbUWtLgMfI4xmyfLz/MPDC09eAq86YwDkWgYnU=; b=Ky/F2JMQexpKd9hcAJfLRz8q6WJoip3exznfucnVEekpEPSoNXShf19QYFV6RS8K9B+tJ2 qpsx1FH9dR633hS3Q8tBfTjfzGxnfizAcc7nk3iI0kLsritvcSYkpiJKQvJEqUrXaK86Ih AW/wMllbp1/Hid4ZqErfwL6XGE0C0tA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515734; h=from:from:reply-to: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=/RO1ANbUWtLgMfI4xmyfLz/MPDC09eAq86YwDkWgYnU=; b=a5PLUG8fPs+S9YTfH8BRYRXYbko3PMUX57cRzf8n3sLLPlP3DbxkSpoMOvDXj2pakAT20z 4YvpeCMyjdukTmBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 09/14] migration/multifd: Isolate ram pages packet data Date: Thu, 1 Aug 2024 09:35:11 -0300 Message-Id: <20240801123516.4498-10-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.60 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.60 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515909560116600 Content-Type: text/plain; charset="utf-8" While we cannot yet disentangle the multifd packet from page data, we can make the code a bit cleaner by setting the page-related fields in a separate function. Signed-off-by: Fabiano Rosas --- migration/multifd.c | 110 ++++++++++++++++++++++++----------------- migration/trace-events | 9 ++-- 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 739fc01cbe..7d946e6661 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -424,67 +424,65 @@ static int multifd_recv_initial_packet(QIOChannel *c,= Error **errp) return msg.id; } =20 -void multifd_send_fill_packet(MultiFDSendParams *p) +static void multifd_ram_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; MultiFDPages_t *pages =3D &p->data->u.ram; - uint64_t packet_num; uint32_t zero_num =3D pages->num - pages->normal_num; - int i; =20 - packet->flags =3D cpu_to_be32(p->flags); packet->pages_alloc =3D cpu_to_be32(multifd_ram_page_count()); packet->normal_pages =3D cpu_to_be32(pages->normal_num); packet->zero_pages =3D cpu_to_be32(zero_num); - packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); - - packet_num =3D qatomic_fetch_inc(&multifd_send_state->packet_num); - packet->packet_num =3D cpu_to_be64(packet_num); =20 if (pages->block) { strncpy(packet->ramblock, pages->block->idstr, 256); } =20 - for (i =3D 0; i < pages->num; i++) { + for (int i =3D 0; i < pages->num; i++) { /* there are architectures where ram_addr_t is 32 bit */ uint64_t temp =3D pages->offset[i]; =20 packet->offset[i] =3D cpu_to_be64(temp); } =20 - p->packets_sent++; p->total_normal_pages +=3D pages->normal_num; p->total_zero_pages +=3D zero_num; =20 - trace_multifd_send(p->id, packet_num, pages->normal_num, zero_num, - p->flags, p->next_packet_size); + trace_multifd_send_ram_fill(p->id, p->total_normal_pages, + p->total_zero_pages); } =20 -static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) +void multifd_send_fill_packet(MultiFDSendParams *p) +{ + MultiFDPacket_t *packet =3D p->packet; + uint64_t packet_num; + + memset(packet, 0, p->packet_len); + + packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); + packet->version =3D cpu_to_be32(MULTIFD_VERSION); + + packet->flags =3D cpu_to_be32(p->flags); + packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); + + packet_num =3D qatomic_fetch_inc(&multifd_send_state->packet_num); + packet->packet_num =3D cpu_to_be64(packet_num); + + p->packets_sent++; + + multifd_ram_fill_packet(p); + + trace_multifd_send_fill(p->id, packet_num, + p->flags, p->next_packet_size); +} + +static int multifd_ram_unfill_packet(MultiFDRecvParams *p, Error **errp) { MultiFDPacket_t *packet =3D p->packet; uint32_t page_count =3D multifd_ram_page_count(); uint32_t page_size =3D multifd_ram_page_size(); int i; =20 - packet->magic =3D be32_to_cpu(packet->magic); - if (packet->magic !=3D MULTIFD_MAGIC) { - error_setg(errp, "multifd: received packet " - "magic %x and expected magic %x", - packet->magic, MULTIFD_MAGIC); - return -1; - } - - packet->version =3D be32_to_cpu(packet->version); - if (packet->version !=3D MULTIFD_VERSION) { - error_setg(errp, "multifd: received packet " - "version %u and expected version %u", - packet->version, MULTIFD_VERSION); - return -1; - } - - p->flags =3D be32_to_cpu(packet->flags); - packet->pages_alloc =3D be32_to_cpu(packet->pages_alloc); /* * If we received a packet that is 100 times bigger than expected @@ -513,15 +511,9 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) return -1; } =20 - p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); - p->packet_num =3D be64_to_cpu(packet->packet_num); - p->packets_recved++; p->total_normal_pages +=3D p->normal_num; p->total_zero_pages +=3D p->zero_num; =20 - trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->zero_num, - p->flags, p->next_packet_size); - if (p->normal_num =3D=3D 0 && p->zero_num =3D=3D 0) { return 0; } @@ -563,6 +555,40 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) return 0; } =20 +static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) +{ + MultiFDPacket_t *packet =3D p->packet; + int ret =3D 0; + + packet->magic =3D be32_to_cpu(packet->magic); + if (packet->magic !=3D MULTIFD_MAGIC) { + error_setg(errp, "multifd: received packet " + "magic %x and expected magic %x", + packet->magic, MULTIFD_MAGIC); + return -1; + } + + packet->version =3D be32_to_cpu(packet->version); + if (packet->version !=3D MULTIFD_VERSION) { + error_setg(errp, "multifd: received packet " + "version %u and expected version %u", + packet->version, MULTIFD_VERSION); + return -1; + } + + p->flags =3D be32_to_cpu(packet->flags); + p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); + p->packet_num =3D be64_to_cpu(packet->packet_num); + p->packets_recved++; + + ret =3D multifd_ram_unfill_packet(p, errp); + + trace_multifd_recv_unfill(p->id, p->packet_num, p->flags, + p->next_packet_size); + + return ret; +} + static bool multifd_send_should_exit(void) { return qatomic_read(&multifd_send_state->exiting); @@ -1036,8 +1062,7 @@ out: =20 rcu_unregister_thread(); migration_threads_remove(thread); - trace_multifd_send_thread_end(p->id, p->packets_sent, p->total_normal_= pages, - p->total_zero_pages); + trace_multifd_send_thread_end(p->id, p->packets_sent); =20 return NULL; } @@ -1207,8 +1232,6 @@ bool multifd_send_setup(void) p->packet_len =3D sizeof(MultiFDPacket_t) + sizeof(uint64_t) * page_count; p->packet =3D g_malloc0(p->packet_len); - p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); - p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); } p->name =3D g_strdup_printf("mig/src/send_%d", i); p->write_flags =3D 0; @@ -1554,7 +1577,6 @@ static void *multifd_recv_thread(void *opaque) qemu_sem_wait(&p->sem_sync); } } else { - p->total_normal_pages +=3D p->data->size / qemu_target_page_si= ze(); p->data->size =3D 0; /* * Order data->size update before clearing @@ -1571,9 +1593,7 @@ static void *multifd_recv_thread(void *opaque) } =20 rcu_unregister_thread(); - trace_multifd_recv_thread_end(p->id, p->packets_recved, - p->total_normal_pages, - p->total_zero_pages); + trace_multifd_recv_thread_end(p->id, p->packets_recved); =20 return NULL; } diff --git a/migration/trace-events b/migration/trace-events index 0b7c3324fb..c65902f042 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -128,21 +128,22 @@ postcopy_preempt_reset_channel(void) "" # multifd.c multifd_new_send_channel_async(uint8_t id) "channel %u" multifd_new_send_channel_async_error(uint8_t id, void *err) "channel=3D%u = err=3D%p" -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_unfill(uint8_t id, uint64_t packet_num, uint32_t flags, uint3= 2_t next_packet_size) "channel %u packet_num %" PRIu64 " flags 0x%x next pa= cket 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) "iter %u" multifd_recv_terminate_threads(bool error) "error %d" -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_end(uint8_t id, uint64_t packets) "channel %u packets = %" PRIu64 multifd_recv_thread_start(uint8_t id) "%u" -multifd_send(uint8_t id, uint64_t packet_num, uint32_t normal_pages, uint3= 2_t zero_pages, uint32_t flags, uint32_t next_packet_size) "channel %u pack= et_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet siz= e %u" +multifd_send_fill(uint8_t id, uint64_t packet_num, uint32_t flags, uint32_= t next_packet_size) "channel %u packet_num %" PRIu64 " flags 0x%x next pack= et size %u" +multifd_send_ram_fill(uint8_t id, uint32_t normal, uint32_t zero) "channel= %u normal pages %u zero pages %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(void) "" -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_end(uint8_t id, uint64_t packets) "channel %u packets = %" 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.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515863; cv=none; d=zohomail.com; s=zohoarc; b=f0J/d0G7uK6uopX5UxPPzvo9Qga8ciO3fRQ0cXiZUi5smp5wGpW8CaLAz0LTrvtrEee/pbUV9WNpOz9ufoJ1YoKz8yu8qIFgRHBVGQeDKq3Z6khQ54oEnVmcybuto9sw17ofN8651m0qvlfvGkUX8smnhDKp7yMdCSK8tVRp3dE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515863; 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=n+XOv7Gu4c73ChHrW4LqNQPVbdOmzFxtgzX+S81fCis=; b=VwAS1cBgBE5BRxkJPLo9uaY3egl3kfO28/fC/sIHs9k4IIqyIvHBpTqV5tZg2hU5vZIlVwDVfdpadquYhL7EW7pMXyE9ung9/94VRfddoaCo407II98a/VIdR+Gk7ab3GNL0k2UNMABQ4oqT0w0HUKToy36Ii0ZBcg7K0JFzKZs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515863949246.38180180524716; Thu, 1 Aug 2024 05:37:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV26-0000IP-6w; Thu, 01 Aug 2024 08:35:50 -0400 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 1sZV1v-0008UC-8Q for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:40 -0400 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1t-0000pw-IE for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:38 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4EB9D21B5F; Thu, 1 Aug 2024 12:35:36 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2546B13946; Thu, 1 Aug 2024 12:35:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gDxXNxaBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515736; h=from:from:reply-to: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=n+XOv7Gu4c73ChHrW4LqNQPVbdOmzFxtgzX+S81fCis=; b=MwQVdH/TXp+cCX0XwWjosNW7Xe/OjydFjKf64z9MnNfHJjFa1YlTnIA51aI09lHUiWolL4 7x2o0kFyxznSo+lRp8mZLbtC0CtToAuCfWQK+soY+xVzqDAI7QKwtUJa+HNte29vgZyYhf VheSA/eugwdWNFgKMP9JuS3knXNbL2E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515736; h=from:from:reply-to: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=n+XOv7Gu4c73ChHrW4LqNQPVbdOmzFxtgzX+S81fCis=; b=VRcf1W/k5x2ezQO8UHrizNOsmdKsR/4TLG68CsfPXI+qfbvJCmjP54+U3MKcL5ih5338Jw Go1jhQNQkMkgAnCA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="MwQVdH/T"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="VRcf1W/k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515736; h=from:from:reply-to: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=n+XOv7Gu4c73ChHrW4LqNQPVbdOmzFxtgzX+S81fCis=; b=MwQVdH/TXp+cCX0XwWjosNW7Xe/OjydFjKf64z9MnNfHJjFa1YlTnIA51aI09lHUiWolL4 7x2o0kFyxznSo+lRp8mZLbtC0CtToAuCfWQK+soY+xVzqDAI7QKwtUJa+HNte29vgZyYhf VheSA/eugwdWNFgKMP9JuS3knXNbL2E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515736; h=from:from:reply-to: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=n+XOv7Gu4c73ChHrW4LqNQPVbdOmzFxtgzX+S81fCis=; b=VRcf1W/k5x2ezQO8UHrizNOsmdKsR/4TLG68CsfPXI+qfbvJCmjP54+U3MKcL5ih5338Jw Go1jhQNQkMkgAnCA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 10/14] migration/multifd: Don't send ram data during SYNC Date: Thu, 1 Aug 2024 09:35:12 -0300 Message-Id: <20240801123516.4498-11-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Rspamd-Queue-Id: 4EB9D21B5F X-Spam-Score: -2.81 X-Spamd-Result: default: False [-2.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515865744116600 Content-Type: text/plain; charset="utf-8" Skip saving and loading any ram data in the packet in the case of a SYNC. This fixes a shortcoming of the current code which requires a reset of the MultiFDPages_t fields right after the previous pending_job finishes, otherwise the very next job might be a SYNC and multifd_send_fill_packet() will put the stale values in the packet. By not calling multifd_ram_fill_packet(), we can stop resetting MultiFDPages_t in the multifd core and leave that to the client code. Actually moving the reset function is not yet done because pages->num=3D=3D0 is used by the client code to determine whether the MultiFDPages_t needs to be flushed. The subsequent patches will replace that with a generic flag that is not dependent on MultiFDPages_t. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 7d946e6661..ec6dcb9999 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -456,6 +456,7 @@ void multifd_send_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; uint64_t packet_num; + bool sync_packet =3D p->flags & MULTIFD_FLAG_SYNC; =20 memset(packet, 0, p->packet_len); =20 @@ -470,7 +471,9 @@ void multifd_send_fill_packet(MultiFDSendParams *p) =20 p->packets_sent++; =20 - multifd_ram_fill_packet(p); + if (!sync_packet) { + multifd_ram_fill_packet(p); + } =20 trace_multifd_send_fill(p->id, packet_num, p->flags, p->next_packet_size); @@ -581,7 +584,9 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) p->packet_num =3D be64_to_cpu(packet->packet_num); p->packets_recved++; =20 - ret =3D multifd_ram_unfill_packet(p, errp); + if (!(p->flags & MULTIFD_FLAG_SYNC)) { + ret =3D multifd_ram_unfill_packet(p, errp); + } =20 trace_multifd_recv_unfill(p->id, p->packet_num, p->flags, p->next_packet_size); @@ -1536,7 +1541,9 @@ static void *multifd_recv_thread(void *opaque) flags =3D p->flags; /* recv methods don't know how to handle the SYNC flag */ p->flags &=3D ~MULTIFD_FLAG_SYNC; - has_data =3D p->normal_num || p->zero_num; + if (!(flags & MULTIFD_FLAG_SYNC)) { + has_data =3D p->normal_num || p->zero_num; + } qemu_mutex_unlock(&p->mutex); } else { /* --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515822; cv=none; d=zohomail.com; s=zohoarc; b=WcibdxsGmbOZthI0IQjLr/e3XlugZ1UIljEG2xbtC9EmIUgpBFhPUIFRebkt5uQcoLsMhKiq59OiQl5RcVqjUoosl46zikEJD8d9OE9KK0vQWFzkkjGyrcXRYld5phOaZO7XMSrFBrna3kYgCa8x6KfxVB8shKrcRha0XnTatqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515822; 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=IGOQXHelFrYd1CF0QtFnL++hhRTSduYUcoZHP849jTY=; b=YiNCkIem7XlgEKunXMFbHLjzlYmU63+uxEdEvvEqHllHBAjrzoSyCocNVVzpF2g9D0orbxt0nDnG01cwU+tddAy0yHqYp4kj8BTrCthjjk0IVI5Oh33mFstdaR8RdmVaDGu17yqQpgZmQQ3ci9soPTas+yHytEOL6K8mdNvlQdo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515822189517.894498746088; Thu, 1 Aug 2024 05:37:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV26-0000Lm-Rj; Thu, 01 Aug 2024 08:35:50 -0400 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 1sZV1x-0008VV-Da for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:42 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1v-0000qz-Br for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:41 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EFF531FB4E; Thu, 1 Aug 2024 12:35:37 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C4A4313946; Thu, 1 Aug 2024 12:35:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id iGKJIhiBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515738; h=from:from:reply-to: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=IGOQXHelFrYd1CF0QtFnL++hhRTSduYUcoZHP849jTY=; b=GrFJtfAsuRsKGQXMGU7bh6WvCy853rPw078QG7rRBXYnDLtwyNt81TRNyPO4j8B4VquSYr mpRUwhmCTfs/nofbf/zZITdcgl/P28M/soknbmKzZLWVJN9OxNuIxfKWIwHrclZwXXmeAc Utd1FGBs06jTausd3fiAPMVetqwXsG8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515738; h=from:from:reply-to: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=IGOQXHelFrYd1CF0QtFnL++hhRTSduYUcoZHP849jTY=; b=ZeoFGU2hr1XJX++74GAyFLydwT5oMz3gBgfzQDJ8SQnazVIF5D8dtAAhWokDcKTdOPQXvM wW0uxzP1sj/XQyCg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=cPy3qveI; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=4mZGPc9y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515737; h=from:from:reply-to: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=IGOQXHelFrYd1CF0QtFnL++hhRTSduYUcoZHP849jTY=; b=cPy3qveIbc2QiFxE4xarszbhc/FxMkTlXa/TpKuTV6Nk1QeZvkB+cpBWIPJ3Rk4M1LZu5c KavyeqoJbTOZWuJasAl+TOAPNsy6e9MtRYSNVt5uAr9iwiT+RDgdmd0cBMe+t/vpteVzKx 9ZcF/WveJ8L9Bet9Ntk0lxxe4TzLU98= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515737; h=from:from:reply-to: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=IGOQXHelFrYd1CF0QtFnL++hhRTSduYUcoZHP849jTY=; b=4mZGPc9yBSLAYfXXGJpO2a+w0bSnAtqB49EyhhYB8h2x6xe31rJi2+HHUMhYHSw2LEqz0w 5a/eg8EB/QVqptAA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 11/14] migration/multifd: Replace multifd_send_state->pages with client data Date: Thu, 1 Aug 2024 09:35:13 -0300 Message-Id: <20240801123516.4498-12-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-1.81 / 50.00]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Spam-Score: -1.81 X-Rspamd-Queue-Id: EFF531FB4E 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1722515823424116600 Content-Type: text/plain; charset="utf-8" Multifd currently has a simple scheduling mechanism that distributes work to the various channels by keeping storage space within each channel and an extra space that is given to the client. Each time the client fills the space with data and calls into multifd, that space is given to the next idle channel and a free storage space is taken from the channel and given to client for the next iteration. This means we always need (#multifd_channels + 1) memory slots to operate multifd. This is fine, except that the presence of this one extra memory slot doesn't allow different types of payloads to be processed at the same time in different channels, i.e. the data type of multifd_send_state->pages needs to be the same as p->pages. For each new data type different from MultiFDPage_t that is to be handled, this logic would need to be duplicated by adding new fields to multifd_send_state, to the channels and to multifd_send_pages(). Fix this situation by moving the extra slot into the client and using only the generic type MultiFDSendData in the multifd core. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd.c | 79 ++++++++++++++++++++++++++------------------- migration/multifd.h | 3 ++ migration/ram.c | 2 ++ 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index ec6dcb9999..1c16879495 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -49,7 +49,6 @@ typedef struct { =20 struct { MultiFDSendParams *params; - MultiFDSendData *data; /* * Global number of generated multifd packets. * @@ -97,6 +96,8 @@ struct { MultiFDMethods *ops; } *multifd_recv_state; =20 +static MultiFDSendData *multifd_ram_send; + static size_t multifd_ram_payload_size(void) { uint32_t n =3D multifd_ram_page_count(); @@ -130,6 +131,17 @@ static MultiFDSendData *multifd_send_data_alloc(void) return g_malloc0(size_minus_payload + max_payload_size); } =20 +void multifd_ram_save_setup(void) +{ + multifd_ram_send =3D multifd_send_data_alloc(); +} + +void multifd_ram_save_cleanup(void) +{ + g_free(multifd_ram_send); + multifd_ram_send =3D NULL; +} + static bool multifd_use_packets(void) { return !migrate_mapped_ram(); @@ -617,25 +629,20 @@ static void multifd_send_kick_main(MultiFDSendParams = *p) } =20 /* - * How we use multifd_send_state->pages and channel->pages? + * multifd_send() works by exchanging the MultiFDSendData object + * provided by the caller with an unused MultiFDSendData object from + * the next channel that is found to be idle. * - * We create a pages for each channel, and a main one. Each time that - * we need to send a batch of pages we interchange the ones between - * multifd_send_state and the channel that is sending it. There are - * two reasons for that: - * - to not have to do so many mallocs during migration - * - to make easier to know what to free at the end of migration + * The channel owns the data until it finishes transmitting and the + * caller owns the empty object until it fills it with data and calls + * this function again. No locking necessary. * - * This way we always know who is the owner of each "pages" struct, - * and we don't need any locking. It belongs to the migration thread - * or to the channel thread. Switching is safe because the migration - * thread is using the channel mutex when changing it, and the channel - * have to had finish with its own, otherwise pending_job can't be - * false. + * Switching is safe because both the migration thread and the channel + * thread have barriers in place to serialize access. * * Returns true if succeed, false otherwise. */ -static bool multifd_send_pages(void) +static bool multifd_send(MultiFDSendData **send_data) { int i; static int next_channel; @@ -676,11 +683,16 @@ static bool multifd_send_pages(void) */ smp_mb_acquire(); =20 - assert(!p->data->u.ram.num); + assert(multifd_payload_empty(p->data)); =20 - tmp =3D multifd_send_state->data; - multifd_send_state->data =3D p->data; + /* + * Swap the pointers. The channel gets the client data for + * transferring and the client gets back an unused data slot. + */ + tmp =3D *send_data; + *send_data =3D p->data; p->data =3D tmp; + /* * Making sure p->data is setup before marking pending_job=3Dtrue. Pai= rs * with the qatomic_load_acquire() in multifd_send_thread(). @@ -712,7 +724,12 @@ bool multifd_queue_page(RAMBlock *block, ram_addr_t of= fset) MultiFDPages_t *pages; =20 retry: - pages =3D &multifd_send_state->data->u.ram; + pages =3D &multifd_ram_send->u.ram; + + if (multifd_payload_empty(multifd_ram_send)) { + multifd_pages_reset(pages); + multifd_set_payload_type(multifd_ram_send, MULTIFD_PAYLOAD_RAM); + } =20 /* If the queue is empty, we can already enqueue now */ if (multifd_queue_empty(pages)) { @@ -730,7 +747,7 @@ retry: * After flush, always retry. */ if (pages->block !=3D block || multifd_queue_full(pages)) { - if (!multifd_send_pages()) { + if (!multifd_send(&multifd_ram_send)) { return false; } goto retry; @@ -860,8 +877,6 @@ static void multifd_send_cleanup_state(void) qemu_sem_destroy(&multifd_send_state->channels_ready); g_free(multifd_send_state->params); multifd_send_state->params =3D NULL; - g_free(multifd_send_state->data); - multifd_send_state->data =3D NULL; g_free(multifd_send_state); multifd_send_state =3D NULL; } @@ -910,15 +925,14 @@ int multifd_send_sync_main(void) { int i; bool flush_zero_copy; - MultiFDPages_t *pages; =20 if (!migrate_multifd()) { return 0; } - pages =3D &multifd_send_state->data->u.ram; - if (pages->num) { - if (!multifd_send_pages()) { - error_report("%s: multifd_send_pages fail", __func__); + + if (!multifd_payload_empty(multifd_ram_send)) { + if (!multifd_send(&multifd_ram_send)) { + error_report("%s: multifd_send fail", __func__); return -1; } } @@ -992,13 +1006,11 @@ static void *multifd_send_thread(void *opaque) =20 /* * Read pending_job flag before p->data. Pairs with the - * qatomic_store_release() in multifd_send_pages(). + * qatomic_store_release() in multifd_send(). */ if (qatomic_load_acquire(&p->pending_job)) { - MultiFDPages_t *pages =3D &p->data->u.ram; - p->iovs_num =3D 0; - assert(pages->num); + assert(!multifd_payload_empty(p->data)); =20 ret =3D multifd_send_state->ops->send_prepare(p, &local_err); if (ret !=3D 0) { @@ -1021,13 +1033,13 @@ static void *multifd_send_thread(void *opaque) stat64_add(&mig_stats.multifd_bytes, p->next_packet_size + p->packet_len); =20 - multifd_pages_reset(pages); p->next_packet_size =3D 0; + multifd_set_payload_type(p->data, MULTIFD_PAYLOAD_NONE); =20 /* * Making sure p->data is published before saying "we're * free". Pairs with the smp_mb_acquire() in - * multifd_send_pages(). + * multifd_send(). */ qatomic_store_release(&p->pending_job, false); } else { @@ -1220,7 +1232,6 @@ bool multifd_send_setup(void) thread_count =3D migrate_multifd_channels(); multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); - multifd_send_state->data =3D multifd_send_data_alloc(); qemu_sem_init(&multifd_send_state->channels_created, 0); qemu_sem_init(&multifd_send_state->channels_ready, 0); qatomic_set(&multifd_send_state->exiting, 0); diff --git a/migration/multifd.h b/migration/multifd.h index c2ba4cad13..e3d0120837 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -275,4 +275,7 @@ static inline uint32_t multifd_ram_page_count(void) { return MULTIFD_PACKET_SIZE / qemu_target_page_size(); } + +void multifd_ram_save_setup(void); +void multifd_ram_save_cleanup(void); #endif diff --git a/migration/ram.c b/migration/ram.c index edec1a2d07..1815b2557b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2387,6 +2387,7 @@ static void ram_save_cleanup(void *opaque) ram_bitmaps_destroy(); =20 xbzrle_cleanup(); + multifd_ram_save_cleanup(); ram_state_cleanup(rsp); g_free(migration_ops); migration_ops =3D NULL; @@ -3058,6 +3059,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque, = Error **errp) migration_ops =3D g_malloc0(sizeof(MigrationOps)); =20 if (migrate_multifd()) { + multifd_ram_save_setup(); 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 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515826; cv=none; d=zohomail.com; s=zohoarc; b=ffbY9N9pxXAUTDYaXVBHButIUqnHxV02lyEEoRGmT9e1ybbT3nD5G34IPYRhVEnv/dzX5ZkgK4EKXf16khyv78jQokCHoLnLxV8gekSjNPNuL2PIbY+9WeOJr12R6UrAI+cnN0OV0g9VIg3bqRJmv57IgqUbgICZiMTqcJhx0IA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515826; 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=unEJEs0mAPmoeu9vAAXxG1Xh/PbJ6Ie5GG6fBVWq7DI=; b=f3r+adRjRMqWkhLQogdAcMyfFFcX+hbjlvNoraJPW7qqC1Tbil5+IpS3Ccz+zu8AS1zLuPobsGJcbWqk7i0hBL0BcrOZWFlhnnmLehhA5jkLeSV9kdu3hTss1I55Mjipx+MqfdlZosDwcYbH82Evk4kcltytHLcm8ft8zbGoDZ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515826389784.5782081328018; Thu, 1 Aug 2024 05:37:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV2A-0000cH-NH; Thu, 01 Aug 2024 08:35:54 -0400 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 1sZV1y-0008WQ-Ul for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:44 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1w-0000xG-TM for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:42 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 99E4F1FB52; Thu, 1 Aug 2024 12:35:39 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6F07513946; Thu, 1 Aug 2024 12:35:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4HeLDRqBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515739; h=from:from:reply-to: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=unEJEs0mAPmoeu9vAAXxG1Xh/PbJ6Ie5GG6fBVWq7DI=; b=jMTw7+J5Q+XBcfH2zPSX+5Q69VkchXFvhBqe7gABNZkOVFV+yVDXrS6PvGJI671jIePXg+ NXZqTrQx8KsAcpuaaxxCaERTzIiLN8sehE2l/tmyL47ZZZso/vM9GCrOn8E4/T/5Dh9Kcj zpxJ4zue9fcDLMHerJsAH1mfjy+8Pz8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515739; h=from:from:reply-to: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=unEJEs0mAPmoeu9vAAXxG1Xh/PbJ6Ie5GG6fBVWq7DI=; b=rP8xwh+9fYx2oN2ua/i6UrCQNa/QNJgC0G7pWiTaXbIq4SFETJW8UwXgrIHCvTkIUD/ian nHq3cBhnodOK42Bg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515739; h=from:from:reply-to: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=unEJEs0mAPmoeu9vAAXxG1Xh/PbJ6Ie5GG6fBVWq7DI=; b=jMTw7+J5Q+XBcfH2zPSX+5Q69VkchXFvhBqe7gABNZkOVFV+yVDXrS6PvGJI671jIePXg+ NXZqTrQx8KsAcpuaaxxCaERTzIiLN8sehE2l/tmyL47ZZZso/vM9GCrOn8E4/T/5Dh9Kcj zpxJ4zue9fcDLMHerJsAH1mfjy+8Pz8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515739; h=from:from:reply-to: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=unEJEs0mAPmoeu9vAAXxG1Xh/PbJ6Ie5GG6fBVWq7DI=; b=rP8xwh+9fYx2oN2ua/i6UrCQNa/QNJgC0G7pWiTaXbIq4SFETJW8UwXgrIHCvTkIUD/ian nHq3cBhnodOK42Bg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 12/14] migration/multifd: Allow multifd sync without flush Date: Thu, 1 Aug 2024 09:35:14 -0300 Message-Id: <20240801123516.4498-13-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.60 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.60 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515827402116600 Content-Type: text/plain; charset="utf-8" Separate the multifd sync from flushing the client data to the channels. These two operations are closely related but not strictly necessary to be executed together. The multifd sync is intrinsic to how multifd works. The multiple channels operate independently and may finish IO out of order in relation to each other. This applies also between the source and destination QEMU. Flushing the data that is left in the client-owned data structures (e.g. MultiFDPages_t) prior to sync is usually the right thing to do, but that is particular to how the ram migration is implemented with several passes over dirty data. Make these two routines separate, allowing future code to call the sync by itself if needed. This also allows the usage of multifd_ram_send to be isolated to ram code. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd.c | 13 +++++++++---- migration/multifd.h | 1 + migration/ram.c | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 1c16879495..c25ab4924c 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -921,11 +921,8 @@ static int multifd_zero_copy_flush(QIOChannel *c) return ret; } =20 -int multifd_send_sync_main(void) +int multifd_ram_flush_and_sync(void) { - int i; - bool flush_zero_copy; - if (!migrate_multifd()) { return 0; } @@ -937,6 +934,14 @@ int multifd_send_sync_main(void) } } =20 + return multifd_send_sync_main(); +} + +int multifd_send_sync_main(void) +{ + int i; + bool flush_zero_copy; + flush_zero_copy =3D migrate_zero_copy_send(); =20 for (i =3D 0; i < migrate_multifd_channels(); i++) { diff --git a/migration/multifd.h b/migration/multifd.h index e3d0120837..19a43d46c0 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -278,4 +278,5 @@ static inline uint32_t multifd_ram_page_count(void) =20 void multifd_ram_save_setup(void); void multifd_ram_save_cleanup(void); +int multifd_ram_flush_and_sync(void); #endif diff --git a/migration/ram.c b/migration/ram.c index 1815b2557b..67ca3d5d51 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1326,7 +1326,7 @@ static int find_dirty_block(RAMState *rs, PageSearchS= tatus *pss) (!migrate_multifd_flush_after_each_section() || migrate_mapped_ram())) { QEMUFile *f =3D rs->pss[RAM_CHANNEL_PRECOPY].pss_channel; - int ret =3D multifd_send_sync_main(); + int ret =3D multifd_ram_flush_and_sync(); if (ret < 0) { return ret; } @@ -3066,7 +3066,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque, = Error **errp) } =20 bql_unlock(); - ret =3D multifd_send_sync_main(); + ret =3D multifd_ram_flush_and_sync(); bql_lock(); if (ret < 0) { error_setg(errp, "%s: multifd synchronization failed", __func__); @@ -3213,7 +3213,7 @@ out: && migration_is_setup_or_active()) { if (migrate_multifd() && migrate_multifd_flush_after_each_section(= ) && !migrate_mapped_ram()) { - ret =3D multifd_send_sync_main(); + ret =3D multifd_ram_flush_and_sync(); if (ret < 0) { return ret; } @@ -3285,7 +3285,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) } } =20 - ret =3D multifd_send_sync_main(); + ret =3D multifd_ram_flush_and_sync(); if (ret < 0) { return ret; } --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515997; cv=none; d=zohomail.com; s=zohoarc; b=m31QXbCL+63ipzmiY4wrJb7B6uonitpbVEVg9vPwuNAch7wQeq9SmNOyltaV+qS1lhqBosMeA20Y8GrJmteZItr1K7xTUboIr/ypPyQUy5JkLJfEMIOL0modPG0rAXE736xiLzp8iLIOAMgtS51B3ViuD0EKa7+/nZrQLzEJkAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515997; 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=PmUTQQyDTHqlG67FNIO6dHj5PDWded6yIHBpLiX753U=; b=D8zgZcKOMqqUVj0J6mAsZZZco+dVZOTEr/+AKA8xu7qvx76xFN7g3XShEdcBLZ5ft5si6aZxYPkR36nT3gOVFh03xBK385lsMpnmNTb+p/B9PJJOrUXQEwy7OwjVtOBc0TQNN6onCW10q5QLVa6P/T9RthVZ6BeINDV7UW4bls4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17225159978091002.9786022284806; Thu, 1 Aug 2024 05:39:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV27-0000PJ-Lk; Thu, 01 Aug 2024 08:35:51 -0400 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 1sZV20-000066-Di for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:45 -0400 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV1y-00011P-LK for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:44 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 408A521A07; Thu, 1 Aug 2024 12:35:41 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 16DD713946; Thu, 1 Aug 2024 12:35:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uPqvMxuBq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515741; h=from:from:reply-to: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=PmUTQQyDTHqlG67FNIO6dHj5PDWded6yIHBpLiX753U=; b=IGST8DQxKEmEls/d4G37MqsDsOz1LugFovq68khKYqvHIMSVspb28QMtLdO4LEmznWrv70 KGqjaJUJ3PnbCabOyBQE442Gf82z0JlHojqpPTd7DI3EnwJlTXipk8yuFUrQFt4q6Hhi9X kKyW2oH8w6mRHsY7Ck5j/oTNM+xoJYE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515741; h=from:from:reply-to: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=PmUTQQyDTHqlG67FNIO6dHj5PDWded6yIHBpLiX753U=; b=0N3idHf4e8rkjguDrqqQ/3YwpLJjT7oBD9FrtH7IAmgrJSVaQWWaJZ86Xk/8liAnwXkLT4 y6WMhEa7Q4XGJ3Cg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515741; h=from:from:reply-to: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=PmUTQQyDTHqlG67FNIO6dHj5PDWded6yIHBpLiX753U=; b=IGST8DQxKEmEls/d4G37MqsDsOz1LugFovq68khKYqvHIMSVspb28QMtLdO4LEmznWrv70 KGqjaJUJ3PnbCabOyBQE442Gf82z0JlHojqpPTd7DI3EnwJlTXipk8yuFUrQFt4q6Hhi9X kKyW2oH8w6mRHsY7Ck5j/oTNM+xoJYE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515741; h=from:from:reply-to: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=PmUTQQyDTHqlG67FNIO6dHj5PDWded6yIHBpLiX753U=; b=0N3idHf4e8rkjguDrqqQ/3YwpLJjT7oBD9FrtH7IAmgrJSVaQWWaJZ86Xk/8liAnwXkLT4 y6WMhEa7Q4XGJ3Cg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 13/14] migration/multifd: Register nocomp ops dynamically Date: Thu, 1 Aug 2024 09:35:15 -0300 Message-Id: <20240801123516.4498-14-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [0.40 / 50.00]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 0.40 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515999886116601 Content-Type: text/plain; charset="utf-8" Prior to moving the ram code into multifd-ram.c, change the code to register the nocomp ops dynamically so we don't need to have the ops structure defined in multifd.c. While here, rename s/nocomp/ram/ and remove the docstrings which are mostly useless (if anything, it's the function pointers in multifd.h that should be documented like that). Signed-off-by: Fabiano Rosas --- migration/multifd.c | 101 ++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 73 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index c25ab4924c..d5be784b6f 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -167,15 +167,7 @@ static void multifd_set_file_bitmap(MultiFDSendParams = *p) } } =20 -/* Multifd without compression */ - -/** - * nocomp_send_setup: setup send side - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_send_setup(MultiFDSendParams *p, Error **errp) +static int ram_send_setup(MultiFDSendParams *p, Error **errp) { uint32_t page_count =3D multifd_ram_page_count(); =20 @@ -193,15 +185,7 @@ static int nocomp_send_setup(MultiFDSendParams *p, Err= or **errp) return 0; } =20 -/** - * nocomp_send_cleanup: cleanup send side - * - * For no compression this function does nothing. - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp) +static void ram_send_cleanup(MultiFDSendParams *p, Error **errp) { g_free(p->iov); p->iov =3D NULL; @@ -222,18 +206,7 @@ static void multifd_send_prepare_iovs(MultiFDSendParam= s *p) p->next_packet_size =3D pages->normal_num * page_size; } =20 -/** - * nocomp_send_prepare: prepare date to be able to send - * - * For no compression we just have to calculate the size of the - * packet. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) +static int ram_send_prepare(MultiFDSendParams *p, Error **errp) { bool use_zero_copy_send =3D migrate_zero_copy_send(); int ret; @@ -272,46 +245,19 @@ static int nocomp_send_prepare(MultiFDSendParams *p, = Error **errp) return 0; } =20 -/** - * nocomp_recv_setup: setup receive side - * - * For no compression this function does nothing. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_recv_setup(MultiFDRecvParams *p, Error **errp) +static int ram_recv_setup(MultiFDRecvParams *p, Error **errp) { p->iov =3D g_new0(struct iovec, multifd_ram_page_count()); return 0; } =20 -/** - * nocomp_recv_cleanup: setup receive side - * - * For no compression this function does nothing. - * - * @p: Params for the channel that we are using - */ -static void nocomp_recv_cleanup(MultiFDRecvParams *p) +static void ram_recv_cleanup(MultiFDRecvParams *p) { g_free(p->iov); p->iov =3D NULL; } =20 -/** - * nocomp_recv: read the data from the channel - * - * For no compression we just need to read things into the correct place. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_recv(MultiFDRecvParams *p, Error **errp) +static int ram_recv(MultiFDRecvParams *p, Error **errp) { uint32_t flags; =20 @@ -341,22 +287,15 @@ static int nocomp_recv(MultiFDRecvParams *p, Error **= errp) return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); } =20 -static MultiFDMethods multifd_nocomp_ops =3D { - .send_setup =3D nocomp_send_setup, - .send_cleanup =3D nocomp_send_cleanup, - .send_prepare =3D nocomp_send_prepare, - .recv_setup =3D nocomp_recv_setup, - .recv_cleanup =3D nocomp_recv_cleanup, - .recv =3D nocomp_recv -}; - -static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] =3D { - [MULTIFD_COMPRESSION_NONE] =3D &multifd_nocomp_ops, -}; +static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] =3D {}; =20 void multifd_register_ops(int method, MultiFDMethods *ops) { - assert(0 < method && method < MULTIFD_COMPRESSION__MAX); + if (method =3D=3D MULTIFD_COMPRESSION_NONE) { + assert(!multifd_ops[method]); + } else { + assert(0 < method && method < MULTIFD_COMPRESSION__MAX); + } multifd_ops[method] =3D ops; } =20 @@ -1755,3 +1694,19 @@ bool multifd_send_prepare_common(MultiFDSendParams *= p) =20 return true; } + +static MultiFDMethods multifd_ram_ops =3D { + .send_setup =3D ram_send_setup, + .send_cleanup =3D ram_send_cleanup, + .send_prepare =3D ram_send_prepare, + .recv_setup =3D ram_recv_setup, + .recv_cleanup =3D ram_recv_cleanup, + .recv =3D ram_recv +}; + +static void multifd_ram_register(void) +{ + multifd_register_ops(MULTIFD_COMPRESSION_NONE, &multifd_ram_ops); +} + +migration_init(multifd_ram_register); --=20 2.35.3 From nobody Sun Nov 24 14:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1722515789; cv=none; d=zohomail.com; s=zohoarc; b=BWNCEjTH7IsLrV3OSdOvGqC5gZkF2o0oXRgwq16MtNujqryx+VEeJTj1fUBaEW7e3Zxi6ucgArR7VSRiHhWi4mVugd/YYPqGyKTXJdQskTSDibW2EOPPpultwnJfF76hJxuUZDkcYe1zEWxnWNh35eAMLj2Z1W71pu0pLaEcAAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722515789; 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=YpMXSRZM8PA0rsDxqY3ONpV7hSLIaFgfRg7eSfun0Uo=; b=QOWnDEqm2L18mgP9Pl8RwueebMVTmV/h2ePuhfaoEuEg7Fb5o+nHg9F/RUl06yaGYpVVwWs6SaE1OchJnj0H7TFQx5w+s25HbXCTglQOYIOwT2IOjfSuLwFs3Z+IACW0KSkTJBhwqjWoX8Pxr5aiG1y1GkOoesy22es8cvaP17s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722515789359325.41744130674624; Thu, 1 Aug 2024 05:36:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZV29-0000Wu-CJ; Thu, 01 Aug 2024 08:35:53 -0400 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 1sZV25-0000E2-3w for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:49 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZV20-00017v-Kd for qemu-devel@nongnu.org; Thu, 01 Aug 2024 08:35:48 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 268E321A09; Thu, 1 Aug 2024 12:35:43 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B9C3213946; Thu, 1 Aug 2024 12:35:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id kFSrHx2Bq2YEYAAAD6G6ig (envelope-from ); Thu, 01 Aug 2024 12:35:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515743; h=from:from:reply-to: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=YpMXSRZM8PA0rsDxqY3ONpV7hSLIaFgfRg7eSfun0Uo=; b=iJh37q7L6m+PKEBvSbD6bsqcYvN6a+2dwhav7CNIsedzFoOGrhdkOcjWpgRq9d0vk2TYws DxLsIOcuhvN5N15MBkgG6vWpUp2XqMp7+curB5qzd4cLkaYjf6ZO9Uqzy3dPtmpXdCeKLK OYyZcOgZwh8sZNQZvib11ZBk6wz1QYc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515743; h=from:from:reply-to: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=YpMXSRZM8PA0rsDxqY3ONpV7hSLIaFgfRg7eSfun0Uo=; b=z5rHPtbxoHYDQEd0fl+MWhRna4loiSbPJTxWiGG0YZzedL+aV1vn9ItS3gA3ZkFMf/Yy5k k7qHT6Igc7i3zbDg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722515743; h=from:from:reply-to: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=YpMXSRZM8PA0rsDxqY3ONpV7hSLIaFgfRg7eSfun0Uo=; b=iJh37q7L6m+PKEBvSbD6bsqcYvN6a+2dwhav7CNIsedzFoOGrhdkOcjWpgRq9d0vk2TYws DxLsIOcuhvN5N15MBkgG6vWpUp2XqMp7+curB5qzd4cLkaYjf6ZO9Uqzy3dPtmpXdCeKLK OYyZcOgZwh8sZNQZvib11ZBk6wz1QYc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722515743; h=from:from:reply-to: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=YpMXSRZM8PA0rsDxqY3ONpV7hSLIaFgfRg7eSfun0Uo=; b=z5rHPtbxoHYDQEd0fl+MWhRna4loiSbPJTxWiGG0YZzedL+aV1vn9ItS3gA3ZkFMf/Yy5k k7qHT6Igc7i3zbDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [PATCH v3 14/14] migration/multifd: Move ram code into multifd-ram.c Date: Thu, 1 Aug 2024 09:35:16 -0300 Message-Id: <20240801123516.4498-15-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240801123516.4498-1-farosas@suse.de> References: <20240801123516.4498-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.60 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.60 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1722515791192116600 Content-Type: text/plain; charset="utf-8" In preparation for adding new payload types to multifd, move most of the ram-related code into multifd-ram.c. Let's try to keep a semblance of layering by not mixing general multifd control flow with the details of transmitting pages of ram. There are still some pieces leftover, namely the p->normal, p->zero, etc variables that we use for zero page tracking and the packet allocation which is heavily dependent on the ram code. Signed-off-by: Fabiano Rosas --- migration/meson.build | 1 + migration/multifd-ram.c | 400 ++++++++++++++++++++++++++++++++++++++++ migration/multifd.c | 384 +------------------------------------- migration/multifd.h | 5 + 4 files changed, 408 insertions(+), 382 deletions(-) create mode 100644 migration/multifd-ram.c diff --git a/migration/meson.build b/migration/meson.build index 5ce2acb41e..0d1c79cffa 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -21,6 +21,7 @@ system_ss.add(files( 'migration-hmp-cmds.c', 'migration.c', 'multifd.c', + 'multifd-ram.c', 'multifd-zlib.c', 'multifd-zero-page.c', 'options.c', diff --git a/migration/multifd-ram.c b/migration/multifd-ram.c new file mode 100644 index 0000000000..81dda140b5 --- /dev/null +++ b/migration/multifd-ram.c @@ -0,0 +1,400 @@ +/* + * Multifd ram code + * + * Copyright (c) 2019-2020 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "exec/ramblock.h" +#include "exec/target_page.h" +#include "file.h" +#include "multifd.h" +#include "options.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "trace.h" + +static MultiFDSendData *multifd_ram_send; + +size_t multifd_ram_payload_size(void) +{ + uint32_t n =3D multifd_ram_page_count(); + + /* + * We keep an array of page offsets at the end of MultiFDPages_t, + * add space for it in the allocation. + */ + return sizeof(MultiFDPages_t) + n * sizeof(ram_addr_t); +} + +void multifd_ram_save_setup(void) +{ + multifd_ram_send =3D multifd_send_data_alloc(); +} + +void multifd_ram_save_cleanup(void) +{ + g_free(multifd_ram_send); + multifd_ram_send =3D NULL; +} + +static void multifd_set_file_bitmap(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D &p->data->u.ram; + + assert(pages->block); + + for (int i =3D 0; i < pages->normal_num; i++) { + ramblock_set_file_bmap_atomic(pages->block, pages->offset[i], true= ); + } + + for (int i =3D pages->normal_num; i < pages->num; i++) { + ramblock_set_file_bmap_atomic(pages->block, pages->offset[i], fals= e); + } +} + +static int ram_send_setup(MultiFDSendParams *p, Error **errp) +{ + uint32_t page_count =3D multifd_ram_page_count(); + + if (migrate_zero_copy_send()) { + p->write_flags |=3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; + } + + if (!migrate_mapped_ram()) { + /* We need one extra place for the packet header */ + p->iov =3D g_new0(struct iovec, page_count + 1); + } else { + p->iov =3D g_new0(struct iovec, page_count); + } + + return 0; +} + +static void ram_send_cleanup(MultiFDSendParams *p, Error **errp) +{ + g_free(p->iov); + p->iov =3D NULL; + return; +} + +static void multifd_send_prepare_iovs(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D &p->data->u.ram; + uint32_t page_size =3D multifd_ram_page_size(); + + for (int i =3D 0; i < pages->normal_num; i++) { + p->iov[p->iovs_num].iov_base =3D pages->block->host + pages->offse= t[i]; + p->iov[p->iovs_num].iov_len =3D page_size; + p->iovs_num++; + } + + p->next_packet_size =3D pages->normal_num * page_size; +} + +static int ram_send_prepare(MultiFDSendParams *p, Error **errp) +{ + bool use_zero_copy_send =3D migrate_zero_copy_send(); + int ret; + + multifd_send_zero_page_detect(p); + + if (migrate_mapped_ram()) { + multifd_send_prepare_iovs(p); + multifd_set_file_bitmap(p); + + return 0; + } + + if (!use_zero_copy_send) { + /* + * Only !zerocopy needs the header in IOV; zerocopy will + * send it separately. + */ + multifd_send_prepare_header(p); + } + + multifd_send_prepare_iovs(p); + p->flags |=3D MULTIFD_FLAG_NOCOMP; + + multifd_send_fill_packet(p); + + if (use_zero_copy_send) { + /* Send header first, without zerocopy */ + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, errp); + if (ret !=3D 0) { + return -1; + } + } + + return 0; +} + +static int ram_recv_setup(MultiFDRecvParams *p, Error **errp) +{ + p->iov =3D g_new0(struct iovec, multifd_ram_page_count()); + return 0; +} + +static void ram_recv_cleanup(MultiFDRecvParams *p) +{ + g_free(p->iov); + p->iov =3D NULL; +} + +static int ram_recv(MultiFDRecvParams *p, Error **errp) +{ + uint32_t flags; + + if (migrate_mapped_ram()) { + return multifd_file_recv_data(p, errp); + } + + flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; + + if (flags !=3D MULTIFD_FLAG_NOCOMP) { + error_setg(errp, "multifd %u: flags received %x flags expected %x", + p->id, flags, MULTIFD_FLAG_NOCOMP); + return -1; + } + + multifd_recv_zero_page_process(p); + + if (!p->normal_num) { + return 0; + } + + for (int i =3D 0; i < p->normal_num; i++) { + p->iov[i].iov_base =3D p->host + p->normal[i]; + p->iov[i].iov_len =3D multifd_ram_page_size(); + ramblock_recv_bitmap_set_offset(p->block, p->normal[i]); + } + return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); +} + +static void multifd_pages_reset(MultiFDPages_t *pages) +{ + /* + * We don't need to touch offset[] array, because it will be + * overwritten later when reused. + */ + pages->num =3D 0; + pages->normal_num =3D 0; + pages->block =3D NULL; +} + +void multifd_ram_fill_packet(MultiFDSendParams *p) +{ + MultiFDPacket_t *packet =3D p->packet; + MultiFDPages_t *pages =3D &p->data->u.ram; + uint32_t zero_num =3D pages->num - pages->normal_num; + + packet->pages_alloc =3D cpu_to_be32(multifd_ram_page_count()); + packet->normal_pages =3D cpu_to_be32(pages->normal_num); + packet->zero_pages =3D cpu_to_be32(zero_num); + + if (pages->block) { + strncpy(packet->ramblock, pages->block->idstr, 256); + } + + for (int i =3D 0; i < pages->num; i++) { + /* there are architectures where ram_addr_t is 32 bit */ + uint64_t temp =3D pages->offset[i]; + + packet->offset[i] =3D cpu_to_be64(temp); + } + + p->total_normal_pages +=3D pages->normal_num; + p->total_zero_pages +=3D zero_num; + + trace_multifd_send_ram_fill(p->id, p->total_normal_pages, + p->total_zero_pages); +} + +int multifd_ram_unfill_packet(MultiFDRecvParams *p, Error **errp) +{ + MultiFDPacket_t *packet =3D p->packet; + uint32_t page_count =3D multifd_ram_page_count(); + uint32_t page_size =3D multifd_ram_page_size(); + int i; + + packet->pages_alloc =3D be32_to_cpu(packet->pages_alloc); + /* + * If we received a packet that is 100 times bigger than expected + * just stop migration. It is a magic number. + */ + if (packet->pages_alloc > page_count) { + error_setg(errp, "multifd: received packet " + "with size %u and expected a size of %u", + packet->pages_alloc, page_count) ; + return -1; + } + + p->normal_num =3D be32_to_cpu(packet->normal_pages); + if (p->normal_num > packet->pages_alloc) { + error_setg(errp, "multifd: received packet " + "with %u normal pages and expected maximum pages are %u= ", + p->normal_num, packet->pages_alloc) ; + return -1; + } + + 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 zero pages are= %u", + p->zero_num, packet->pages_alloc - p->normal_num) ; + return -1; + } + + p->total_normal_pages +=3D p->normal_num; + p->total_zero_pages +=3D p->zero_num; + + if (p->normal_num =3D=3D 0 && p->zero_num =3D=3D 0) { + return 0; + } + + /* make sure that ramblock is 0 terminated */ + packet->ramblock[255] =3D 0; + p->block =3D qemu_ram_block_by_name(packet->ramblock); + if (!p->block) { + error_setg(errp, "multifd: unknown ram block %s", + packet->ramblock); + return -1; + } + + p->host =3D p->block->host; + for (i =3D 0; i < p->normal_num; i++) { + uint64_t offset =3D be64_to_cpu(packet->offset[i]); + + if (offset > (p->block->used_length - page_size)) { + error_setg(errp, "multifd: offset too long %" PRIu64 + " (max " RAM_ADDR_FMT ")", + offset, p->block->used_length); + return -1; + } + p->normal[i] =3D offset; + } + + for (i =3D 0; i < p->zero_num; i++) { + uint64_t offset =3D be64_to_cpu(packet->offset[p->normal_num + i]); + + if (offset > (p->block->used_length - page_size)) { + error_setg(errp, "multifd: offset too long %" PRIu64 + " (max " RAM_ADDR_FMT ")", + offset, p->block->used_length); + return -1; + } + p->zero[i] =3D offset; + } + + return 0; +} + +static inline bool multifd_queue_empty(MultiFDPages_t *pages) +{ + return pages->num =3D=3D 0; +} + +static inline bool multifd_queue_full(MultiFDPages_t *pages) +{ + return pages->num =3D=3D multifd_ram_page_count(); +} + +static inline void multifd_enqueue(MultiFDPages_t *pages, ram_addr_t offse= t) +{ + pages->offset[pages->num++] =3D offset; +} + +/* Returns true if enqueue successful, false otherwise */ +bool multifd_queue_page(RAMBlock *block, ram_addr_t offset) +{ + MultiFDPages_t *pages; + +retry: + pages =3D &multifd_ram_send->u.ram; + + if (multifd_payload_empty(multifd_ram_send)) { + multifd_pages_reset(pages); + multifd_set_payload_type(multifd_ram_send, MULTIFD_PAYLOAD_RAM); + } + + /* If the queue is empty, we can already enqueue now */ + if (multifd_queue_empty(pages)) { + pages->block =3D block; + multifd_enqueue(pages, offset); + return true; + } + + /* + * Not empty, meanwhile we need a flush. It can because of either: + * + * (1) The page is not on the same ramblock of previous ones, or, + * (2) The queue is full. + * + * After flush, always retry. + */ + if (pages->block !=3D block || multifd_queue_full(pages)) { + if (!multifd_send(&multifd_ram_send)) { + return false; + } + goto retry; + } + + /* Not empty, and we still have space, do it! */ + multifd_enqueue(pages, offset); + return true; +} + +int multifd_ram_flush_and_sync(void) +{ + if (!migrate_multifd()) { + return 0; + } + + if (!multifd_payload_empty(multifd_ram_send)) { + if (!multifd_send(&multifd_ram_send)) { + error_report("%s: multifd_send fail", __func__); + return -1; + } + } + + return multifd_send_sync_main(); +} + +bool multifd_send_prepare_common(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D &p->data->u.ram; + multifd_send_zero_page_detect(p); + + if (!pages->normal_num) { + p->next_packet_size =3D 0; + return false; + } + + multifd_send_prepare_header(p); + + return true; +} + +static MultiFDMethods multifd_ram_ops =3D { + .send_setup =3D ram_send_setup, + .send_cleanup =3D ram_send_cleanup, + .send_prepare =3D ram_send_prepare, + .recv_setup =3D ram_recv_setup, + .recv_cleanup =3D ram_recv_cleanup, + .recv =3D ram_recv +}; + +static void multifd_ram_register(void) +{ + multifd_register_ops(MULTIFD_COMPRESSION_NONE, &multifd_ram_ops); +} + +migration_init(multifd_ram_register); diff --git a/migration/multifd.c b/migration/multifd.c index d5be784b6f..99197d6174 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -96,20 +96,7 @@ struct { MultiFDMethods *ops; } *multifd_recv_state; =20 -static MultiFDSendData *multifd_ram_send; - -static size_t multifd_ram_payload_size(void) -{ - uint32_t n =3D multifd_ram_page_count(); - - /* - * We keep an array of page offsets at the end of MultiFDPages_t, - * add space for it in the allocation. - */ - return sizeof(MultiFDPages_t) + n * sizeof(ram_addr_t); -} - -static MultiFDSendData *multifd_send_data_alloc(void) +MultiFDSendData *multifd_send_data_alloc(void) { size_t max_payload_size, size_minus_payload; =20 @@ -131,17 +118,6 @@ static MultiFDSendData *multifd_send_data_alloc(void) return g_malloc0(size_minus_payload + max_payload_size); } =20 -void multifd_ram_save_setup(void) -{ - multifd_ram_send =3D multifd_send_data_alloc(); -} - -void multifd_ram_save_cleanup(void) -{ - g_free(multifd_ram_send); - multifd_ram_send =3D NULL; -} - static bool multifd_use_packets(void) { return !migrate_mapped_ram(); @@ -152,141 +128,6 @@ void multifd_send_channel_created(void) qemu_sem_post(&multifd_send_state->channels_created); } =20 -static void multifd_set_file_bitmap(MultiFDSendParams *p) -{ - MultiFDPages_t *pages =3D &p->data->u.ram; - - assert(pages->block); - - for (int i =3D 0; i < pages->normal_num; i++) { - ramblock_set_file_bmap_atomic(pages->block, pages->offset[i], true= ); - } - - for (int i =3D pages->normal_num; i < pages->num; i++) { - ramblock_set_file_bmap_atomic(pages->block, pages->offset[i], fals= e); - } -} - -static int ram_send_setup(MultiFDSendParams *p, Error **errp) -{ - uint32_t page_count =3D multifd_ram_page_count(); - - if (migrate_zero_copy_send()) { - p->write_flags |=3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; - } - - if (multifd_use_packets()) { - /* We need one extra place for the packet header */ - p->iov =3D g_new0(struct iovec, page_count + 1); - } else { - p->iov =3D g_new0(struct iovec, page_count); - } - - return 0; -} - -static void ram_send_cleanup(MultiFDSendParams *p, Error **errp) -{ - g_free(p->iov); - p->iov =3D NULL; - return; -} - -static void multifd_send_prepare_iovs(MultiFDSendParams *p) -{ - MultiFDPages_t *pages =3D &p->data->u.ram; - uint32_t page_size =3D multifd_ram_page_size(); - - for (int i =3D 0; i < pages->normal_num; i++) { - p->iov[p->iovs_num].iov_base =3D pages->block->host + pages->offse= t[i]; - p->iov[p->iovs_num].iov_len =3D page_size; - p->iovs_num++; - } - - p->next_packet_size =3D pages->normal_num * page_size; -} - -static int ram_send_prepare(MultiFDSendParams *p, Error **errp) -{ - bool use_zero_copy_send =3D migrate_zero_copy_send(); - int ret; - - multifd_send_zero_page_detect(p); - - if (!multifd_use_packets()) { - multifd_send_prepare_iovs(p); - multifd_set_file_bitmap(p); - - return 0; - } - - if (!use_zero_copy_send) { - /* - * Only !zerocopy needs the header in IOV; zerocopy will - * send it separately. - */ - multifd_send_prepare_header(p); - } - - multifd_send_prepare_iovs(p); - p->flags |=3D MULTIFD_FLAG_NOCOMP; - - multifd_send_fill_packet(p); - - if (use_zero_copy_send) { - /* Send header first, without zerocopy */ - ret =3D qio_channel_write_all(p->c, (void *)p->packet, - p->packet_len, errp); - if (ret !=3D 0) { - return -1; - } - } - - return 0; -} - -static int ram_recv_setup(MultiFDRecvParams *p, Error **errp) -{ - p->iov =3D g_new0(struct iovec, multifd_ram_page_count()); - return 0; -} - -static void ram_recv_cleanup(MultiFDRecvParams *p) -{ - g_free(p->iov); - p->iov =3D NULL; -} - -static int ram_recv(MultiFDRecvParams *p, Error **errp) -{ - uint32_t flags; - - if (!multifd_use_packets()) { - return multifd_file_recv_data(p, errp); - } - - flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; - - if (flags !=3D MULTIFD_FLAG_NOCOMP) { - error_setg(errp, "multifd %u: flags received %x flags expected %x", - p->id, flags, MULTIFD_FLAG_NOCOMP); - return -1; - } - - multifd_recv_zero_page_process(p); - - if (!p->normal_num) { - return 0; - } - - for (int i =3D 0; i < p->normal_num; i++) { - p->iov[i].iov_base =3D p->host + p->normal[i]; - p->iov[i].iov_len =3D multifd_ram_page_size(); - ramblock_recv_bitmap_set_offset(p->block, p->normal[i]); - } - return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); -} - static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] =3D {}; =20 void multifd_register_ops(int method, MultiFDMethods *ops) @@ -299,18 +140,6 @@ void multifd_register_ops(int method, MultiFDMethods *= ops) multifd_ops[method] =3D ops; } =20 -/* Reset a MultiFDPages_t* object for the next use */ -static void multifd_pages_reset(MultiFDPages_t *pages) -{ - /* - * We don't need to touch offset[] array, because it will be - * overwritten later when reused. - */ - pages->num =3D 0; - pages->normal_num =3D 0; - pages->block =3D NULL; -} - static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) { MultiFDInit_t msg =3D {}; @@ -375,34 +204,6 @@ static int multifd_recv_initial_packet(QIOChannel *c, = Error **errp) return msg.id; } =20 -static void multifd_ram_fill_packet(MultiFDSendParams *p) -{ - MultiFDPacket_t *packet =3D p->packet; - MultiFDPages_t *pages =3D &p->data->u.ram; - uint32_t zero_num =3D pages->num - pages->normal_num; - - packet->pages_alloc =3D cpu_to_be32(multifd_ram_page_count()); - packet->normal_pages =3D cpu_to_be32(pages->normal_num); - packet->zero_pages =3D cpu_to_be32(zero_num); - - if (pages->block) { - strncpy(packet->ramblock, pages->block->idstr, 256); - } - - for (int i =3D 0; i < pages->num; i++) { - /* there are architectures where ram_addr_t is 32 bit */ - uint64_t temp =3D pages->offset[i]; - - packet->offset[i] =3D cpu_to_be64(temp); - } - - p->total_normal_pages +=3D pages->normal_num; - p->total_zero_pages +=3D zero_num; - - trace_multifd_send_ram_fill(p->id, p->total_normal_pages, - p->total_zero_pages); -} - void multifd_send_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; @@ -430,85 +231,6 @@ void multifd_send_fill_packet(MultiFDSendParams *p) p->flags, p->next_packet_size); } =20 -static int multifd_ram_unfill_packet(MultiFDRecvParams *p, Error **errp) -{ - MultiFDPacket_t *packet =3D p->packet; - uint32_t page_count =3D multifd_ram_page_count(); - uint32_t page_size =3D multifd_ram_page_size(); - int i; - - packet->pages_alloc =3D be32_to_cpu(packet->pages_alloc); - /* - * If we received a packet that is 100 times bigger than expected - * just stop migration. It is a magic number. - */ - if (packet->pages_alloc > page_count) { - error_setg(errp, "multifd: received packet " - "with size %u and expected a size of %u", - packet->pages_alloc, page_count) ; - return -1; - } - - p->normal_num =3D be32_to_cpu(packet->normal_pages); - if (p->normal_num > packet->pages_alloc) { - error_setg(errp, "multifd: received packet " - "with %u normal pages and expected maximum pages are %u= ", - p->normal_num, packet->pages_alloc) ; - return -1; - } - - 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 zero pages are= %u", - p->zero_num, packet->pages_alloc - p->normal_num) ; - return -1; - } - - p->total_normal_pages +=3D p->normal_num; - p->total_zero_pages +=3D p->zero_num; - - if (p->normal_num =3D=3D 0 && p->zero_num =3D=3D 0) { - return 0; - } - - /* make sure that ramblock is 0 terminated */ - packet->ramblock[255] =3D 0; - p->block =3D qemu_ram_block_by_name(packet->ramblock); - if (!p->block) { - error_setg(errp, "multifd: unknown ram block %s", - packet->ramblock); - return -1; - } - - p->host =3D p->block->host; - for (i =3D 0; i < p->normal_num; i++) { - uint64_t offset =3D be64_to_cpu(packet->offset[i]); - - if (offset > (p->block->used_length - page_size)) { - error_setg(errp, "multifd: offset too long %" PRIu64 - " (max " RAM_ADDR_FMT ")", - offset, p->block->used_length); - return -1; - } - p->normal[i] =3D offset; - } - - for (i =3D 0; i < p->zero_num; i++) { - uint64_t offset =3D be64_to_cpu(packet->offset[p->normal_num + i]); - - if (offset > (p->block->used_length - page_size)) { - error_setg(errp, "multifd: offset too long %" PRIu64 - " (max " RAM_ADDR_FMT ")", - offset, p->block->used_length); - return -1; - } - p->zero[i] =3D offset; - } - - return 0; -} - static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) { MultiFDPacket_t *packet =3D p->packet; @@ -581,7 +303,7 @@ static void multifd_send_kick_main(MultiFDSendParams *p) * * Returns true if succeed, false otherwise. */ -static bool multifd_send(MultiFDSendData **send_data) +bool multifd_send(MultiFDSendData **send_data) { int i; static int next_channel; @@ -642,61 +364,6 @@ static bool multifd_send(MultiFDSendData **send_data) return true; } =20 -static inline bool multifd_queue_empty(MultiFDPages_t *pages) -{ - return pages->num =3D=3D 0; -} - -static inline bool multifd_queue_full(MultiFDPages_t *pages) -{ - return pages->num =3D=3D multifd_ram_page_count(); -} - -static inline void multifd_enqueue(MultiFDPages_t *pages, ram_addr_t offse= t) -{ - pages->offset[pages->num++] =3D offset; -} - -/* Returns true if enqueue successful, false otherwise */ -bool multifd_queue_page(RAMBlock *block, ram_addr_t offset) -{ - MultiFDPages_t *pages; - -retry: - pages =3D &multifd_ram_send->u.ram; - - if (multifd_payload_empty(multifd_ram_send)) { - multifd_pages_reset(pages); - multifd_set_payload_type(multifd_ram_send, MULTIFD_PAYLOAD_RAM); - } - - /* If the queue is empty, we can already enqueue now */ - if (multifd_queue_empty(pages)) { - pages->block =3D block; - multifd_enqueue(pages, offset); - return true; - } - - /* - * Not empty, meanwhile we need a flush. It can because of either: - * - * (1) The page is not on the same ramblock of previous ones, or, - * (2) The queue is full. - * - * After flush, always retry. - */ - if (pages->block !=3D block || multifd_queue_full(pages)) { - if (!multifd_send(&multifd_ram_send)) { - return false; - } - goto retry; - } - - /* Not empty, and we still have space, do it! */ - multifd_enqueue(pages, offset); - return true; -} - /* Multifd send side hit an error; remember it and prepare to quit */ static void multifd_send_set_error(Error *err) { @@ -860,22 +527,6 @@ static int multifd_zero_copy_flush(QIOChannel *c) return ret; } =20 -int multifd_ram_flush_and_sync(void) -{ - if (!migrate_multifd()) { - return 0; - } - - if (!multifd_payload_empty(multifd_ram_send)) { - if (!multifd_send(&multifd_ram_send)) { - error_report("%s: multifd_send fail", __func__); - return -1; - } - } - - return multifd_send_sync_main(); -} - int multifd_send_sync_main(void) { int i; @@ -1679,34 +1330,3 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error= **errp) QEMU_THREAD_JOINABLE); qatomic_inc(&multifd_recv_state->count); } - -bool multifd_send_prepare_common(MultiFDSendParams *p) -{ - MultiFDPages_t *pages =3D &p->data->u.ram; - multifd_send_zero_page_detect(p); - - if (!pages->normal_num) { - p->next_packet_size =3D 0; - return false; - } - - multifd_send_prepare_header(p); - - return true; -} - -static MultiFDMethods multifd_ram_ops =3D { - .send_setup =3D ram_send_setup, - .send_cleanup =3D ram_send_cleanup, - .send_prepare =3D ram_send_prepare, - .recv_setup =3D ram_recv_setup, - .recv_cleanup =3D ram_recv_cleanup, - .recv =3D ram_recv -}; - -static void multifd_ram_register(void) -{ - multifd_register_ops(MULTIFD_COMPRESSION_NONE, &multifd_ram_ops); -} - -migration_init(multifd_ram_register); diff --git a/migration/multifd.h b/migration/multifd.h index 19a43d46c0..2197d0b44f 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -265,6 +265,8 @@ static inline void multifd_send_prepare_header(MultiFDS= endParams *p) } =20 void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc); +bool multifd_send(MultiFDSendData **send_data); +MultiFDSendData *multifd_send_data_alloc(void); =20 static inline uint32_t multifd_ram_page_size(void) { @@ -279,4 +281,7 @@ static inline uint32_t multifd_ram_page_count(void) void multifd_ram_save_setup(void); void multifd_ram_save_cleanup(void); int multifd_ram_flush_and_sync(void); +size_t multifd_ram_payload_size(void); +void multifd_ram_fill_packet(MultiFDSendParams *p); +int multifd_ram_unfill_packet(MultiFDRecvParams *p, Error **errp); #endif --=20 2.35.3