[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v20210601 14/38] tools/guest: save: move iov array


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olaf Hering <olaf@xxxxxxxxx>
  • Date: Tue, 1 Jun 2021 18:10:54 +0200
  • Arc-authentication-results: i=1; strato.com; dkim=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563891; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=kIq3yzkr1orG0VWk81XmidxQ5pZTMt5qbdvFQWlb7zs=; b=UtyPia57fROHf4uKw/IvvaBpuizNrkgb0xR9uBnPu8azM4Y9z+LMDd2yPY9Rv1DqlP dVvfQAv1P37lX8P/lugVi81UjUGredLIj1wrEKzmDrlJnFFjpzfPOovx5KfGHuJf6/Og 1DVdu56tVECjja2o7b/0HusynbosHL5R8qzR+0IfOjbFje+/6E7fMrZhf9SXbNife8pE Kzy7fEh07yg65khvuG+LPfPGZAGeJLj19622yk7b3szhI++W3uFZPcoJS2zqb4vFTL+B HWsaFbVbIKcMMtUyvWlXqUMD9YLFz7scioMxWwZA8B3Kmta3oPwkYeQZtm7sOqcN+OP2 tJPw==
  • Arc-seal: i=1; a=rsa-sha256; t=1622563891; cv=none; d=strato.com; s=strato-dkim-0002; b=Xd7pOeVIiHYXGHD5gRxZOQBgSiSriTJtjfkH69uEPdEq+Nd1KZVpseWUuk97WuPxI1 qMRegzQl14wS6ijxza1EykXP/NXS714hp2STDA6QpEc6rD5hJuwbl3R7UKHQWH7Azusa C+wtWvtN1St4gDsTIg8KTa9Pi3vrpxL8lH1eSryoVSyDKldVJxGtIG9f78eZdTqOKuEI 8tYccyi/9BvOKkijUOB0irNLd3P/pz8VnqzTMkDNjuVpr7TPAmjtPi89Iknum9aROedD 3QEYjzmx7IZuMlJ9Pzt3ynOhYKKW6k9aNTGAULanPz+gfGYQnqET+TWastQ2rJ/0PRoA q6tw==
  • Authentication-results: strato.com; dkim=none
  • Cc: Olaf Hering <olaf@xxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 01 Jun 2021 16:12:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Remove allocation from hotpath, move iov array into preallocated space.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
---
 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 07dfa7d57d..b3294e79af 100644
--- a/tools/libs/saverestore/common.h
+++ b/tools/libs/saverestore/common.h
@@ -231,6 +231,8 @@ 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];
 };
 
 struct xc_sr_restore_arrays {
diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c
index 5033f18bef..1d9e55afe8 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);
 



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.