File xen.sr-restore-pfns.patch of Package xen
From: Olaf Hering <olaf@aepfle.de>
Date: Fri, 23 Oct 2020 14:36:45 +0200
Subject: sr restore pfns
tools/guest: restore: move pfns array
Remove allocation from hotpath, move pfns array into preallocated space.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
tools/libs/guest/xg_sr_common.h | 2 ++
tools/libs/guest/xg_sr_restore.c | 6 ++----
2 files changed, 4 insertions(+), 4 deletions(-)
--- a/tools/libs/guest/xg_sr_common.h
+++ b/tools/libs/guest/xg_sr_common.h
@@ -215,24 +215,26 @@ struct xc_sr_save_arrays {
xen_pfn_t types[MAX_BATCH_SIZE];
/* write_batch: Errors from attempting to map the gfns. */
int errors[MAX_BATCH_SIZE];
/* write_batch: iovec[] for writev(). */
struct iovec iov[MAX_BATCH_SIZE + 4];
/* write_batch */
uint64_t rec_pfns[MAX_BATCH_SIZE];
/* write_batch: Pointers to page data to send. Mapped gfns or local allocations. */
void *guest_data[MAX_BATCH_SIZE];
};
struct xc_sr_restore_arrays {
+ /* handle_page_data */
+ xen_pfn_t 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
@@ -306,25 +306,25 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned int count,
/*
* Validate a PAGE_DATA record from the stream, and pass the results to
* process_page_data() to actually perform the legwork.
*/
static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
{
xc_interface *xch = ctx->xch;
struct xc_sr_rec_page_data_header *pages = rec->data;
unsigned int i, pages_of_data = 0;
int rc = -1;
- xen_pfn_t *pfns = NULL, pfn;
+ xen_pfn_t *pfns = ctx->restore.m->pfns, pfn;
uint32_t *types = NULL, type;
/*
* v2 compatibility only exists for x86 streams. This is a bit of a
* bodge, but it is less bad than duplicating handle_page_data() between
* different architectures.
*/
#if defined(__i386__) || defined(__x86_64__)
/* v2 compat. Infer the position of STATIC_DATA_END. */
if ( ctx->restore.format_version < 3 && !ctx->restore.seen_static_data_end )
{
rc = handle_static_data_end(ctx);
@@ -354,27 +354,26 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
{
ERROR("Expected at least 1 pfn in PAGE_DATA record");
goto err;
}
if ( rec->length < sizeof(*pages) + (pages->count * sizeof(uint64_t)) )
{
ERROR("PAGE_DATA record (length %u) too short to contain %u"
" pfns worth of information", rec->length, pages->count);
goto err;
}
- pfns = malloc(pages->count * sizeof(*pfns));
types = malloc(pages->count * sizeof(*types));
- if ( !pfns || !types )
+ if ( !types )
{
ERROR("Unable to allocate enough memory for %u pfns",
pages->count);
goto err;
}
for ( i = 0; i < pages->count; ++i )
{
pfn = pages->pfn[i] & PAGE_DATA_PFN_MASK;
if ( !ctx->restore.ops.pfn_is_valid(ctx, pfn) )
{
ERROR("pfn %#"PRIpfn" (index %u) outside domain maximum", pfn, i);
@@ -403,25 +402,24 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
(PAGE_SIZE * pages_of_data)) )
{
ERROR("PAGE_DATA record wrong size: length %u, expected "
"%zu + %zu + %lu", rec->length, sizeof(*pages),
(sizeof(uint64_t) * pages->count), (PAGE_SIZE * pages_of_data));
goto err;
}
rc = process_page_data(ctx, pages->count, pfns, types,
&pages->pfn[pages->count]);
err:
free(types);
- free(pfns);
return rc;
}
/*
* Send checkpoint dirty pfn list to primary.
*/
static int send_checkpoint_dirty_pfn_list(struct xc_sr_context *ctx)
{
xc_interface *xch = ctx->xch;
int rc = -1;
unsigned int count, written;