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

[PATCH v20210601 15/38] tools/guest: save: move rec_pfns array


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olaf Hering <olaf@xxxxxxxxx>
  • Date: Tue, 1 Jun 2021 18:10:55 +0200
  • Arc-authentication-results: i=1; strato.com; dkim=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563892; 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=3eJ8lfkM75YdRBwLz3IvZoNgnQXSN5j9vpY7FzwJfSQ=; b=PBFVi+mK0hxstPCEJ4VhRAjU21GlGzuN+SL++kGQ/i2BDcF/NfOW2Zsy3wsKFevozm o4kY2J/Avt2CWLPjOaLSDmdm17jyFDcBdbKGaD9WAwcDma/4ho4XGQyMuS6jsvRyaI3N Ta/4iLKMo0NAGLSyEpckb/ZVS1/NcJR0fQwyucnYiAFJL+uAWo063RuwiuV7fCDl9ZwD uKn5K9niilZV6BIkjqvujNtL389HLKKmVH4LyqQ6u6pGqn/MjPKgxIyekIIcd/tYs1WA q7HOMX2DHXg3YZ73w8EIU6oW3VFZkWWgjCKYiOq4or/zygr4dI2BNtWFBdivBL972paw Outw==
  • Arc-seal: i=1; a=rsa-sha256; t=1622563892; cv=none; d=strato.com; s=strato-dkim-0002; b=PfsEkPMGS+5tPzW4MpLS4b5cQT/mvpFrBoxLm5VNSVORaH7Jw7/RTMsrI2WRYVOtiF y2l8e9TSu1ykKVsd8PLopUW8TJm1oRPVaEIb4Y98rxmjmVHWmN3+YDLPf6mBVmr+gzrM aug2asGY0xM/8T3tEflKxKeKLeICjFCs+gGOU3naJsFTJs7RwvxANiR1pltU2F9hYoXs t+U67JjJ4Djq7ZjUvsYlQPCibe69wnN6nq1jq/oSoT4uXAiKLf3XpxekLghXdwNbB8lA IWyhxl+qrK0LjeVK/fbBOoc+u0EWtO9S8yP9jd8tz3wCPVDmW5n6SxOulL5iBi9t/vP1 qILg==
  • 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:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
---
 tools/libs/saverestore/common.h |  2 ++
 tools/libs/saverestore/save.c   | 11 +----------
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/common.h
index b3294e79af..6a2f266469 100644
--- a/tools/libs/saverestore/common.h
+++ b/tools/libs/saverestore/common.h
@@ -233,6 +233,8 @@ struct xc_sr_save_arrays {
     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];
 };
 
 struct xc_sr_restore_arrays {
diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c
index 1d9e55afe8..ba8046b530 100644
--- a/tools/libs/saverestore/save.c
+++ b/tools/libs/saverestore/save.c
@@ -96,7 +96,7 @@ static int write_batch(struct xc_sr_context *ctx)
     unsigned int i, p, nr_pages = 0, nr_pages_mapped = 0;
     unsigned int nr_pfns = ctx->save.nr_batch_pfns;
     void *page, *orig_page;
-    uint64_t *rec_pfns = NULL;
+    uint64_t *rec_pfns = ctx->save.m->rec_pfns;
     struct iovec *iov = ctx->save.m->iov; int iovcnt = 0;
     struct xc_sr_rec_page_data_header hdr = { 0 };
     struct xc_sr_record rec = {
@@ -201,14 +201,6 @@ static int write_batch(struct xc_sr_context *ctx)
         }
     }
 
-    rec_pfns = malloc(nr_pfns * sizeof(*rec_pfns));
-    if ( !rec_pfns )
-    {
-        ERROR("Unable to allocate %zu bytes of memory for page data pfn list",
-              nr_pfns * sizeof(*rec_pfns));
-        goto err;
-    }
-
     hdr.count = nr_pfns;
 
     rec.length = sizeof(hdr);
@@ -259,7 +251,6 @@ static int write_batch(struct xc_sr_context *ctx)
     rc = ctx->save.nr_batch_pfns = 0;
 
  err:
-    free(rec_pfns);
     if ( guest_mapping )
         xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped);
     for ( i = 0; local_pages && i < nr_pfns; ++i )



 


Rackspace

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