From nobody Sun Nov 24 10:39:11 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=1725454210; cv=none; d=zohomail.com; s=zohoarc; b=g11QWrJKfc2uNJ1P7CEVPtbQt/lfcS4G2Y0WFdSL2iyJGmWvSBAZThnrT03RyZ1MAQJad+YM0VgyWhdWhg2Az068k584zZFm3ZDPzaymcw3gHSGOsStfI4Nr0HbdZCU8sjcGGvZcafjSAoIJm7Ra+J/8QXrwusCGJhHFNpcd4H4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725454210; 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=m20m0r4QWCLMsSs8oz0T1IcCV7Rz+rDYdRTAHBTA5V0=; b=blHN85fuI+WLizeHbb5R+hMKA5EO+74Pfx/dWB9AgeIjabns8HvEu9sIYq3xQ2T3VfO2XJZCRhdU45goWr5aIjdT8vec1KNAHVV9Lr1milWgUmJcKuD1WBQKAW7FPU81eXSNtAbz/0QjTwnN5C6kK0h3dVVrAJDCarVZCVPvBDU= 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 1725454210113576.3175327763581; Wed, 4 Sep 2024 05:50:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slpNZ-0004x5-49; Wed, 04 Sep 2024 08:44:57 -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 1slpNQ-0004Pe-J5 for qemu-devel@nongnu.org; Wed, 04 Sep 2024 08:44:49 -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 1slpNN-0005Wt-Em for qemu-devel@nongnu.org; Wed, 04 Sep 2024 08:44:48 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4E8821F7BD; Wed, 4 Sep 2024 12:44:44 +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 233ED139D2; Wed, 4 Sep 2024 12:44:42 +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 iKKtNjpW2GZuVQAAD6G6ig (envelope-from ); Wed, 04 Sep 2024 12:44:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725453884; 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=m20m0r4QWCLMsSs8oz0T1IcCV7Rz+rDYdRTAHBTA5V0=; b=DKqaC2KG7ZMIoXf5XHbBvjNqm0rRSrZq3cRtdlNNPMwI4CLM8EcOQqe5HJwyChV8LUGgnG fuhKfn472/tm8EGfYz0HZF+3iiZk0GQSWd8UA3T4kNTr738OZ5u2XULLdCusr3yu53CwMI O1f+IJL4lLmfMbnxVUTy46erLuU83Fs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725453884; 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=m20m0r4QWCLMsSs8oz0T1IcCV7Rz+rDYdRTAHBTA5V0=; b=OFm0CobitZzSliU65W1qwvUa+68m0z99dArwK/MamKGOHsW6+QNbZQicin7243wkFVo5KZ fH1v8Dxm5HvekgDg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725453884; 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=m20m0r4QWCLMsSs8oz0T1IcCV7Rz+rDYdRTAHBTA5V0=; b=DKqaC2KG7ZMIoXf5XHbBvjNqm0rRSrZq3cRtdlNNPMwI4CLM8EcOQqe5HJwyChV8LUGgnG fuhKfn472/tm8EGfYz0HZF+3iiZk0GQSWd8UA3T4kNTr738OZ5u2XULLdCusr3yu53CwMI O1f+IJL4lLmfMbnxVUTy46erLuU83Fs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725453884; 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=m20m0r4QWCLMsSs8oz0T1IcCV7Rz+rDYdRTAHBTA5V0=; b=OFm0CobitZzSliU65W1qwvUa+68m0z99dArwK/MamKGOHsW6+QNbZQicin7243wkFVo5KZ fH1v8Dxm5HvekgDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Richard Henderson Subject: [PULL 13/34] migration/multifd: Inline page_size and page_count Date: Wed, 4 Sep 2024 09:43:56 -0300 Message-Id: <20240904124417.14565-14-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240904124417.14565-1-farosas@suse.de> References: <20240904124417.14565-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.79 X-Spamd-Result: default: False [-2.79 / 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.19)[-0.940]; 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:mid,suse.de:email]; RCVD_TLS_ALL(0.00)[] 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1725454211370116600 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. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas --- 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 0bd9c2253e..3dfed8a005 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); @@ -1157,7 +1162,7 @@ bool multifd_send_setup(void) { MigrationState *s =3D migrate_get_current(); 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)) { @@ -1569,7 +1572,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 @@ -1613,8 +1616,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