From nobody Sun Nov 24 17:05:20 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