From nobody Mon Feb 9 21:12:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162619962336761.20851299222454; Tue, 13 Jul 2021 11:07:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.155552.287254 (Exim 4.92) (envelope-from ) id 1m3Mnz-0008Nu-6N; Tue, 13 Jul 2021 18:06:51 +0000 Received: by outflank-mailman (output) from mailman id 155552.287254; Tue, 13 Jul 2021 18:06:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m3Mny-0008Ln-QF; Tue, 13 Jul 2021 18:06:50 +0000 Received: by outflank-mailman (input) for mailman id 155552; Tue, 13 Jul 2021 18:06:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m3Mnx-0002UL-Gz for xen-devel@lists.xenproject.org; Tue, 13 Jul 2021 18:06:49 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.171]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a7527314-1255-4f65-8912-cbbd84ac5443; Tue, 13 Jul 2021 18:06:24 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx6DI6ItAz (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 13 Jul 2021 20:06:18 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a7527314-1255-4f65-8912-cbbd84ac5443 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1626199578; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=mxNpwWOhZuO/yAfsj1BhbOC7Eeea1lW7O20Bo/SSJmE=; b=HbNTpUkaCGH7smmG0mRQLhqgGG/1A9vgPoaBIZvvS0ju1bTcHhjH8bJgkThGS+5kj8 Vw7H9McJFKbB9GEXnNxveKT5SETAMzjYr49v6Kc514vP/JsCqEs0MwnmQ3pRbopO1w1V 66eiIFywf3sEEsjffgaqezJ8UAfuuOSDF3/FmW/O29dAe0p2e1fbkAUB88eFaQBneVmd O8X3VLh2RlkPObAi+kI7ivGHR0A0Sv08BX/gpSMLv3M0W2/X1VpC7JwfVHu4ohGRlsqX s9obyuUsrbhve2kMKU4nQ8owzFf/SAkXGWv6HdtumjWT4/HVHVnCXS7O3c9R1QMBP5W2 0IBQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgthqlagRsstpH9XYEN5v9xf7dypFU9ge5p0Oi0V" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210713 17/31] tools: restore: preallocate map_errs array Date: Tue, 13 Jul 2021 20:05:51 +0200 Message-Id: <20210713180605.12096-18-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713180605.12096-1-olaf@aepfle.de> References: <20210713180605.12096-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626199624053100001 Content-Type: text/plain; charset="utf-8" Remove repeated allocation from migration loop. There will never be more than MAX_BATCH_SIZE pages to process in an incoming batch. Allocate the space once. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 22 +++++++--------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 11e45dbdc5..336be98c93 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -259,6 +259,7 @@ struct xc_sr_context xen_pfn_t *pfns; uint32_t *types; xen_pfn_t *mfns; + int *map_errs; =20 int send_back_fd; unsigned long p2m_size; diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 24cd8c6a07..866a7c86cd 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -204,21 +204,12 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, xen_pfn_t *pfns, uint32_t *types, void *page_= data) { xc_interface *xch =3D ctx->xch; - int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; void *mapping =3D NULL, *guest_page =3D NULL; unsigned int i, /* i indexes the pfns from the record. */ j, /* j indexes the subset of pfns we decide to map. */ nr_pages =3D 0; =20 - if ( !map_errs ) - { - rc =3D -1; - ERROR("Failed to allocate %zu bytes to process page data", - count * sizeof(*map_errs)); - goto err; - } - rc =3D populate_pfns(ctx, count, pfns, types); if ( rc ) { @@ -240,7 +231,7 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, =20 mapping =3D guest_page =3D xenforeignmemory_map( xch->fmem, ctx->domid, PROT_READ | PROT_WRITE, - nr_pages, ctx->restore.mfns, map_errs); + nr_pages, ctx->restore.mfns, ctx->restore.map_errs); if ( !mapping ) { rc =3D -1; @@ -254,11 +245,11 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, if ( !page_type_has_stream_data(types[i]) ) continue; =20 - if ( map_errs[j] ) + if ( ctx->restore.map_errs[j] ) { rc =3D -1; ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], ctx->restore.mfns[j], types[i], map_errs[j]); + pfns[i], ctx->restore.mfns[j], types[i], ctx->restore.ma= p_errs[j]); goto err; } =20 @@ -296,8 +287,6 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, if ( mapping ) xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); =20 - free(map_errs); - return rc; } =20 @@ -717,7 +706,9 @@ static int setup(struct xc_sr_context *ctx) ctx->restore.pfns =3D malloc(MAX_BATCH_SIZE * sizeof(*ctx->restore.pfn= s)); ctx->restore.types =3D malloc(MAX_BATCH_SIZE * sizeof(*ctx->restore.ty= pes)); ctx->restore.mfns =3D malloc(MAX_BATCH_SIZE * sizeof(*ctx->restore.mfn= s)); - if ( !ctx->restore.pfns || !ctx->restore.types || !ctx->restore.mfns ) + ctx->restore.map_errs =3D malloc(MAX_BATCH_SIZE * sizeof(*ctx->restore= .map_errs)); + if ( !ctx->restore.pfns || !ctx->restore.types || !ctx->restore.mfns || + !ctx->restore.map_errs ) { ERROR("Unable to allocate memory"); rc =3D -1; @@ -754,6 +745,7 @@ static void cleanup(struct xc_sr_context *ctx) =20 free(ctx->restore.buffered_records); free(ctx->restore.populated_pfns); + free(ctx->restore.map_errs); free(ctx->restore.mfns); free(ctx->restore.types); free(ctx->restore.pfns);