Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22BA0C07E96 for ; Tue, 13 Jul 2021 18:06:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E8DCE61369 for ; Tue, 13 Jul 2021 18:06:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8DCE61369 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aepfle.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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: 8bit 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_common.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; int send_back_fd; unsigned long p2m_size; diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_restore.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 *ctx, unsigned int count, xen_pfn_t *pfns, uint32_t *types, void *page_data) { xc_interface *xch = ctx->xch; - int *map_errs = malloc(count * sizeof(*map_errs)); int rc; void *mapping = NULL, *guest_page = NULL; unsigned int i, /* i indexes the pfns from the record. */ j, /* j indexes the subset of pfns we decide to map. */ nr_pages = 0; - if ( !map_errs ) - { - rc = -1; - ERROR("Failed to allocate %zu bytes to process page data", - count * sizeof(*map_errs)); - goto err; - } - rc = 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, mapping = guest_page = 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 = -1; @@ -254,11 +245,11 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned int count, if ( !page_type_has_stream_data(types[i]) ) continue; - if ( map_errs[j] ) + if ( ctx->restore.map_errs[j] ) { rc = -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.map_errs[j]); goto err; } @@ -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); - free(map_errs); - return rc; } @@ -717,7 +706,9 @@ static int setup(struct xc_sr_context *ctx) ctx->restore.pfns = malloc(MAX_BATCH_SIZE * sizeof(*ctx->restore.pfns)); ctx->restore.types = malloc(MAX_BATCH_SIZE * sizeof(*ctx->restore.types)); ctx->restore.mfns = malloc(MAX_BATCH_SIZE * sizeof(*ctx->restore.mfns)); - if ( !ctx->restore.pfns || !ctx->restore.types || !ctx->restore.mfns ) + ctx->restore.map_errs = 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 = -1; @@ -754,6 +745,7 @@ static void cleanup(struct xc_sr_context *ctx) 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);