[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/21] migration/postcopy: allocate tmp_page in setup stage
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PULL 08/21] migration/postcopy: allocate tmp_page in setup stage |
Date: |
Fri, 11 Oct 2019 20:16:33 +0100 |
From: Wei Yang <address@hidden>
During migration, a tmp page is allocated so that we could place a whole
host page during postcopy.
Currently the page is allocated during load stage, this is a little bit
late. And more important, if we failed to allocate it, the error is not
checked properly. Even it is NULL, we would still use it.
This patch moves the allocation to setup stage and if failed error
message would be printed and caller would notice it.
Signed-off-by: Wei Yang <address@hidden>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
migration/postcopy-ram.c | 40 ++++++++++------------------------------
migration/postcopy-ram.h | 7 -------
migration/ram.c | 2 +-
3 files changed, 11 insertions(+), 38 deletions(-)
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 1f63e65ed7..9a16f52a79 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -1134,6 +1134,16 @@ int postcopy_ram_enable_notify(MigrationIncomingState
*mis)
return -1;
}
+ mis->postcopy_tmp_page = mmap(NULL, mis->largest_page_size,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE |
+ MAP_ANONYMOUS, -1, 0);
+ if (mis->postcopy_tmp_page == MAP_FAILED) {
+ mis->postcopy_tmp_page = NULL;
+ error_report("%s: Failed to map postcopy_tmp_page %s",
+ __func__, strerror(errno));
+ return -1;
+ }
+
/*
* Ballooning can mark pages as absent while we're postcopying
* that would cause false userfaults.
@@ -1260,30 +1270,6 @@ int postcopy_place_page_zero(MigrationIncomingState
*mis, void *host,
}
}
-/*
- * Returns a target page of memory that can be mapped at a later point in time
- * using postcopy_place_page
- * The same address is used repeatedly, postcopy_place_page just takes the
- * backing page away.
- * Returns: Pointer to allocated page
- *
- */
-void *postcopy_get_tmp_page(MigrationIncomingState *mis)
-{
- if (!mis->postcopy_tmp_page) {
- mis->postcopy_tmp_page = mmap(NULL, mis->largest_page_size,
- PROT_READ | PROT_WRITE, MAP_PRIVATE |
- MAP_ANONYMOUS, -1, 0);
- if (mis->postcopy_tmp_page == MAP_FAILED) {
- mis->postcopy_tmp_page = NULL;
- error_report("%s: %s", __func__, strerror(errno));
- return NULL;
- }
- }
-
- return mis->postcopy_tmp_page;
-}
-
#else
/* No target OS support, stubs just fail */
void fill_destination_postcopy_migration_info(MigrationInfo *info)
@@ -1341,12 +1327,6 @@ int postcopy_place_page_zero(MigrationIncomingState
*mis, void *host,
return -1;
}
-void *postcopy_get_tmp_page(MigrationIncomingState *mis)
-{
- assert(0);
- return NULL;
-}
-
int postcopy_wake_shared(struct PostCopyFD *pcfd,
uint64_t client_addr,
RAMBlock *rb)
diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h
index 9c8bd2bae0..fb4cd11d28 100644
--- a/migration/postcopy-ram.h
+++ b/migration/postcopy-ram.h
@@ -100,13 +100,6 @@ typedef enum {
POSTCOPY_INCOMING_END
} PostcopyState;
-/*
- * Allocate a page of memory that can be mapped at a later point in time
- * using postcopy_place_page
- * Returns: Pointer to allocated page
- */
-void *postcopy_get_tmp_page(MigrationIncomingState *mis);
-
PostcopyState postcopy_state_get(void);
/* Set the state and return the old state */
PostcopyState postcopy_state_set(PostcopyState new_state);
diff --git a/migration/ram.c b/migration/ram.c
index e29c8b3408..071687ef37 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -4032,7 +4032,7 @@ static int ram_load_postcopy(QEMUFile *f)
bool matches_target_page_size = false;
MigrationIncomingState *mis = migration_incoming_get_current();
/* Temporary page that is later 'placed' */
- void *postcopy_host_page = postcopy_get_tmp_page(mis);
+ void *postcopy_host_page = mis->postcopy_tmp_page;
void *last_host = NULL;
bool all_zero = false;
--
2.23.0
- [PULL 00/21] migration queue, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 01/21] migration: use migration_is_active to represent active state, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 02/21] rcu: Add automatically released rcu_read_lock variants, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 03/21] migration: Fix missing rcu_read_unlock, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 05/21] migration: Use automatic rcu_read unlock in rdma.c, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 08/21] migration/postcopy: allocate tmp_page in setup stage,
Dr. David Alan Gilbert (git) <=
- [PULL 04/21] migration: Use automatic rcu_read unlock in ram.c, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 06/21] rcu: Use automatic rc_read unlock in core memory/exec code, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 09/21] migration/postcopy: map large zero page in postcopy_ram_incoming_setup(), Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 07/21] migration: Don't try and recover return path in non-postcopy, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 11/21] migration: pass in_postcopy instead of check state again, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 10/21] migration/postcopy: fix typo in mark_postcopy_blocktime_begin's comment, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 12/21] migration: report SaveStateEntry id and name on failure, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 13/21] migration/postcopy: mis->have_listen_thread check will never be touched, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 14/21] migration/postcopy: postpone setting PostcopyState to END, Dr. David Alan Gilbert (git), 2019/10/11
- [PULL 15/21] migration/postcopy: rename postcopy_ram_enable_notify to postcopy_ram_incoming_setup, Dr. David Alan Gilbert (git), 2019/10/11