|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v7 5/6] libs/guest: allocate various migration arrays just once
From: Edwin Török <edwin.torok@xxxxxxxxxx>
Allocate these array just once at the start of migration,
using the maximum batch size, and free them at the end.
Signed-off-by: Edwin Török <edwin.torok@xxxxxxxxxx>
Signed-off-by: Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
---
Changes since v2:
- change prefix in subject.
Changes since v3:
- fix comment style
Changes since v4:
- change order of fields in structure.
Changes since v6:
- split preparation commit.
---
tools/libs/guest/xg_sr_common.h | 6 ++++++
tools/libs/guest/xg_sr_save.c | 33 ++++++++++++---------------------
2 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_common.h
index 7574c9f5b6..c07c6db59e 100644
--- a/tools/libs/guest/xg_sr_common.h
+++ b/tools/libs/guest/xg_sr_common.h
@@ -246,6 +246,12 @@ struct xc_sr_context
struct xc_sr_context_save_buffers
{
xen_pfn_t batch_pfns[MAX_BATCH_SIZE];
+ xen_pfn_t mfns[MAX_BATCH_SIZE];
+ xen_pfn_t types[MAX_BATCH_SIZE];
+ void *local_pages[MAX_BATCH_SIZE];
+ struct iovec iov[MAX_BATCH_SIZE + 2]; /* Headers + data. */
+ uint64_t rec_pfns[MAX_BATCH_SIZE];
+ int errors[MAX_BATCH_SIZE];
} *buffers;
} save;
diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c
index 8956f4260d..a49df00971 100644
--- a/tools/libs/guest/xg_sr_save.c
+++ b/tools/libs/guest/xg_sr_save.c
@@ -117,24 +117,18 @@ static int write_batch(struct xc_sr_context *ctx)
batch_pfns = ctx->save.buffers->batch_pfns;
/* Mfns of the batch pfns. */
- mfns = malloc(nr_pfns * sizeof(*mfns));
+ mfns = ctx->save.buffers->mfns;
/* Types of the batch pfns. */
- types = malloc(nr_pfns * sizeof(*types));
+ types = ctx->save.buffers->types;
/* Errors from attempting to map the gfns. */
- errors = malloc(nr_pfns * sizeof(*errors));
+ errors = ctx->save.buffers->errors;
/* Pointers to locally allocated pages. Need freeing. */
- local_pages = calloc(nr_pfns, sizeof(*local_pages));
+ local_pages = ctx->save.buffers->local_pages;
+ memset(local_pages, 0, sizeof(*local_pages) * nr_pfns);
/* iovec[] for writev(). */
- iov = malloc((nr_pfns + 2) * sizeof(*iov));
+ iov = ctx->save.buffers->iov;
/* page_data record PFNs list */
- rec_pfns = malloc(nr_pfns * sizeof(*rec_pfns));
-
- if ( !mfns || !types || !errors || !local_pages || !iov || !rec_pfns )
- {
- ERROR("Unable to allocate arrays for a batch of %u pages",
- nr_pfns);
- goto err;
- }
+ rec_pfns = ctx->save.buffers->rec_pfns;
iov[0].iov_base = &hdrs;
iov[0].iov_len = sizeof(hdrs);
@@ -253,13 +247,10 @@ static int write_batch(struct xc_sr_context *ctx)
if ( guest_mapping )
xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped);
for ( i = 0; local_pages && i < nr_pfns; ++i )
+ {
free(local_pages[i]);
- free(rec_pfns);
- free(iov);
- free(local_pages);
- free(errors);
- free(types);
- free(mfns);
+ local_pages[i] = NULL;
+ }
return rc;
}
@@ -793,8 +784,8 @@ static int setup(struct xc_sr_context *ctx)
if ( !ctx->save.buffers || !dirty_bitmap || !ctx->save.deferred_pages )
{
- ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and"
- " deferred pages");
+ ERROR("Unable to allocate memory for dirty bitmaps, deferred pages"
+ " and various batch buffers");
rc = -1;
errno = ENOMEM;
goto err;
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |