From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: dgilbert@redhat.com
Subject: [Qemu-devel] [PULL 28/65] ram: Move migration_bitmap_rcu into RAMState
Date: Fri, 21 Apr 2017 13:56:09 +0200 [thread overview]
Message-ID: <20170421115646.15544-29-quintela@redhat.com> (raw)
In-Reply-To: <20170421115646.15544-1-quintela@redhat.com>
Once there, rename the type to be shorter.
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
---
migration/ram.c | 86 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 47 insertions(+), 39 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 23819cd..f6ae17f 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -138,6 +138,19 @@ out:
return ret;
}
+struct RAMBitmap {
+ struct rcu_head rcu;
+ /* Main migration bitmap */
+ unsigned long *bmap;
+ /* bitmap of pages that haven't been sent even once
+ * only maintained and used in postcopy at the moment
+ * where it's used to send the dirtymap at the start
+ * of the postcopy phase
+ */
+ unsigned long *unsentmap;
+};
+typedef struct RAMBitmap RAMBitmap;
+
/* State of RAM for migration */
struct RAMState {
/* Last block that we have visited searching for dirty pages */
@@ -187,6 +200,8 @@ struct RAMState {
uint64_t migration_dirty_pages;
/* protects modification of the bitmap */
QemuMutex bitmap_mutex;
+ /* Ram Bitmap protected by RCU */
+ RAMBitmap *ram_bitmap;
};
typedef struct RAMState RAMState;
@@ -243,18 +258,6 @@ struct PageSearchStatus {
};
typedef struct PageSearchStatus PageSearchStatus;
-static struct BitmapRcu {
- struct rcu_head rcu;
- /* Main migration bitmap */
- unsigned long *bmap;
- /* bitmap of pages that haven't been sent even once
- * only maintained and used in postcopy at the moment
- * where it's used to send the dirtymap at the start
- * of the postcopy phase
- */
- unsigned long *unsentmap;
-} *migration_bitmap_rcu;
-
struct CompressParam {
bool done;
bool quit;
@@ -577,7 +580,7 @@ ram_addr_t migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb,
unsigned long next;
- bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+ bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
if (rs->ram_bulk_stage && nr > base) {
next = nr + 1;
} else {
@@ -592,7 +595,7 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs, ram_addr_t addr)
{
bool ret;
int nr = addr >> TARGET_PAGE_BITS;
- unsigned long *bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+ unsigned long *bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
ret = test_and_clear_bit(nr, bitmap);
@@ -606,7 +609,7 @@ static void migration_bitmap_sync_range(RAMState *rs, ram_addr_t start,
ram_addr_t length)
{
unsigned long *bitmap;
- bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+ bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
rs->migration_dirty_pages +=
cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length,
&rs->num_dirty_pages_period);
@@ -1149,14 +1152,14 @@ static bool get_queued_page(RAMState *rs, MigrationState *ms,
*/
if (block) {
unsigned long *bitmap;
- bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+ bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
dirty = test_bit(*ram_addr_abs >> TARGET_PAGE_BITS, bitmap);
if (!dirty) {
trace_get_queued_page_not_dirty(
block->idstr, (uint64_t)offset,
(uint64_t)*ram_addr_abs,
test_bit(*ram_addr_abs >> TARGET_PAGE_BITS,
- atomic_rcu_read(&migration_bitmap_rcu)->unsentmap));
+ atomic_rcu_read(&rs->ram_bitmap)->unsentmap));
} else {
trace_get_queued_page(block->idstr,
(uint64_t)offset,
@@ -1316,7 +1319,7 @@ static int ram_save_target_page(RAMState *rs, MigrationState *ms, QEMUFile *f,
if (res < 0) {
return res;
}
- unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
+ unsentmap = atomic_rcu_read(&rs->ram_bitmap)->unsentmap;
if (unsentmap) {
clear_bit(dirty_ram_abs >> TARGET_PAGE_BITS, unsentmap);
}
@@ -1480,7 +1483,7 @@ void free_xbzrle_decoded_buf(void)
xbzrle_decoded_buf = NULL;
}
-static void migration_bitmap_free(struct BitmapRcu *bmap)
+static void migration_bitmap_free(struct RAMBitmap *bmap)
{
g_free(bmap->bmap);
g_free(bmap->unsentmap);
@@ -1489,11 +1492,13 @@ static void migration_bitmap_free(struct BitmapRcu *bmap)
static void ram_migration_cleanup(void *opaque)
{
+ RAMState *rs = opaque;
+
/* caller have hold iothread lock or is in a bh, so there is
* no writing race against this migration_bitmap
*/
- struct BitmapRcu *bitmap = migration_bitmap_rcu;
- atomic_rcu_set(&migration_bitmap_rcu, NULL);
+ struct RAMBitmap *bitmap = rs->ram_bitmap;
+ atomic_rcu_set(&rs->ram_bitmap, NULL);
if (bitmap) {
memory_global_dirty_log_stop();
call_rcu(bitmap, migration_bitmap_free, rcu);
@@ -1530,9 +1535,9 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new)
/* called in qemu main thread, so there is
* no writing race against this migration_bitmap
*/
- if (migration_bitmap_rcu) {
- struct BitmapRcu *old_bitmap = migration_bitmap_rcu, *bitmap;
- bitmap = g_new(struct BitmapRcu, 1);
+ if (rs->ram_bitmap) {
+ struct RAMBitmap *old_bitmap = rs->ram_bitmap, *bitmap;
+ bitmap = g_new(struct RAMBitmap, 1);
bitmap->bmap = bitmap_new(new);
/* prevent migration_bitmap content from being set bit
@@ -1550,7 +1555,7 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new)
*/
bitmap->unsentmap = NULL;
- atomic_rcu_set(&migration_bitmap_rcu, bitmap);
+ atomic_rcu_set(&rs->ram_bitmap, bitmap);
qemu_mutex_unlock(&rs->bitmap_mutex);
rs->migration_dirty_pages += new - old;
call_rcu(old_bitmap, migration_bitmap_free, rcu);
@@ -1565,13 +1570,13 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new)
void ram_debug_dump_bitmap(unsigned long *todump, bool expected)
{
int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
-
+ RAMState *rs = &ram_state;
int64_t cur;
int64_t linelen = 128;
char linebuf[129];
if (!todump) {
- todump = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+ todump = atomic_rcu_read(&rs->ram_bitmap)->bmap;
}
for (cur = 0; cur < ram_pages; cur += linelen) {
@@ -1600,8 +1605,9 @@ void ram_debug_dump_bitmap(unsigned long *todump, bool expected)
void ram_postcopy_migrated_memory_release(MigrationState *ms)
{
+ RAMState *rs = &ram_state;
struct RAMBlock *block;
- unsigned long *bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+ unsigned long *bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
unsigned long first = block->offset >> TARGET_PAGE_BITS;
@@ -1636,11 +1642,12 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
unsigned long start,
unsigned long length)
{
+ RAMState *rs = &ram_state;
unsigned long end = start + length; /* one after the end */
unsigned long current;
unsigned long *unsentmap;
- unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
+ unsentmap = atomic_rcu_read(&rs->ram_bitmap)->unsentmap;
for (current = start; current < end; ) {
unsigned long one = find_next_bit(unsentmap, end, current);
@@ -1739,8 +1746,8 @@ static void postcopy_chunk_hostpages_pass(MigrationState *ms, bool unsent_pass,
return;
}
- bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
- unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
+ bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
+ unsentmap = atomic_rcu_read(&rs->ram_bitmap)->unsentmap;
if (unsent_pass) {
/* Find a sent page */
@@ -1898,15 +1905,16 @@ static int postcopy_chunk_hostpages(MigrationState *ms)
*/
int ram_postcopy_send_discard_bitmap(MigrationState *ms)
{
+ RAMState *rs = &ram_state;
int ret;
unsigned long *bitmap, *unsentmap;
rcu_read_lock();
/* This should be our last sync, the src is now paused */
- migration_bitmap_sync(&ram_state);
+ migration_bitmap_sync(rs);
- unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
+ unsentmap = atomic_rcu_read(&rs->ram_bitmap)->unsentmap;
if (!unsentmap) {
/* We don't have a safe way to resize the sentmap, so
* if the bitmap was resized it will be NULL at this
@@ -1927,7 +1935,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
/*
* Update the unsentmap to be unsentmap = unsentmap | dirty
*/
- bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
+ bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
bitmap_or(unsentmap, unsentmap, bitmap,
last_ram_offset() >> TARGET_PAGE_BITS);
@@ -2022,16 +2030,16 @@ static int ram_state_init(RAMState *rs)
bytes_transferred = 0;
ram_state_reset(rs);
- migration_bitmap_rcu = g_new0(struct BitmapRcu, 1);
+ rs->ram_bitmap = g_new0(struct RAMBitmap, 1);
/* Skip setting bitmap if there is no RAM */
if (ram_bytes_total()) {
ram_bitmap_pages = last_ram_offset() >> TARGET_PAGE_BITS;
- migration_bitmap_rcu->bmap = bitmap_new(ram_bitmap_pages);
- bitmap_set(migration_bitmap_rcu->bmap, 0, ram_bitmap_pages);
+ rs->ram_bitmap->bmap = bitmap_new(ram_bitmap_pages);
+ bitmap_set(rs->ram_bitmap->bmap, 0, ram_bitmap_pages);
if (migrate_postcopy_ram()) {
- migration_bitmap_rcu->unsentmap = bitmap_new(ram_bitmap_pages);
- bitmap_set(migration_bitmap_rcu->unsentmap, 0, ram_bitmap_pages);
+ rs->ram_bitmap->unsentmap = bitmap_new(ram_bitmap_pages);
+ bitmap_set(rs->ram_bitmap->unsentmap, 0, ram_bitmap_pages);
}
}
--
2.9.3
next prev parent reply other threads:[~2017-04-21 11:57 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-21 11:55 [Qemu-devel] [PULL 00/65] Migration pull request Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 01/65] ram: Update all functions comments Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 02/65] ram: Rename flush_page_queue() to migration_page_queue_free() Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 03/65] ram: Rename block_name to rbname Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 04/65] ram: Create RAMState Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 05/65] ram: Add dirty_rate_high_cnt to RAMState Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 06/65] ram: Move bitmap_sync_count into RAMState Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 07/65] ram: Move start time " Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 08/65] ram: Move bytes_xfer_prev " Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 09/65] ram: Change byte_xfer_{prev, now} type to uint64_t Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 10/65] ram: Move num_dirty_pages_period into RAMState Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 11/65] ram: Change num_dirty_pages_period type to uint64_t Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 12/65] ram: Move xbzrle_cache_miss_prev into RAMState Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 13/65] ram: Move iterations_prev " Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 14/65] ram: Move dup_pages " Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 15/65] ram: Remove unused dup_mig_bytes_transferred() Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 16/65] ram: Remove unused pages_skipped variable Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 17/65] ram: Move norm_pages to RAMState Juan Quintela
2017-04-21 11:55 ` [Qemu-devel] [PULL 18/65] ram: Remove norm_mig_bytes_transferred Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 19/65] ram: Move iterations into RAMState Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 20/65] ram: Move xbzrle_bytes " Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 21/65] ram: Move xbzrle_pages " Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 22/65] ram: Move xbzrle_cache_miss " Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 23/65] ram: Move xbzrle_cache_miss_rate " Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 24/65] ram: Move xbzrle_overflows " Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 25/65] ram: Move migration_dirty_pages to RAMState Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 26/65] ram: Everything was init to zero, so use memset Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 27/65] ram: Move migration_bitmap_mutex into RAMState Juan Quintela
2017-04-21 11:56 ` Juan Quintela [this message]
2017-04-21 11:56 ` [Qemu-devel] [PULL 29/65] ram: Move bytes_transferred " Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 30/65] ram: Use the RAMState bytes_transferred parameter Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 31/65] ram: Remove ram_save_remaining Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 32/65] ram: Move last_req_rb to RAMState Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 33/65] ram: Move src_page_req* " Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 34/65] ram: Create ram_dirty_sync_count() Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 35/65] ram: Remove dirty_bytes_rate Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 36/65] ram: Move dirty_pages_rate to RAMState Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 37/65] ram: Move postcopy_requests into RAMState Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 38/65] ram: Add QEMUFile to RAMState Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 39/65] ram: Move QEMUFile into RAMState Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 40/65] ram: Remove compression_switch and inline its logic Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 41/65] migration: Remove MigrationState from migration_in_postcopy Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 42/65] ram: We don't need MigrationState parameter anymore Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 43/65] ram: Rename qemu_target_page_bits() to qemu_target_page_size() Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 44/65] ram: Add page-size to output in 'info migrate' Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 45/65] ram: Pass RAMBlock to bitmap_sync Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 46/65] ram: ram_discard_range() don't use the mis parameter Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 47/65] ram: reorganize last_sent_block Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 48/65] ram: Use page number instead of an address for the bitmap operations Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 49/65] ram: Remember last_page instead of last_offset Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 50/65] ram: Change offset field in PageSearchStatus to page Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 51/65] ram: Use ramblock and page offset instead of absolute offset Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 52/65] ram: rename last_ram_offset() last_ram_pages() Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 53/65] ram: Use RAMBitmap type for coherence Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 54/65] migration: Remove MigrationState parameter from migration_is_idle() Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 55/65] qdev: qdev_hotplug is really a bool Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 56/65] qdev: Export qdev_hot_removed Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 57/65] qdev: Move qdev_unplug() to qdev-monitor.c Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 58/65] migration: Disable hotplug/unplug during migration Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 59/65] ram: Remove migration_bitmap_extend() Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 60/65] migration: don't close a file descriptor while it can be in use Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 61/65] virtio-rng: stop virtqueue while the CPU is stopped Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 62/65] migration: set current_active_state once Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 63/65] migration: rename max_size to threshold_size Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 64/65] hmp: info migrate_capability format tunes Juan Quintela
2017-04-21 11:56 ` [Qemu-devel] [PULL 65/65] hmp: info migrate_parameters " Juan Quintela
2017-04-21 16:09 ` [Qemu-devel] [PULL 00/65] Migration pull request Peter Maydell
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=20170421115646.15544-29-quintela@redhat.com \
--to=quintela@redhat.com \
--cc=dgilbert@redhat.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).