From nobody Mon Nov 25 02:05:47 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=1718918560; cv=none; d=zohomail.com; s=zohoarc; b=ga6HRz7XcLosFCeXFQk6sXItS/a5dOWuWYmQVneoq7r1n6+IleU+f62y2UGPnXFf1L7ljyy0QmCoKHNaCNJchlUmXvbWW4Zf5371ez1vSWUTQIM0AlIbMQW5JxKyvcH8mdacYn1cG/g3Cs57MY5BZG8XGCfRIzQ+uccT5Zfo91s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918560; 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=xGBOlwSV+lcB+dUpCAZJoCxv+H6GGTT7Mw7AvJjicx0=; b=FezfSevfd3/myw8aP8+N0fzRaJTgkyBCK7DTFMpUoILmKVhmLsWOgPcTDfdD+q1lQfqQTDLLFWtj4kdByoZO7CNntzaiDiGAxYk+YIWUbmUQlAXUlSNdoZwhVDzOkhj7mhCaW7hfl69FnuqTDM7sfymWgA7AoY2xiyt7WbBcwHA= 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 1718918560758996.3157447766047; Thu, 20 Jun 2024 14:22:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDi-0000s2-IS; Thu, 20 Jun 2024 17:21:26 -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 1sKPDf-0000r8-Et for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:24 -0400 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKPDc-0007FK-EC for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:22 -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 A562A1F8B5; Thu, 20 Jun 2024 21:21:16 +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 728F613ACA; Thu, 20 Jun 2024 21:21:15 +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 0IZ8DkuddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918476; 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=xGBOlwSV+lcB+dUpCAZJoCxv+H6GGTT7Mw7AvJjicx0=; b=RKehQw2HogyjeziGa2jjoFOcM/we3MruJMAlHRMI6bP9UlauUx14rObprRD0RPcRW7mXgP jnqKtzSCsGdy6Vepq7Dja4k/RkmxItyTB7dFZMTOxeChzUou6SzoPOr87s8Ol+qMaN/JFm tvkwdH1gFUu5D2fDLkre2CfKGIBAZvI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918476; 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=xGBOlwSV+lcB+dUpCAZJoCxv+H6GGTT7Mw7AvJjicx0=; b=igC6MGfO1W4En/8DSMW7CXkGIY5Xde4JO/I7qDkbVa+uz7+7amy9yW1CMOSyztuvPurDDL f6rJKUkDvZpI2hAg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918476; 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=xGBOlwSV+lcB+dUpCAZJoCxv+H6GGTT7Mw7AvJjicx0=; b=RKehQw2HogyjeziGa2jjoFOcM/we3MruJMAlHRMI6bP9UlauUx14rObprRD0RPcRW7mXgP jnqKtzSCsGdy6Vepq7Dja4k/RkmxItyTB7dFZMTOxeChzUou6SzoPOr87s8Ol+qMaN/JFm tvkwdH1gFUu5D2fDLkre2CfKGIBAZvI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918476; 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=xGBOlwSV+lcB+dUpCAZJoCxv+H6GGTT7Mw7AvJjicx0=; b=igC6MGfO1W4En/8DSMW7CXkGIY5Xde4JO/I7qDkbVa+uz7+7amy9yW1CMOSyztuvPurDDL f6rJKUkDvZpI2hAg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 1/7] migration/multifd: Reduce access to p->pages Date: Thu, 20 Jun 2024 18:21:05 -0300 Message-Id: <20240620212111.29319-2-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 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)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; 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)[imap1.dmz-prg2.suse.org:helo,suse.de:email] X-Spam-Score: -2.80 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:2; 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718918561474100003 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 d82885fdbb..506f42e124 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 Mon Nov 25 02:05:47 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=1718918574; cv=none; d=zohomail.com; s=zohoarc; b=jWFZ1x49sJrpBTAZciFAF33xV5NlCwvCPEelpuJv/LVpZrAGfHjEYuQkKTDH63PFKKZJO0K4BSq9exeHkDeAKWh1FerwXRJHPuiMmbOEdFw/8AUyYsWSwJnmwdHDo4IgXwk2kOgLfgY+4D/P44ioiw917YvzY2scPUdvWBn8O1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918574; 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=ZzbyuqoZTPjGrfwTq0zkQ1jWPw3whxK8wBwe8ugBbiA=; b=A9xOcOCA7YyOnsJlR6/746p7lFMm12Lamkz/3ZFVvGE4q9J0LolRL31RXK8DUzim5SGUlWTR373+G3joyhv5QyFM54lU3l0rP+r/mkzKW+M9IgeWnHylHw4BiH+cEYoC3RBxxLsVrdrB21A1Aty+NOnSjssh5s6LnI0JxjTTACg= 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 1718918574216779.0116222416453; Thu, 20 Jun 2024 14:22:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDi-0000rr-1Y; Thu, 20 Jun 2024 17:21:26 -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 1sKPDf-0000r5-Dt for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:24 -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 1sKPDc-0007FQ-EJ for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:21 -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 42C431F8B8; Thu, 20 Jun 2024 21:21:18 +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 1B7DA1369F; Thu, 20 Jun 2024 21:21:16 +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 aInFNEyddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918478; 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=ZzbyuqoZTPjGrfwTq0zkQ1jWPw3whxK8wBwe8ugBbiA=; b=D+9ef5Nr6Yotc9NwDVuCZP5TBGkIYDZbA+pqLB2WwiamfvuI7PCa2xB0JoGeE6jwr0Yy4V lyQ71RMpTYU8Myxy1LYw5uoalX4YbEOlsVFwGfd7Lg+tgEnJzL9YqWN29uTOKxZDqv9RzT jD8hwRljUIwvHhSTYc7qQuE8LQ+oZRk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918478; 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=ZzbyuqoZTPjGrfwTq0zkQ1jWPw3whxK8wBwe8ugBbiA=; b=TSrKt4gv7sdOkddYcGKIKY5qBmtliFwSuZH7QYFV34+TCRKs+2jyR5KmipRmpQDNtvVUsd Jj2aZzu5g4KUNtBw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918478; 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=ZzbyuqoZTPjGrfwTq0zkQ1jWPw3whxK8wBwe8ugBbiA=; b=D+9ef5Nr6Yotc9NwDVuCZP5TBGkIYDZbA+pqLB2WwiamfvuI7PCa2xB0JoGeE6jwr0Yy4V lyQ71RMpTYU8Myxy1LYw5uoalX4YbEOlsVFwGfd7Lg+tgEnJzL9YqWN29uTOKxZDqv9RzT jD8hwRljUIwvHhSTYc7qQuE8LQ+oZRk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918478; 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=ZzbyuqoZTPjGrfwTq0zkQ1jWPw3whxK8wBwe8ugBbiA=; b=TSrKt4gv7sdOkddYcGKIKY5qBmtliFwSuZH7QYFV34+TCRKs+2jyR5KmipRmpQDNtvVUsd Jj2aZzu5g4KUNtBw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 2/7] migration/multifd: Pass in MultiFDPages_t to file_write_ramblock_iov Date: Thu, 20 Jun 2024 18:21:06 -0300 Message-Id: <20240620212111.29319-3-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 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)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718918575456100003 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. 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 ab18ba505a..07e8648c7d 100644 --- a/migration/file.c +++ b/migration/file.c @@ -167,12 +167,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 7699c04677..d735b623b0 100644 --- a/migration/file.h +++ b/migration/file.h @@ -22,6 +22,6 @@ void file_cleanup_outgoing_migration(void); bool file_send_channel_create(gpointer opaque, Error **errp); void file_create_incoming_channels(QIOChannel *ioc, 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 506f42e124..58340d9d95 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -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, - 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 Mon Nov 25 02:05:47 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=1718918564; cv=none; d=zohomail.com; s=zohoarc; b=dsRrPngF0e3zS0PljvdUzQpubhAx25C09N8sm1xTdLksaUbw+RNdx0jerJgKZs9phEciyQ4yesUHZCB304aCH1cVW/QqVw93FKf9wsrdvLzSGmzV1RC30cdmvunesVwbM+LFPP9v9XlYsoCutYG/pmAomvfE/H1s6uNTDtik8sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918564; 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=kBvGieyDmAJ34lvusFrhcmfNOw8J3H9YbFb8zG91/a8=; b=kr1VesxNaFaEIlghqJVQbGyFjlOA7RUbK+id+iGRTpiuLAzLYlKle/9i7IrK6pngm+KqDPGFIPY/Ylq4lOK9SoJ6XPYKBrDQiDiEqT4TAIC9sqkCHtVG2q9dKZxFO5Fa8THdKZk3sZ68bUyFP3v4lPW98av6RWdtvQeUVuXACpA= 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 1718918564978284.36521204055714; Thu, 20 Jun 2024 14:22:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDi-0000s1-JR; Thu, 20 Jun 2024 17:21:26 -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 1sKPDh-0000rW-Bp for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:25 -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 1sKPDe-0007Fe-6a for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:25 -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 E393021AE4; Thu, 20 Jun 2024 21:21:19 +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 BAAAC1369F; Thu, 20 Jun 2024 21:21:18 +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 CCksIE6ddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918480; 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=kBvGieyDmAJ34lvusFrhcmfNOw8J3H9YbFb8zG91/a8=; b=N5K/HyMeE4CQ1VacO/UuTBbiU437XbR64wDIshEx3thrERBtDWCqCHtpG7BWA1PFZDuiuO N/wESbKX9YQvm9Pbhko5PNXN+fFBkjogqUZd1FSH3aZmYDinR2LKSeNCxqYiYYW6lz9+VN xV7HJOuV7vQYNGSGyNO8rBqPu3oTFKA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918480; 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=kBvGieyDmAJ34lvusFrhcmfNOw8J3H9YbFb8zG91/a8=; b=Z03eGOiHHfJUy6oOHmY5jcvg3w5PTU6ilB9P6sNYrzHsDzquS+3c37SvTYU/G07PJiAkyE 7dRIC3XdJH53YLCA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ANiUhL3T; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=kI15Jf8r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918479; 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=kBvGieyDmAJ34lvusFrhcmfNOw8J3H9YbFb8zG91/a8=; b=ANiUhL3TiFNoUAb3hT7lTfIr5Zwr0NAvvdGnAs66Y+5wg8iNwXcQkOxvkEIenZcwAw2WHy ELB/gtW2hm7Qtm3eSJVYGPgo8ZKqmZr+4P8fn4WiPvxjU8+ryMUgfKf66h56VxMNQtU3Iz dDEQWq/2atogZ0NgfszufILBtLgVfKQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918479; 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=kBvGieyDmAJ34lvusFrhcmfNOw8J3H9YbFb8zG91/a8=; b=kI15Jf8rYPHDoYVkbfTkY6BvGDpdPaYWuE2mkHqVlgdxW4DfmK1/6qt9s/qoNo0RjPGNTq AqeCwucQkj7l/eCQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 3/7] migration/multifd: Replace p->pages with an opaque pointer Date: Thu, 20 Jun 2024 18:21:07 -0300 Message-Id: <20240620212111.29319-4-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E393021AE4 X-Spam-Score: -4.01 X-Spamd-Result: default: False [-4.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_LOW(-1.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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1718918565409100002 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 a new type MultiFDSendData that hides an opaque pointer. 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 --- migration/multifd-zero-page.c | 2 +- migration/multifd-zlib.c | 2 +- migration/multifd-zstd.c | 2 +- migration/multifd.c | 57 +++++++++++++++++++++-------------- migration/multifd.h | 13 ++++---- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/migration/multifd-zero-page.c b/migration/multifd-zero-page.c index e1b8370f88..1ad77462a4 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->opaque; 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 65f8aba5c8..e75e04d2c7 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->opaque; 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 cb6075a9a5..1ba572a882 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->opaque; struct zstd_data *z =3D p->compress_data; int ret; uint32_t i; diff --git a/migration/multifd.c b/migration/multifd.c index 58340d9d95..55b31c4515 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. * @@ -110,7 +109,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->opaque; =20 assert(pages->block); =20 @@ -164,7 +163,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->opaque; =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]; @@ -411,7 +410,7 @@ static void multifd_pages_clear(MultiFDPages_t *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->opaque; uint64_t packet_num; uint32_t zero_num =3D pages->num - pages->normal_num; int i; @@ -591,7 +590,8 @@ 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; + MultiFDPages_t *channel_pages; + MultiFDSendData *data =3D multifd_send_state->data; =20 if (multifd_send_should_exit()) { return false; @@ -626,11 +626,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; + + channel_pages =3D p->data->opaque; + assert(!channel_pages->num); + + multifd_send_state->data =3D p->data; + p->data =3D data; /* - * 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); @@ -660,7 +663,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->opaque; =20 /* If the queue is empty, we can already enqueue now */ if (multifd_queue_empty(pages)) { @@ -790,8 +793,10 @@ static bool multifd_send_cleanup_channel(MultiFDSendPa= rams *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; + multifd_pages_clear(p->data->opaque); + p->data->opaque =3D NULL; + g_free(p->data); + p->data =3D NULL; p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; @@ -808,8 +813,10 @@ 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; + multifd_pages_clear(multifd_send_state->data->opaque); + multifd_send_state->data->opaque =3D NULL; + g_free(multifd_send_state->data); + multifd_send_state->data =3D NULL; g_free(multifd_send_state); multifd_send_state =3D NULL; } @@ -858,11 +865,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->opaque; + if (pages->num) { if (!multifd_send_pages()) { error_report("%s: multifd_send_pages fail", __func__); return -1; @@ -937,11 +946,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->opaque; =20 p->iovs_num =3D 0; assert(pages->num); @@ -953,7 +962,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->opaque, &local_err); } else { ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_= num, NULL, 0, p->write_flags, @@ -973,7 +982,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(). */ @@ -1169,7 +1178,8 @@ 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 g_new0(MultiFDSendData, 1); + multifd_send_state->data->opaque =3D multifd_pages_init(page_count); 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); @@ -1181,7 +1191,8 @@ 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 g_new0(MultiFDSendData, 1); + p->data->opaque =3D multifd_pages_init(page_count); =20 if (use_packets) { p->packet_len =3D sizeof(MultiFDPacket_t) @@ -1684,7 +1695,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->opaque; multifd_send_zero_page_detect(p); =20 if (!pages->normal_num) { diff --git a/migration/multifd.h b/migration/multifd.h index 0ecd6f47d7..2029bfd80a 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -16,6 +16,7 @@ #include "ram.h" =20 typedef struct MultiFDRecvData MultiFDRecvData; +typedef struct MultiFDSendData MultiFDSendData; =20 bool multifd_send_setup(void); void multifd_send_shutdown(void); @@ -89,6 +90,11 @@ struct MultiFDRecvData { off_t file_offset; }; =20 +struct MultiFDSendData { + void *opaque; + size_t size; +}; + typedef struct { /* Fields are only written at creating/deletion time */ /* No lock required for them, they are read only */ @@ -131,12 +137,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 Mon Nov 25 02:05:47 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=1718918521; cv=none; d=zohomail.com; s=zohoarc; b=nm/Sr8DS2d4nMG9KscbqtjPLoaQmXGwUcNDOlLZ8MKR+RozoTuWbuUkKvihV7DWOpeu9PjdAIK9EZ70WaM96sr3Ysv1QsK4tAXQY3n+H/abxr2PmwL+v6pQFlMNnZgtRSO8rF1a2vHhq3Aj0pG+jYrJqeP7C/RahOYy944lihqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918521; 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=nWM0DEqicz0Jg1qFZiAZd1DDln0brGsaOXQkR5WZ0F4=; b=FlD/KACfmUxtlMHLf6wOPZui+YL/IYRi20eGzIVfkiHkDVQxWLHUoQtLWHeFh6kGn9SJ7HoUfV9zgjiUStKVhibg7hnlZq0vyPCtMNOwMRA+fDT1lwV1OL1HJEfG4dcegBm1Q5msryYu8mQUfGrMDbnoOM9p1auOQLK/pzA69ZY= 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 1718918521580523.9645267532247; Thu, 20 Jun 2024 14:22:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDl-0000tT-1z; Thu, 20 Jun 2024 17:21:29 -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 1sKPDi-0000rs-9v for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:26 -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 1sKPDg-0007Fl-N9 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:26 -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 93C0B21AE9; Thu, 20 Jun 2024 21:21: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 62CE21369F; Thu, 20 Jun 2024 21:21: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 oLGjClCddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918481; 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=nWM0DEqicz0Jg1qFZiAZd1DDln0brGsaOXQkR5WZ0F4=; b=aE9g2poGey1XanWwXE6JKPi0MCoPBI7UV+1UucimSagzCIClQXRR5ir+C3iXUhpzB3m83I Y1DMLLwLqBR0Z31r9petRwn8qbWKFhx0ln++ooJmjAswrCq3ZEJILslAfZJUUYHqu5K5iS w0wCvER6aGKJCKlO4V3LIc7hxcJD1F0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918481; 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=nWM0DEqicz0Jg1qFZiAZd1DDln0brGsaOXQkR5WZ0F4=; b=51HGSuu18I2cH6+/SSnz+uDgIoYe1FwJR9FyCOLJbydTX7vsQtg3S7ZgrHPWZZqxHuyt/5 6PatP1xWr9bfM9CA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=aE9g2poG; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=51HGSuu1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918481; 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=nWM0DEqicz0Jg1qFZiAZd1DDln0brGsaOXQkR5WZ0F4=; b=aE9g2poGey1XanWwXE6JKPi0MCoPBI7UV+1UucimSagzCIClQXRR5ir+C3iXUhpzB3m83I Y1DMLLwLqBR0Z31r9petRwn8qbWKFhx0ln++ooJmjAswrCq3ZEJILslAfZJUUYHqu5K5iS w0wCvER6aGKJCKlO4V3LIc7hxcJD1F0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918481; 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=nWM0DEqicz0Jg1qFZiAZd1DDln0brGsaOXQkR5WZ0F4=; b=51HGSuu18I2cH6+/SSnz+uDgIoYe1FwJR9FyCOLJbydTX7vsQtg3S7ZgrHPWZZqxHuyt/5 6PatP1xWr9bfM9CA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 4/7] migration/multifd: Move pages accounting into multifd_send_zero_page_detect() Date: Thu, 20 Jun 2024 18:21:08 -0300 Message-Id: <20240620212111.29319-5-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 93C0B21AE9 X-Spam-Score: -4.01 X-Spamd-Result: default: False [-4.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_LOW(-1.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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718918523234100011 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. Signed-off-by: Fabiano Rosas --- migration/multifd-zero-page.c | 4 ++++ migration/multifd.c | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/multifd-zero-page.c b/migration/multifd-zero-page.c index 1ad77462a4..63a1c24ba8 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" @@ -74,6 +75,9 @@ void multifd_send_zero_page_detect(MultiFDSendParams *p) } =20 pages->normal_num =3D i; + + 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 55b31c4515..c4a952576d 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -975,8 +975,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 Mon Nov 25 02:05:47 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=1718918520; cv=none; d=zohomail.com; s=zohoarc; b=ncAzpVjzix2un+cYr1EXEQ6kFb8VNVFScE0S0m4dV/459oqcA8RUTqUyYbDd2i1JIFxi7evJOiQZuLQK6q3d0fe9E67oxG2aWBvGOJqYZ/vOMXbrHz1fnslKYjDDjpTdobUfWbEE/jLpg6HbUijDp6XfJl2skxYmfOzDBHTMxAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918520; 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=MIn+SH76t9uhG6rbk0QerWFG2heKJCS5IiUb1AYNQv4=; b=Qe+Mkh6gSHaWaiceoZBGMA0FlR6KeGkCRXyhxHYH3tfvYKSb/Zc3EXLYIavKfqBJA0wdOH9NL0wFF0awuYejuruy3cbUc0XBSK1wB5UWeh+nVTNTVhhNss5ZllqvCi2j0Vkqiu8R4WUT3ng8igoxKQq5ovZhUlE6rYtpCw5ryrM= 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 1718918520819783.6611453582107; Thu, 20 Jun 2024 14:22:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDk-0000tQ-OC; Thu, 20 Jun 2024 17:21:28 -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 1sKPDi-0000sP-QV for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:26 -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 1sKPDg-0007Fw-NF for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:26 -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 2D39221AED; Thu, 20 Jun 2024 21:21: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 057CB1369F; Thu, 20 Jun 2024 21:21: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 GFONL1GddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918483; 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=MIn+SH76t9uhG6rbk0QerWFG2heKJCS5IiUb1AYNQv4=; b=uc55DwPL7k5VdikQeB38yp3jtSAMxitSaZrH9a8daFYKHcLK5KxYC3YxeG3J5jThzP+b2d ZLSuI+oFhP1scySBpKrgWE6JI75UU3OgfSJUGIbCSfi1+tZdM3yhcsX3+cJHnzf2ZchKGz EMurLNI+zF0LM5r/CrEiV4WEEUSWXSU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918483; 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=MIn+SH76t9uhG6rbk0QerWFG2heKJCS5IiUb1AYNQv4=; b=47YxLQ53ShOWkSgPyqetLfITWyFCE+l1F0wn6atN+jKkmBGqHyB+IEstt9GShYC79aaYI6 sMmyejJomgMTQlBQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=uc55DwPL; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=47YxLQ53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918483; 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=MIn+SH76t9uhG6rbk0QerWFG2heKJCS5IiUb1AYNQv4=; b=uc55DwPL7k5VdikQeB38yp3jtSAMxitSaZrH9a8daFYKHcLK5KxYC3YxeG3J5jThzP+b2d ZLSuI+oFhP1scySBpKrgWE6JI75UU3OgfSJUGIbCSfi1+tZdM3yhcsX3+cJHnzf2ZchKGz EMurLNI+zF0LM5r/CrEiV4WEEUSWXSU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918483; 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=MIn+SH76t9uhG6rbk0QerWFG2heKJCS5IiUb1AYNQv4=; b=47YxLQ53ShOWkSgPyqetLfITWyFCE+l1F0wn6atN+jKkmBGqHyB+IEstt9GShYC79aaYI6 sMmyejJomgMTQlBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 5/7] migration/multifd: Isolate ram pages packet data Date: Thu, 20 Jun 2024 18:21:09 -0300 Message-Id: <20240620212111.29319-6-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-4.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_LOW(-1.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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 2D39221AED X-Spam-Score: -4.01 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718918521996100005 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 | 104 +++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 36 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index c4a952576d..6fe339b378 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -407,65 +407,64 @@ static void multifd_pages_clear(MultiFDPages_t *pages) g_free(pages); } =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->opaque; - 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(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); - - 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, +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++; + + if (p->data) { + multifd_ram_fill_packet(p); + } + + trace_multifd_send(p->id, packet_num, + be32_to_cpu(packet->normal_pages), + be32_to_cpu(packet->zero_pages), p->flags, p->next_packet_size); } =20 -static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) +static int multifd_ram_unfill_packet(MultiFDRecvParams *p, Error **errp) { MultiFDPacket_t *packet =3D p->packet; 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 @@ -494,15 +493,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; } @@ -544,6 +537,45 @@ 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++; + + if (p->flags & MULTIFD_FLAG_SYNC) { + p->normal_num =3D 0; + p->zero_num =3D 0; + } else { + ret =3D multifd_ram_unfill_packet(p, errp); + } + + trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->zero_num, + p->flags, p->next_packet_size); + + return ret; +} + static bool multifd_send_should_exit(void) { return qatomic_read(&multifd_send_state->exiting); --=20 2.35.3 From nobody Mon Nov 25 02:05:47 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=1718918567; cv=none; d=zohomail.com; s=zohoarc; b=m7NWAmgg2IP+teQ2XJz1lP2tI6LKXGFFxWFAgbncoO1eCaizabykElH/PUwixqIWSF4CR59V41L+z0ltaWtP9FG1YagflYlwCIJYKMDCp6zm9Uqg/T0ZH1gYti9O7akoeaNEMzurpZcOZgtJ8ZgS17RmDnqDayEyFnL+D7Z9ECw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918567; 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=xUZ7U02vafxzx7h6uqHVC6ik0KAEACkxC08XokYcrjU=; b=eq3pA3VdYZCesywjqn53ikJdt5Z3/8Fg25Mt0nyevsupsPDieLNftCxgGvrEMRjsqDd9Mw28mZ7ETDOuqAuMKrZDMgDX+jsw+9bvA1J7AVG5RKs8X0fCbekfDQXGRyzujP6tB3OwCT5Mh580CCda2H4pbIUasILkDZ+0NpmdNOY= 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 1718918567112226.54719372670422; Thu, 20 Jun 2024 14:22:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDl-0000tn-Mq; Thu, 20 Jun 2024 17:21:29 -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 1sKPDk-0000tF-Ea for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:28 -0400 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKPDi-0007G8-28 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:28 -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 CE82A1F8B4; Thu, 20 Jun 2024 21:21: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 A81031369F; Thu, 20 Jun 2024 21:21: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 yH0NG1OddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918484; 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=xUZ7U02vafxzx7h6uqHVC6ik0KAEACkxC08XokYcrjU=; b=DZb1GZrpHZLiCdTGyJlIQuczZzV9Ta0OqUJ/2TpDjueYd8FiH0iLUV1P46XAa3Vqw+uV9V Qvb+TALEYeNr5YgtQg18wAvsQSeLim/9ynw7Hxsk0+6dO+c/Z/tEaMuK0ClHZTSEGveQLT 2Y3IWBSpCQ7/TFSnDotLd0T0Y0zWVns= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918484; 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=xUZ7U02vafxzx7h6uqHVC6ik0KAEACkxC08XokYcrjU=; b=hc+g1btSK9+eamCo3C2Sxa+ISTfORLXN5AyqLoH6YYE1zZ4yvxwjB9icBgiASvTCJGzPIQ uPfD4SRNOvvPK8AA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=DZb1GZrp; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hc+g1btS DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918484; 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=xUZ7U02vafxzx7h6uqHVC6ik0KAEACkxC08XokYcrjU=; b=DZb1GZrpHZLiCdTGyJlIQuczZzV9Ta0OqUJ/2TpDjueYd8FiH0iLUV1P46XAa3Vqw+uV9V Qvb+TALEYeNr5YgtQg18wAvsQSeLim/9ynw7Hxsk0+6dO+c/Z/tEaMuK0ClHZTSEGveQLT 2Y3IWBSpCQ7/TFSnDotLd0T0Y0zWVns= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918484; 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=xUZ7U02vafxzx7h6uqHVC6ik0KAEACkxC08XokYcrjU=; b=hc+g1btSK9+eamCo3C2Sxa+ISTfORLXN5AyqLoH6YYE1zZ4yvxwjB9icBgiASvTCJGzPIQ uPfD4SRNOvvPK8AA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 6/7] migration/multifd: Move payload storage out of the channel parameters Date: Thu, 20 Jun 2024 18:21:10 -0300 Message-Id: <20240620212111.29319-7-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: CE82A1F8B4 X-Spam-Score: -4.01 X-Spamd-Result: default: False [-4.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_LOW(-1.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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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:2; 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718918567467100005 Content-Type: text/plain; charset="utf-8" Multifd currently has a simple scheduling mechanism that distributes work to the various channels by providing the client (producer) with a memory slot and swapping that slot with free slot from the next idle channel (consumer). Or graphically: [] <-- multifd_send_state->pages [][][][] <-- channels' p->pages pointers 1) client fills the empty slot with data: [a] [][][][] 2) multifd_send_pages() finds an idle channel and swaps the pointers: [a] [][][][] ^idle [] [a][][][] 3) client can immediately fill new slot with more data: [b] [a][][][] 4) channel processes the data, the channel slot is now free to use again: [b] [][][][] This works just fine, except that it 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 needs to be duplicated by adding new fields to multifd_send_state and to the channels. The core of the issue here is that we're using the channel parameters (MultiFDSendParams) to hold the storage space on behalf of the multifd client (currently ram.c). This is cumbersome because it forces us to change multifd_send_pages() to check the data type being handled before deciding which field to use. One way to solve this is to detach the storage space from the multifd channel and put it somewhere else, in control of the multifd client. That way, multifd_send_pages() can operate on an opaque pointer without needing to be adapted to each new data type. Implement this logic with a new "slots" abstraction: struct MultiFDSendData { void *opaque; size_t size; } struct MultiFDSlots { MultiFDSendData **free; <-- what used to be p->pages MultiFDSendData *active; <-- what used to be multifd_send_state->pages }; Each multifd client now gets one set of slots to use. The slots are passed into multifd_send_pages() (renamed to multifd_send). The channels now only hold a pointer to the generic MultiFDSendData, and after it's processed that reference can be dropped. Or graphically: 1) client fills the active slot with data. Channels point to nothing at this point: [a] <-- active slot [][][][] <-- free slots, one per-channel [][][][] <-- channels' p->data pointers 2) multifd_send() swaps the pointers inside the client slot. Channels still point to nothing: [] [a][][][] [][][][] 3) multifd_send() finds an idle channel and updates its pointer: [] [a][][][] [a][][][] ^idle 4) a second client calls multifd_send(), but with it's own slots: [] [b] [a][][][] [][][][] [a][][][] 5) multifd_send() does steps 2 and 3 again: [] [] [a][][][] [][b][][] [a][b][][] ^idle 6) The channels continue processing the data and lose/acquire the references as multifd_send() updates them. The free lists of each client are not affected. Signed-off-by: Fabiano Rosas --- migration/multifd.c | 119 +++++++++++++++++++++++++++++++------------- migration/multifd.h | 17 +++++++ migration/ram.c | 1 + 3 files changed, 102 insertions(+), 35 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 6fe339b378..f22a1c2e84 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -97,6 +97,30 @@ struct { MultiFDMethods *ops; } *multifd_recv_state; =20 +MultiFDSlots *multifd_allocate_slots(void *(*alloc_fn)(void), + void (*reset_fn)(void *), + void (*cleanup_fn)(void *)) +{ + int thread_count =3D migrate_multifd_channels(); + MultiFDSlots *slots =3D g_new0(MultiFDSlots, 1); + + slots->active =3D g_new0(MultiFDSendData, 1); + slots->free =3D g_new0(MultiFDSendData *, thread_count); + + slots->active->opaque =3D alloc_fn(); + slots->active->reset =3D reset_fn; + slots->active->cleanup =3D cleanup_fn; + + for (int i =3D 0; i < thread_count; i++) { + slots->free[i] =3D g_new0(MultiFDSendData, 1); + slots->free[i]->opaque =3D alloc_fn(); + slots->free[i]->reset =3D reset_fn; + slots->free[i]->cleanup =3D cleanup_fn; + } + + return slots; +} + static bool multifd_use_packets(void) { return !migrate_mapped_ram(); @@ -313,8 +337,10 @@ void multifd_register_ops(int method, MultiFDMethods *= ops) } =20 /* Reset a MultiFDPages_t* object for the next use */ -static void multifd_pages_reset(MultiFDPages_t *pages) +static void multifd_pages_reset(void *opaque) { + MultiFDPages_t *pages =3D opaque; + /* * We don't need to touch offset[] array, because it will be * overwritten later when reused. @@ -388,8 +414,9 @@ static int multifd_recv_initial_packet(QIOChannel *c, E= rror **errp) return msg.id; } =20 -static MultiFDPages_t *multifd_pages_init(uint32_t n) +static void *multifd_pages_init(void) { + uint32_t n =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); MultiFDPages_t *pages =3D g_new0(MultiFDPages_t, 1); =20 pages->allocated =3D n; @@ -398,13 +425,24 @@ static MultiFDPages_t *multifd_pages_init(uint32_t n) return pages; } =20 -static void multifd_pages_clear(MultiFDPages_t *pages) +static void multifd_pages_clear(void *opaque) { + MultiFDPages_t *pages =3D opaque; + multifd_pages_reset(pages); pages->allocated =3D 0; g_free(pages->offset); pages->offset =3D NULL; - g_free(pages); +} + +/* TODO: move these to multifd-ram.c */ +MultiFDSlots *multifd_ram_send_slots; + +void multifd_ram_save_setup(void) +{ + multifd_ram_send_slots =3D multifd_allocate_slots(multifd_pages_init, + multifd_pages_reset, + multifd_pages_clear); } =20 static void multifd_ram_fill_packet(MultiFDSendParams *p) @@ -617,13 +655,12 @@ static void multifd_send_kick_main(MultiFDSendParams = *p) * * Returns true if succeed, false otherwise. */ -static bool multifd_send_pages(void) +static bool multifd_send(MultiFDSlots *slots) { int i; static int next_channel; MultiFDSendParams *p =3D NULL; /* make happy gcc */ - MultiFDPages_t *channel_pages; - MultiFDSendData *data =3D multifd_send_state->data; + MultiFDSendData *active_slot; =20 if (multifd_send_should_exit()) { return false; @@ -659,11 +696,24 @@ static bool multifd_send_pages(void) */ smp_mb_acquire(); =20 - channel_pages =3D p->data->opaque; - assert(!channel_pages->num); + assert(!slots->free[p->id]->size); + + /* + * Swap the slots. The client gets a free slot to fill up for the + * next iteration and the channel gets the active slot for + * processing. + */ + active_slot =3D slots->active; + slots->active =3D slots->free[p->id]; + p->data =3D active_slot; + + /* + * By the next time we arrive here, the channel will certainly + * have consumed the active slot. Put it back on the free list + * now. + */ + slots->free[p->id] =3D active_slot; =20 - multifd_send_state->data =3D p->data; - p->data =3D data; /* * Making sure p->data is setup before marking pending_job=3Dtrue. Pai= rs * with the qatomic_load_acquire() in multifd_send_thread(). @@ -687,6 +737,7 @@ static inline bool multifd_queue_full(MultiFDPages_t *p= ages) static inline void multifd_enqueue(MultiFDPages_t *pages, ram_addr_t offse= t) { pages->offset[pages->num++] =3D offset; + multifd_ram_send_slots->active->size +=3D qemu_target_page_size(); } =20 /* Returns true if enqueue successful, false otherwise */ @@ -695,7 +746,7 @@ bool multifd_queue_page(RAMBlock *block, ram_addr_t off= set) MultiFDPages_t *pages; =20 retry: - pages =3D multifd_send_state->data->opaque; + pages =3D multifd_ram_send_slots->active->opaque; =20 /* If the queue is empty, we can already enqueue now */ if (multifd_queue_empty(pages)) { @@ -713,7 +764,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_slots)) { return false; } goto retry; @@ -825,10 +876,12 @@ static bool multifd_send_cleanup_channel(MultiFDSendP= arams *p, Error **errp) qemu_sem_destroy(&p->sem_sync); g_free(p->name); p->name =3D NULL; - multifd_pages_clear(p->data->opaque); - p->data->opaque =3D NULL; - g_free(p->data); - p->data =3D NULL; + if (p->data) { + p->data->cleanup(p->data->opaque); + p->data->opaque =3D NULL; + /* p->data was not allocated by us, just clear the pointer */ + p->data =3D NULL; + } p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; @@ -845,10 +898,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; - multifd_pages_clear(multifd_send_state->data->opaque); - multifd_send_state->data->opaque =3D NULL; - g_free(multifd_send_state->data); - multifd_send_state->data =3D NULL; g_free(multifd_send_state); multifd_send_state =3D NULL; } @@ -897,14 +946,13 @@ 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->opaque; - if (pages->num) { - if (!multifd_send_pages()) { + + if (multifd_ram_send_slots->active->size) { + if (!multifd_send(multifd_ram_send_slots)) { error_report("%s: multifd_send_pages fail", __func__); return -1; } @@ -979,13 +1027,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->opaque; - p->iovs_num =3D 0; - assert(pages->num); + assert(p->data->size); =20 ret =3D multifd_send_state->ops->send_prepare(p, &local_err); if (ret !=3D 0) { @@ -1008,13 +1054,20 @@ 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; =20 + /* + * The data has now been sent. Since multifd_send() + * already put this slot on the free list, reset the + * entire slot before releasing the barrier below. + */ + p->data->size =3D 0; + p->data->reset(p->data->opaque); + /* * 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 { @@ -1208,8 +1261,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 g_new0(MultiFDSendData, 1); - multifd_send_state->data->opaque =3D multifd_pages_init(page_count); 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); @@ -1221,8 +1272,6 @@ bool multifd_send_setup(void) qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->sem_sync, 0); p->id =3D i; - p->data =3D g_new0(MultiFDSendData, 1); - p->data->opaque =3D multifd_pages_init(page_count); =20 if (use_packets) { p->packet_len =3D sizeof(MultiFDPacket_t) diff --git a/migration/multifd.h b/migration/multifd.h index 2029bfd80a..5230729077 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -17,6 +17,10 @@ =20 typedef struct MultiFDRecvData MultiFDRecvData; typedef struct MultiFDSendData MultiFDSendData; +typedef struct MultiFDSlots MultiFDSlots; + +typedef void *(multifd_data_alloc_cb)(void); +typedef void (multifd_data_cleanup_cb)(void *); =20 bool multifd_send_setup(void); void multifd_send_shutdown(void); @@ -93,8 +97,21 @@ struct MultiFDRecvData { struct MultiFDSendData { void *opaque; size_t size; + /* reset the slot for reuse after successful transfer */ + void (*reset)(void *); + void (*cleanup)(void *); }; =20 +struct MultiFDSlots { + MultiFDSendData **free; + MultiFDSendData *active; +}; + +MultiFDSlots *multifd_allocate_slots(void *(*alloc_fn)(void), + void (*reset_fn)(void *), + void (*cleanup_fn)(void *)); +void multifd_ram_save_setup(void); + typedef struct { /* Fields are only written at creating/deletion time */ /* No lock required for them, they are read only */ diff --git a/migration/ram.c b/migration/ram.c index ceea586b06..c33a9dcf3f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3058,6 +3058,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 Mon Nov 25 02:05:47 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=1718918585; cv=none; d=zohomail.com; s=zohoarc; b=JoTWKne9lmSL9ut5HrOHEVIQUuSP7YIwDEL4WdkLcc2DkfQhUAmzNmaRR2w5UeTtrUkMZjfImEleJZ2Xyn1xkaD2KeTchXGGjjbmZSbxieXnOE5L6be6wQBnuwwmW7vM1YHlwEj7BhOX6fLhE9H66eePgY6hPxOVbN7tnQunWrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918585; 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=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=U8YCE+ahbUzWcViWDxR7rVXtRAdhqr4apqSSlyaiMbsf6u+xju6g+NOX0+msGWfO1Cn3kXQOYChADs+a19Fdb4qnNKjka5uT7UvtQIzNwkESGZNxb8kJk2F4Ef8yVmT41Ej+0tFbV+noMYJXZBZ7/fyfA8wOeoycVmLwGDQPDAY= 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 171891858554459.077511153328146; Thu, 20 Jun 2024 14:23:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDn-0000uH-Aw; Thu, 20 Jun 2024 17:21:31 -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 1sKPDl-0000ti-DP for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:29 -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 1sKPDj-0007GX-PJ for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:29 -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 75B3B1F8B6; Thu, 20 Jun 2024 21:21: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 4DD0A1369F; Thu, 20 Jun 2024 21:21: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 iGZmBVWddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918486; 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=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=FGNWovgJBiV3omDJPA/xgpP5M+zJ47SYkWQ7JMhWs69YuIGluCz7oilYjKKX7w13foxtEy OlWKnFkLpUFcJp5IIF4FsGnDao3VzjY5qfcM5FORltp7/8+aqY6Y85GazIcdP/lL9tzx5I TtmQMlb5w/W4LnK1HnrBF3i0u1t66r4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918486; 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=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=WEtEnsXgF9ms6/B8qRELGOJJYsajyTkuvZhKAo/askcWgDpQURxdqcbqBQ1zEa/I6jAIJH Kb2T+uwX9NyiQgBw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918486; 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=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=FGNWovgJBiV3omDJPA/xgpP5M+zJ47SYkWQ7JMhWs69YuIGluCz7oilYjKKX7w13foxtEy OlWKnFkLpUFcJp5IIF4FsGnDao3VzjY5qfcM5FORltp7/8+aqY6Y85GazIcdP/lL9tzx5I TtmQMlb5w/W4LnK1HnrBF3i0u1t66r4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918486; 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=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=WEtEnsXgF9ms6/B8qRELGOJJYsajyTkuvZhKAo/askcWgDpQURxdqcbqBQ1zEa/I6jAIJH Kb2T+uwX9NyiQgBw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 7/7] migration/multifd: Hide multifd slots implementation Date: Thu, 20 Jun 2024 18:21:11 -0300 Message-Id: <20240620212111.29319-8-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 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)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718918587544100003 Content-Type: text/plain; charset="utf-8" The only two things the multifd client needs to access are the active slot and the active slot size: The active slot itself is obviously needed because it's where the data is put. The slot size is needed only by the ram pages code, because it does not fill the data slot and sends it in one go, it instead fills the slot partially at each call of multifd_queue_page(), so the size is needed to differentiate an empty slot (free or recently consumed) from the slot that is partially full. Hide the MultiFDSlots implementation so the client is not tempted to make use of the free list. That field is there simply because we need the client to carry a handle to that memory, it's not supposed to be accessed directly. Signed-off-by: Fabiano Rosas --- migration/multifd.c | 26 +++++++++++++++++++++++--- migration/multifd.h | 8 +++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index f22a1c2e84..9fb719eb0d 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -38,6 +38,11 @@ #define MULTIFD_MAGIC 0x11223344U #define MULTIFD_VERSION 1 =20 +struct MultiFDSlots { + MultiFDSendData **free; + MultiFDSendData *active; +}; + typedef struct { uint32_t magic; uint32_t version; @@ -737,7 +742,22 @@ static inline bool multifd_queue_full(MultiFDPages_t *= pages) static inline void multifd_enqueue(MultiFDPages_t *pages, ram_addr_t offse= t) { pages->offset[pages->num++] =3D offset; - multifd_ram_send_slots->active->size +=3D qemu_target_page_size(); + multifd_set_slot_size(multifd_ram_send_slots, qemu_target_page_size()); +} + +void *multifd_get_active_slot(MultiFDSlots *multifd_ram_send_slots) +{ + return multifd_ram_send_slots->active->opaque; +} + +void multifd_set_slot_size(MultiFDSlots *multifd_ram_send_slots, size_t si= ze) +{ + multifd_ram_send_slots->active->size +=3D size; +} + +bool multifd_slot_has_data(MultiFDSlots *multifd_ram_send_slots) +{ + return !!multifd_ram_send_slots->active->size; } =20 /* Returns true if enqueue successful, false otherwise */ @@ -746,7 +766,7 @@ bool multifd_queue_page(RAMBlock *block, ram_addr_t off= set) MultiFDPages_t *pages; =20 retry: - pages =3D multifd_ram_send_slots->active->opaque; + pages =3D multifd_get_active_slot(multifd_ram_send_slots); =20 /* If the queue is empty, we can already enqueue now */ if (multifd_queue_empty(pages)) { @@ -951,7 +971,7 @@ int multifd_send_sync_main(void) return 0; } =20 - if (multifd_ram_send_slots->active->size) { + if (multifd_slot_has_data(multifd_ram_send_slots)) { if (!multifd_send(multifd_ram_send_slots)) { error_report("%s: multifd_send_pages fail", __func__); return -1; diff --git a/migration/multifd.h b/migration/multifd.h index 5230729077..8f99fe2652 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -102,15 +102,13 @@ struct MultiFDSendData { void (*cleanup)(void *); }; =20 -struct MultiFDSlots { - MultiFDSendData **free; - MultiFDSendData *active; -}; - MultiFDSlots *multifd_allocate_slots(void *(*alloc_fn)(void), void (*reset_fn)(void *), void (*cleanup_fn)(void *)); void multifd_ram_save_setup(void); +void *multifd_get_active_slot(MultiFDSlots *multifd_ram_send_slots); +void multifd_set_slot_size(MultiFDSlots *multifd_ram_send_slots, size_t si= ze); +bool multifd_slot_has_data(MultiFDSlots *multifd_ram_send_slots); =20 typedef struct { /* Fields are only written at creating/deletion time */ --=20 2.35.3