File xen.sr-restore-populate_pfns-pfns.patch of Package xen
From: Olaf Hering <olaf@aepfle.de>
Date: Fri, 23 Oct 2020 14:58:53 +0200
Subject: sr restore populate_pfns pfns
tools/guest: restore: move pfns array in populate_pfns
Remove allocation from hotpath, move populate_pfns' pfns array into preallocated space.
Use some prefix to avoid conflict with an array used in handle_page_data.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
tools/libs/guest/xg_sr_common.h | 1 +
tools/libs/guest/xg_sr_restore.c | 11 +----------
2 files changed, 2 insertions(+), 10 deletions(-)
--- a/tools/libs/guest/xg_sr_common.h
+++ b/tools/libs/guest/xg_sr_common.h
@@ -223,24 +223,25 @@ struct xc_sr_save_arrays {
void *guest_data[MAX_BATCH_SIZE];
};
struct xc_sr_restore_arrays {
/* handle_page_data */
xen_pfn_t pfns[MAX_BATCH_SIZE];
uint32_t types[MAX_BATCH_SIZE];
/* process_page_data */
xen_pfn_t mfns[MAX_BATCH_SIZE];
int map_errs[MAX_BATCH_SIZE];
/* populate_pfns */
xen_pfn_t pp_mfns[MAX_BATCH_SIZE];
+ xen_pfn_t pp_pfns[MAX_BATCH_SIZE];
};
struct xc_sr_context
{
xc_interface *xch;
uint32_t domid;
int fd;
/* Plain VM, or checkpoints over time. */
xc_stream_type_t stream_type;
xc_dominfo_t dominfo;
--- a/tools/libs/guest/xg_sr_restore.c
+++ b/tools/libs/guest/xg_sr_restore.c
@@ -130,35 +130,28 @@ static int pfn_set_populated(struct xc_sr_context *ctx, xen_pfn_t pfn)
}
/*
* Given a set of pfns, obtain memory from Xen to fill the physmap for the
* unpopulated subset. If types is NULL, no page type checking is performed
* and all unpopulated pfns are populated.
*/
int populate_pfns(struct xc_sr_context *ctx, unsigned int count,
const xen_pfn_t *original_pfns, const uint32_t *types)
{
xc_interface *xch = ctx->xch;
xen_pfn_t *mfns = ctx->restore.m->pp_mfns,
- *pfns = malloc(count * sizeof(*pfns));
+ *pfns = ctx->restore.m->pp_pfns;
unsigned int i, nr_pfns = 0;
int rc = -1;
- if ( !pfns )
- {
- ERROR("Failed to allocate %zu bytes for populating the physmap",
- 2 * count * sizeof(*mfns));
- goto err;
- }
-
for ( i = 0; i < count; ++i )
{
if ( (!types ||
(types && page_type_has_stream_data(types[i]) == true)) &&
!pfn_is_populated(ctx, original_pfns[i]) )
{
rc = pfn_set_populated(ctx, original_pfns[i]);
if ( rc )
goto err;
pfns[nr_pfns] = mfns[nr_pfns] = original_pfns[i];
++nr_pfns;
}
@@ -181,26 +174,24 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned int count,
ERROR("Populate physmap failed for pfn %u", i);
rc = -1;
goto err;
}
ctx->restore.ops.set_gfn(ctx, pfns[i], mfns[i]);
}
}
rc = 0;
err:
- free(pfns);
-
return rc;
}
/*
* Given a list of pfns, their types, and a block of page data from the
* stream, populate and record their types, map the relevant subset and copy
* the data into the guest.
*/
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;