Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
migration: add migration capability to bypass the shared memory
Browse files Browse the repository at this point in the history
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
  • Loading branch information
laijs committed Aug 16, 2016
1 parent b0ea076 commit 162b05b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
5 changes: 5 additions & 0 deletions exec.c
Expand Up @@ -1334,6 +1334,11 @@ static RAMBlock *find_ram_block(ram_addr_t addr)
return NULL;
}

bool qemu_ram_is_shared(RAMBlock *rb)
{
return rb->flags & RAM_SHARED;
}

/* Called with iothread lock held. */
void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
{
Expand Down
2 changes: 2 additions & 0 deletions include/exec/cpu-all.h
Expand Up @@ -300,6 +300,8 @@ static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
return (char *)block->host + offset;
}

bool qemu_ram_is_shared(RAMBlock *rb);

typedef struct RAMList {
QemuMutex mutex;
/* Protected by the iothread lock. */
Expand Down
1 change: 1 addition & 0 deletions include/migration/migration.h
Expand Up @@ -178,6 +178,7 @@ int migrate_compress_level(void);
int migrate_compress_threads(void);
int migrate_decompress_threads(void);
bool migrate_use_events(void);
bool migrate_bypass_shared_memory(void);

void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
Expand Down
9 changes: 9 additions & 0 deletions migration/migration.c
Expand Up @@ -227,6 +227,15 @@ static void migrate_generate_event(int new_state)
}
}

bool migrate_bypass_shared_memory(void)
{
MigrationState *s;

s = migrate_get_current();

return s->enabled_capabilities[MIGRATION_CAPABILITY_BYPASS_SHARED_MEMORY];
}

/*
* Called on -incoming with a defer: uri.
* The migration can be started later after any parameters have been
Expand Down
33 changes: 26 additions & 7 deletions migration/ram.c
Expand Up @@ -546,6 +546,28 @@ static void migration_bitmap_sync_init(void)
num_dirty_pages_period = 0;
xbzrle_cache_miss_prev = 0;
iterations_prev = 0;
migration_dirty_pages = 0;
}

static void migration_bitmap_init(unsigned long *bitmap)
{
RAMBlock *block;

bitmap_clear(bitmap, 0, last_ram_offset() >> TARGET_PAGE_BITS);
rcu_read_lock();
QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
if (!migrate_bypass_shared_memory() || !qemu_ram_is_shared(block)) {
bitmap_set(bitmap, block->offset >> TARGET_PAGE_BITS,
block->used_length >> TARGET_PAGE_BITS);

/*
* Count the total number of pages used by ram blocks not including
* any gaps due to alignment or unplugs.
*/
migration_dirty_pages += block->used_length >> TARGET_PAGE_BITS;
}
}
rcu_read_unlock();
}

/* Called with iothread lock held, to protect ram_list.dirty_memory[] */
Expand Down Expand Up @@ -573,7 +595,9 @@ static void migration_bitmap_sync(void)
qemu_mutex_lock(&migration_bitmap_mutex);
rcu_read_lock();
QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
migration_bitmap_sync_range(block->mr->ram_addr, block->used_length);
if (!migrate_bypass_shared_memory() || !qemu_ram_is_shared(block)) {
migration_bitmap_sync_range(block->offset, block->used_length);
}
}
rcu_read_unlock();
qemu_mutex_unlock(&migration_bitmap_mutex);
Expand Down Expand Up @@ -1147,12 +1171,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
ram_bitmap_pages = last_ram_offset() >> TARGET_PAGE_BITS;
migration_bitmap = bitmap_new(ram_bitmap_pages);
bitmap_set(migration_bitmap, 0, ram_bitmap_pages);

/*
* Count the total number of pages used by ram blocks not including any
* gaps due to alignment or unplugs.
*/
migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
migration_bitmap_init(migration_bitmap);

memory_global_dirty_log_start();
migration_bitmap_sync();
Expand Down
6 changes: 5 additions & 1 deletion qapi-schema.json
Expand Up @@ -529,11 +529,15 @@
# @auto-converge: If enabled, QEMU will automatically throttle down the guest
# to speed up convergence of RAM migration. (since 1.6)
#
# @bypass-shared-memory: the shared memory region will be bypassed on migration.
# This feature allows the memory region to be reused by new qemu(s)
# or be migrated separately. (since 2.6)
#
# Since: 1.2
##
{ 'enum': 'MigrationCapability',
'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
'compress', 'events'] }
'compress', 'events', 'bypass-shared-memory'] }

##
# @MigrationCapabilityStatus
Expand Down
2 changes: 2 additions & 0 deletions qmp-commands.hx
Expand Up @@ -3407,6 +3407,7 @@ Enable/Disable migration capabilities
- "auto-converge": throttle down guest to help convergence of migration
- "zero-blocks": compress zero blocks during block migration
- "events": generate events for each migration state change
- "bypass-shared-memory": bypass shared memory region

Arguments:

Expand Down Expand Up @@ -3434,6 +3435,7 @@ Query current migration capabilities
- "rdma-pin-all" : RDMA Pin Page state (json-bool)
- "auto-converge" : Auto Converge state (json-bool)
- "zero-blocks" : Zero Blocks state (json-bool)
- "bypass-shared-memory": bypass shared memory state (json-bool)

Arguments:

Expand Down

0 comments on commit 162b05b

Please sign in to comment.