From: Peter Xu <peterx@redhat.com>
To: Alexey Perevalov <a.perevalov@samsung.com>
Cc: qemu-devel@nongnu.org, i.maximets@samsung.com, eblake@redhat.com,
dgilbert@redhat.com
Subject: Re: [Qemu-devel] [PATCH V6 07/10] migration: add bitmap for copied page
Date: Wed, 24 May 2017 14:57:36 +0800 [thread overview]
Message-ID: <20170524065736.GF3873@pxdev.xzpeter.org> (raw)
In-Reply-To: <1495539071-12995-8-git-send-email-a.perevalov@samsung.com>
On Tue, May 23, 2017 at 02:31:08PM +0300, Alexey Perevalov wrote:
> This patch adds ability to track down already copied
> pages, it's necessary for calculation vCPU block time in
> postcopy migration feature and maybe for restore after
> postcopy migration failure.
>
> Functions which work with RAMBlock are placed into ram.c,
> due to TARGET_WORDS_BIGENDIAN is poisoned int postcopy-ram.c -
> hardware independed code.
>
> Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
> ---
> include/migration/migration.h | 16 +++++++++++
> migration/postcopy-ram.c | 22 ++++++++++++---
> migration/ram.c | 63 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 97 insertions(+), 4 deletions(-)
>
> diff --git a/include/migration/migration.h b/include/migration/migration.h
> index 449cb07..4e05c83 100644
> --- a/include/migration/migration.h
> +++ b/include/migration/migration.h
> @@ -101,6 +101,20 @@ struct MigrationIncomingState {
> LoadStateEntry_Head loadvm_handlers;
>
> /*
> + * bitmap indicates whether page copied,
> + * based on ramblock offset
> + * now it is using only for blocktime calculation in
> + * postcopy migration, so livetime of this entry:
> + * since user requested blocktime calculation,
> + * till the end of postcopy migration
> + * as an example it could represend following memory map
> + * ___________________________________
> + * |4k pages | hugepages | 4k pages
Can we really do this?
The problem is AFAIU migration stream is sending pages only in target
page size, even for huge pages... so even for huge pages we should
still need per TARGET_PAGE_SIZE bitmap?
(Please refer to ram_state_init() on init of RAMBlock.bmap)
> + *
> + * */
> + unsigned long *copied_pages;
> +
> + /*
> * PostcopyBlocktimeContext to keep information for postcopy
> * live migration, to calculate vCPU block time
> * */
> @@ -279,6 +293,8 @@ int migrate_compress_threads(void);
> int migrate_decompress_threads(void);
> bool migrate_use_events(void);
> bool migrate_postcopy_blocktime(void);
> +unsigned long int get_copied_bit_offset(ram_addr_t addr);
> +unsigned long int *copied_pages_bitmap_new(void);
>
> /* Sending on the return path - generic and then for each message type */
> void migrate_send_rp_message(MigrationIncomingState *mis,
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index 5435a40..d647769 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -94,23 +94,34 @@ static void destroy_blocktime_context(struct PostcopyBlocktimeContext *ctx)
>
> static void postcopy_migration_cb(Notifier *n, void *data)
> {
> - PostcopyBlocktimeContext *ctx = container_of(n, PostcopyBlocktimeContext,
> - postcopy_notifier);
> MigrationState *s = data;
> if (migration_has_finished(s) || migration_has_failed(s)) {
> + MigrationIncomingState *mis = migration_incoming_get_current();
> + PostcopyBlocktimeContext *ctx = mis->blocktime_ctx;
> +
> + if (!ctx) {
> + return;
> + }
If we are in postcopy_migration_cb() already, then we have registered
the notifiers, then... could this (!ctx) really happen?
> +
> g_free(ctx->page_fault_vcpu_time);
> /* g_free is NULL robust */
> ctx->page_fault_vcpu_time = NULL;
> g_free(ctx->vcpu_addr);
> ctx->vcpu_addr = NULL;
> + g_free(mis->copied_pages);
> + mis->copied_pages = NULL;
> }
> }
>
> static void migration_exit_cb(Notifier *n, void *data)
> {
> - PostcopyBlocktimeContext *ctx = container_of(n, PostcopyBlocktimeContext,
> - exit_notifier);
> + MigrationIncomingState *mis = migration_incoming_get_current();
> + PostcopyBlocktimeContext *ctx = mis->blocktime_ctx;
> + if (!ctx) {
> + return;
> + }
I failed to find out why touched this up...
Thanks,
> destroy_blocktime_context(ctx);
> + mis->blocktime_ctx = NULL;
> }
>
> static struct PostcopyBlocktimeContext *blocktime_context_new(void)
> @@ -227,6 +238,9 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
> mis->blocktime_ctx = blocktime_context_new();
> }
>
> + if (!mis->copied_pages) {
> + mis->copied_pages = copied_pages_bitmap_new();
> + }
> asked_features |= UFFD_FEATURE_THREAD_ID;
> }
> #endif
> diff --git a/migration/ram.c b/migration/ram.c
> index f59fdd4..1abb6bb 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -2661,6 +2661,69 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
> return ret;
> }
>
> +static unsigned long get_total_bits_per_page(ram_addr_t mem_length,
> + size_t page_size)
> +{
> + unsigned long page_size_bit = find_last_bit((unsigned long *)&page_size,
> + BITS_PER_LONG);
> + unsigned long total_bits = mem_length >> page_size_bit;
> + if (mem_length % page_size) {
> + total_bits += 1;
> + }
> + return total_bits;
> +}
> +
> +/*
> + * this function allocates bitmap for copied pages,
> + * also it calculates
> + * how many entries do we need
> + * */
> +unsigned long int *copied_pages_bitmap_new(void)
> +{
> + RAMBlock *block;
> + unsigned long int total_bits = 0;
> +
> + rcu_read_lock();
> + RAMBLOCK_FOREACH(block) {
> + /* in general case used_length may not be aligned
> + * by page_size */
> +
> + total_bits += get_total_bits_per_page(block->used_length,
> + block->page_size);
> + }
> + rcu_read_unlock();
> +
> + return bitmap_new(total_bits);
> +}
> +
> +unsigned long int get_copied_bit_offset(ram_addr_t addr)
> +{
> + RAMBlock *block;
> + unsigned long int iter_bit = 0;
> +
> + rcu_read_lock();
> + RAMBLOCK_FOREACH(block) {
> + /* in general case used_length may not be aligned
> + * by page_size */
> + if (block->host == NULL) {
> + continue;
> + }
> + if (addr - (ram_addr_t)block->host < block->max_length) {
> + unsigned long page_size_bit = find_last_bit(
> + (unsigned long *)&block->page_size,
> + BITS_PER_LONG);
> + ram_addr_t offset = addr - (ram_addr_t)block->host;
> + iter_bit += offset >> page_size_bit;
> + break;
> + }
> + iter_bit += get_total_bits_per_page(block->used_length,
> + block->page_size);
> + }
> + rcu_read_unlock();
> +
> + return iter_bit;
> +}
> +
> static SaveVMHandlers savevm_ram_handlers = {
> .save_live_setup = ram_save_setup,
> .save_live_iterate = ram_save_iterate,
> --
> 1.8.3.1
>
--
Peter Xu
next prev parent reply other threads:[~2017-05-24 6:57 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20170523113120eucas1p2032ace2121aa8627067b6d7f03fbf482@eucas1p2.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 00/10] calculate blocktime for postcopy live migration Alexey Perevalov
[not found] ` <CGME20170523113126eucas1p163c64fe50bd44026fdf4d36716bfc4f2@eucas1p1.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 01/10] userfault: add pid into uffd_msg & update UFFD_FEATURE_* Alexey Perevalov
[not found] ` <CGME20170523113127eucas1p22dba0fddcc9bcf70e554bf659272f947@eucas1p2.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 02/10] migration: pass MigrationIncomingState* into migration check functions Alexey Perevalov
2017-05-31 17:54 ` Dr. David Alan Gilbert
2017-06-05 5:59 ` Alexey Perevalov
2017-06-05 9:15 ` Dr. David Alan Gilbert
[not found] ` <CGME20170523113127eucas1p1b6cebc0fc51a056b8c1a983d375f1012@eucas1p1.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 03/10] migration: fix hardcoded function name in error report Alexey Perevalov
[not found] ` <CGME20170523113128eucas1p17a89f8cb47d5731c50f94c3218ba155f@eucas1p1.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 04/10] migration: split ufd_version_check onto receive/request features part Alexey Perevalov
2017-05-24 2:36 ` Peter Xu
2017-05-24 6:45 ` Alexey
2017-05-24 11:33 ` Peter Xu
2017-05-24 11:47 ` Alexey Perevalov
2017-05-31 19:12 ` Dr. David Alan Gilbert
[not found] ` <CGME20170523113129eucas1p2146e1018e660eed0b319cbe22adc2712@eucas1p2.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 05/10] migration: introduce postcopy-blocktime capability Alexey Perevalov
[not found] ` <CGME20170523113129eucas1p179082f20f41d1069f5fbd0f37535fae9@eucas1p1.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 06/10] migration: add postcopy blocktime ctx into MigrationIncomingState Alexey Perevalov
2017-05-24 3:31 ` Peter Xu
2017-06-05 6:31 ` Alexey Perevalov
[not found] ` <CGME20170523113130eucas1p1babac9d8659c10abe22ddc7d5b9526ab@eucas1p1.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 07/10] migration: add bitmap for copied page Alexey Perevalov
2017-05-24 6:57 ` Peter Xu [this message]
2017-05-24 7:56 ` Alexey
2017-05-24 12:01 ` Peter Xu
2017-05-24 12:16 ` Alexey Perevalov
2017-05-24 23:30 ` Peter Xu
2017-05-25 6:28 ` Alexey Perevalov
2017-05-25 7:25 ` Peter Xu
2017-05-31 19:25 ` Dr. David Alan Gilbert
[not found] ` <CGME20170523113131eucas1p24a041de6004237e437f97a24340507e2@eucas1p2.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 08/10] migration: calculate vCPU blocktime on dst side Alexey Perevalov
2017-05-24 7:53 ` Peter Xu
2017-05-24 9:37 ` Alexey
2017-05-24 11:22 ` Peter Xu
2017-05-24 11:37 ` Alexey Perevalov
2017-06-01 10:07 ` Dr. David Alan Gilbert
2017-06-01 10:50 ` Dr. David Alan Gilbert
2017-06-01 10:57 ` Dr. David Alan Gilbert
2017-06-07 7:34 ` Alexey Perevalov
[not found] ` <CGME20170523113131eucas1p1ec4e059c13ce977e3a3872c343e6b858@eucas1p1.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 09/10] migration: add postcopy total blocktime into query-migrate Alexey Perevalov
2017-06-01 11:35 ` Dr. David Alan Gilbert
[not found] ` <CGME20170523113132eucas1p19143aceccbb30a0051635cddcf376bb6@eucas1p1.samsung.com>
2017-05-23 11:31 ` [Qemu-devel] [PATCH V6 10/10] migration: postcopy_blocktime documentation Alexey Perevalov
2017-06-01 11:37 ` Dr. David Alan Gilbert
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=20170524065736.GF3873@pxdev.xzpeter.org \
--to=peterx@redhat.com \
--cc=a.perevalov@samsung.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=i.maximets@samsung.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).