All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xenproject.org
Cc: Olaf Hering <olaf@aepfle.de>, Ian Jackson <iwj@xenproject.org>,
	Wei Liu <wl@xen.org>, Anthony PERARD <anthony.perard@citrix.com>
Subject: [PATCH v20210111 14/39] tools/guest: prepare to allocate arrays once
Date: Mon, 11 Jan 2021 18:41:59 +0100	[thread overview]
Message-ID: <20210111174224.24714-15-olaf@aepfle.de> (raw)
In-Reply-To: <20210111174224.24714-1-olaf@aepfle.de>

The hotpath 'send_dirty_pages' is supposed to do just one thing: sending.
The other end 'handle_page_data' is supposed to do just receiving.

But instead both do other costly work like memory allocations and data moving.
Do the allocations once, the array sizes are a compiletime constant.
Avoid unneeded copying of data by receiving data directly into mapped guest memory.

This patch is just prepartion, subsequent changes will populate the arrays.

Once all changes are applied, migration of a busy HVM domU changes like that:

Without this series, from sr650 to sr950 (xen-4.15.20201027T173911.16a20963b3 xen_testing):
2020-10-29 10:23:10.711+0000: xc: show_transfer_rate: 23663128 bytes + 2879563 pages in 55.324905335 sec, 203 MiB/sec: Internal error
2020-10-29 10:23:35.115+0000: xc: show_transfer_rate: 16829632 bytes + 2097552 pages in 24.401179720 sec, 335 MiB/sec: Internal error
2020-10-29 10:23:59.436+0000: xc: show_transfer_rate: 16829032 bytes + 2097478 pages in 24.319025928 sec, 336 MiB/sec: Internal error
2020-10-29 10:24:23.844+0000: xc: show_transfer_rate: 16829024 bytes + 2097477 pages in 24.406992500 sec, 335 MiB/sec: Internal error
2020-10-29 10:24:48.292+0000: xc: show_transfer_rate: 16828912 bytes + 2097463 pages in 24.446489027 sec, 335 MiB/sec: Internal error
2020-10-29 10:25:01.816+0000: xc: show_transfer_rate: 16836080 bytes + 2098356 pages in 13.447091818 sec, 609 MiB/sec: Internal error

With this series, from sr650 to sr950 (xen-4.15.20201027T173911.16a20963b3 xen_unstable):
2020-10-28 21:26:05.074+0000: xc: show_transfer_rate: 23663128 bytes + 2879563 pages in 52.564054368 sec, 213 MiB/sec: Internal error
2020-10-28 21:26:23.527+0000: xc: show_transfer_rate: 16830040 bytes + 2097603 pages in 18.450592015 sec, 444 MiB/sec: Internal error
2020-10-28 21:26:41.926+0000: xc: show_transfer_rate: 16830944 bytes + 2097717 pages in 18.397862306 sec, 445 MiB/sec: Internal error
2020-10-28 21:27:00.339+0000: xc: show_transfer_rate: 16829176 bytes + 2097498 pages in 18.411973339 sec, 445 MiB/sec: Internal error
2020-10-28 21:27:18.643+0000: xc: show_transfer_rate: 16828592 bytes + 2097425 pages in 18.303326695 sec, 447 MiB/sec: Internal error
2020-10-28 21:27:26.289+0000: xc: show_transfer_rate: 16835952 bytes + 2098342 pages in 7.579846749 sec, 1081 MiB/sec: Internal error

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/libs/guest/xg_sr_common.h  | 8 ++++++++
 tools/libs/guest/xg_sr_restore.c | 8 ++++++++
 tools/libs/guest/xg_sr_save.c    | 4 +++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_common.h
index f3a7a29298..62bc87b5f4 100644
--- a/tools/libs/guest/xg_sr_common.h
+++ b/tools/libs/guest/xg_sr_common.h
@@ -211,6 +211,12 @@ static inline int update_blob(struct xc_sr_blob *blob,
     return 0;
 }
 
+struct xc_sr_save_arrays {
+};
+
+struct xc_sr_restore_arrays {
+};
+
 struct xc_sr_context
 {
     xc_interface *xch;
@@ -248,6 +254,7 @@ struct xc_sr_context
             unsigned long *deferred_pages;
             unsigned long nr_deferred_pages;
             xc_hypercall_buffer_t dirty_bitmap_hbuf;
+            struct xc_sr_save_arrays *m;
         } save;
 
         struct /* Restore data. */
@@ -299,6 +306,7 @@ struct xc_sr_context
 
             /* Sender has invoked verify mode on the stream. */
             bool verify;
+            struct xc_sr_restore_arrays *m;
         } restore;
     };
 
diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_restore.c
index 0332ae9f32..4a9ece9681 100644
--- a/tools/libs/guest/xg_sr_restore.c
+++ b/tools/libs/guest/xg_sr_restore.c
@@ -739,6 +739,13 @@ static int setup(struct xc_sr_context *ctx)
     }
     ctx->restore.allocated_rec_num = DEFAULT_BUF_RECORDS;
 
+    ctx->restore.m = malloc(sizeof(*ctx->restore.m));
+    if ( !ctx->restore.m ) {
+        ERROR("Unable to allocate memory for arrays");
+        rc = -1;
+        goto err;
+    }
+
  err:
     return rc;
 }
@@ -757,6 +764,7 @@ static void cleanup(struct xc_sr_context *ctx)
         xc_hypercall_buffer_free_pages(
             xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->restore.p2m_size)));
 
+    free(ctx->restore.m);
     free(ctx->restore.buffered_records);
     free(ctx->restore.populated_pfns);
 
diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c
index da031fcfce..baaeb12762 100644
--- a/tools/libs/guest/xg_sr_save.c
+++ b/tools/libs/guest/xg_sr_save.c
@@ -853,8 +853,9 @@ static int setup(struct xc_sr_context *ctx)
     ctx->save.batch_pfns = malloc(MAX_BATCH_SIZE *
                                   sizeof(*ctx->save.batch_pfns));
     ctx->save.deferred_pages = bitmap_alloc(ctx->save.p2m_size);
+    ctx->save.m = malloc(sizeof(*ctx->save.m));
 
-    if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pages )
+    if ( !ctx->save.m || !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pages )
     {
         ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and"
               " deferred pages");
@@ -886,6 +887,7 @@ static void cleanup(struct xc_sr_context *ctx)
                                    NRPAGES(bitmap_size(ctx->save.p2m_size)));
     free(ctx->save.deferred_pages);
     free(ctx->save.batch_pfns);
+    free(ctx->save.m);
 }
 
 /*


  parent reply	other threads:[~2021-01-11 17:43 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 17:41 [PATCH v20210111 00/39] leftover from 2020 Olaf Hering
2021-01-11 17:41 ` [PATCH v20210111 01/39] stubdom: fix tpm_version Olaf Hering
2021-01-11 18:06   ` Samuel Thibault
2021-01-11 17:41 ` [PATCH v20210111 02/39] xl: use proper name for bash_completion file Olaf Hering
2021-02-08 15:48   ` Ian Jackson
2021-01-11 17:41 ` [PATCH v20210111 03/39] docs: remove stale create example from xl.1 Olaf Hering
2021-02-08 15:41   ` Ian Jackson
2021-02-08 15:42   ` Ian Jackson
2021-01-11 17:41 ` [PATCH v20210111 04/39] docs: substitute XEN_CONFIG_DIR in xl.conf.5 Olaf Hering
2021-02-08 15:45   ` Ian Jackson
2021-01-11 17:41 ` [PATCH v20210111 05/39] tools: add with-xen-scriptdir configure option Olaf Hering
2021-02-08 16:03   ` Ian Jackson
2021-02-08 17:23     ` Olaf Hering
2021-02-08 17:48       ` Ian Jackson
2021-02-08 17:54         ` Olaf Hering
2021-02-08 17:55           ` Ian Jackson
2021-01-11 17:41 ` [PATCH v20210111 06/39] Use XEN_SCRIPT_DIR to refer to /etc/xen/scripts Olaf Hering
2021-02-08 16:04   ` Ian Jackson
2021-02-08 16:23     ` Ian Jackson
2021-01-11 17:41 ` [PATCH v20210111 07/39] xl: optionally print timestamps during xl migrate Olaf Hering
2021-02-08 16:22   ` Ian Jackson
2021-02-08 17:30     ` Olaf Hering
2021-02-08 17:47       ` Ian Jackson
2021-02-08 18:53     ` Olaf Hering
2021-01-11 17:41 ` [PATCH v20210111 08/39] xl: fix description of migrate --debug Olaf Hering
2021-02-08 16:25   ` Ian Jackson
2021-02-08 16:39     ` Andrew Cooper
2021-02-09 12:42       ` Olaf Hering
2021-01-11 17:41 ` [PATCH v20210111 09/39] tools: add readv_exact to libxenctrl Olaf Hering
2021-01-11 17:41 ` [PATCH v20210111 10/39] tools: add xc_is_known_page_type " Olaf Hering
2021-01-11 17:41 ` [PATCH v20210111 11/39] tools: use xc_is_known_page_type Olaf Hering
2021-01-11 17:41 ` [PATCH v20210111 12/39] tools: unify type checking for data pfns in migration stream Olaf Hering
2021-01-11 17:41 ` [PATCH v20210111 13/39] tools: show migration transfer rate in send_dirty_pages Olaf Hering
2021-01-11 17:41 ` Olaf Hering [this message]
2021-01-11 17:42 ` [PATCH v20210111 15/39] tools/guest: save: move batch_pfns Olaf Hering
2021-02-08 17:46   ` Ian Jackson
2021-01-11 17:42 ` [PATCH v20210111 16/39] tools/guest: save: move mfns array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 17/39] tools/guest: save: move types array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 18/39] tools/guest: save: move errors array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 19/39] tools/guest: save: move iov array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 20/39] tools/guest: save: move rec_pfns array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 21/39] tools/guest: save: move guest_data array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 22/39] tools/guest: save: move local_pages array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 23/39] tools/guest: restore: move pfns array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 24/39] tools/guest: restore: move types array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 25/39] tools/guest: restore: move mfns array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 26/39] tools/guest: restore: move map_errs array Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 27/39] tools/guest: restore: move mfns array in populate_pfns Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 28/39] tools/guest: restore: move pfns " Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 29/39] tools/guest: restore: split record processing Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 30/39] tools/guest: restore: split handle_page_data Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 31/39] tools/guest: restore: write data directly into guest Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 32/39] tools: remove tabs from code produced by libxl_save_msgs_gen.pl Olaf Hering
2021-02-08 16:28   ` Ian Jackson
2021-01-11 17:42 ` [PATCH v20210111 33/39] tools: recognize LIBXL_API_VERSION for 4.15 Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 34/39] tools: adjust libxl_domain_suspend to receive a struct props Olaf Hering
2021-01-12  9:17   ` Christian Lindig
2021-01-11 17:42 ` [PATCH v20210111 35/39] tools: change struct precopy_stats to precopy_stats_t Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 36/39] tools: add callback to libxl for precopy_policy and precopy_stats_t Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 37/39] tools: add --max_iters to libxl_domain_suspend Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 38/39] tools: add --min_remaining " Olaf Hering
2021-01-11 17:42 ` [PATCH v20210111 39/39] tools: add --abort_if_busy " Olaf Hering

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210111174224.24714-15-olaf@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=anthony.perard@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.