[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v20210616 15/36] tools: save: move iov array
Remove allocation from hotpath, move iov array into preallocated space. Signed-off-by: Olaf Hering <olaf@xxxxxxxxx> Reviewed-by: Juergen Gross <jgross@xxxxxxxx> --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/common.h index 558b5fbf06..ae87954364 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -231,6 +231,8 @@ struct 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]; }; struct sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 9ebbf00ce7..1a5f3d29ea 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -97,7 +97,7 @@ static int write_batch(struct xc_sr_context *ctx) unsigned int nr_pfns = ctx->save.nr_batch_pfns; void *page, *orig_page; uint64_t *rec_pfns = NULL; - struct iovec *iov = NULL; int iovcnt = 0; + struct iovec *iov = ctx->save.m->iov; int iovcnt = 0; struct xc_sr_rec_page_data_header hdr = { 0 }; struct xc_sr_record rec = { .type = REC_TYPE_PAGE_DATA, @@ -109,10 +109,8 @@ static int write_batch(struct xc_sr_context *ctx) guest_data = calloc(nr_pfns, sizeof(*guest_data)); /* Pointers to locally allocated pages. Need freeing. */ local_pages = calloc(nr_pfns, sizeof(*local_pages)); - /* iovec[] for writev(). */ - iov = malloc((nr_pfns + 4) * sizeof(*iov)); - if ( !guest_data || !local_pages || !iov ) + if ( !guest_data || !local_pages ) { ERROR("Unable to allocate arrays for a batch of %u pages", nr_pfns); @@ -266,7 +264,6 @@ static int write_batch(struct xc_sr_context *ctx) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i = 0; local_pages && i < nr_pfns; ++i ) free(local_pages[i]); - free(iov); free(local_pages); free(guest_data);
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |