diff options
Diffstat (limited to 'migration')
| -rw-r--r-- | migration/migration.c | 45 | ||||
| -rw-r--r-- | migration/migration.h | 1 | ||||
| -rw-r--r-- | migration/page_cache.c | 12 | ||||
| -rw-r--r-- | migration/ram.c | 20 | ||||
| -rw-r--r-- | migration/ram.h | 2 |
5 files changed, 46 insertions, 34 deletions
diff --git a/migration/migration.c b/migration/migration.c index 62761d5705..4de3b551fe 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -71,7 +71,7 @@ #define DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT 10 /* Migration XBZRLE default cache size */ -#define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024) +#define DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE (64 * 1024 * 1024) /* The delay time (in ms) between two COLO checkpoints * Note: Please change this default value to 10000 when we support hybrid mode. @@ -515,6 +515,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->x_multifd_channels = s->parameters.x_multifd_channels; params->has_x_multifd_page_count = true; params->x_multifd_page_count = s->parameters.x_multifd_page_count; + params->has_xbzrle_cache_size = true; + params->xbzrle_cache_size = s->parameters.xbzrle_cache_size; return params; } @@ -817,6 +819,16 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp) return false; } + if (params->has_xbzrle_cache_size && + (params->xbzrle_cache_size < qemu_target_page_size() || + !is_power_of_2(params->xbzrle_cache_size))) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "xbzrle_cache_size", + "is invalid, it should be bigger than target page size" + " and a power of two"); + return false; + } + return true; } @@ -878,9 +890,12 @@ static void migrate_params_test_apply(MigrateSetParameters *params, if (params->has_x_multifd_page_count) { dest->x_multifd_page_count = params->x_multifd_page_count; } + if (params->has_xbzrle_cache_size) { + dest->xbzrle_cache_size = params->xbzrle_cache_size; + } } -static void migrate_params_apply(MigrateSetParameters *params) +static void migrate_params_apply(MigrateSetParameters *params, Error **errp) { MigrationState *s = migrate_get_current(); @@ -946,6 +961,10 @@ static void migrate_params_apply(MigrateSetParameters *params) if (params->has_x_multifd_page_count) { s->parameters.x_multifd_page_count = params->x_multifd_page_count; } + if (params->has_xbzrle_cache_size) { + s->parameters.xbzrle_cache_size = params->xbzrle_cache_size; + xbzrle_cache_resize(params->xbzrle_cache_size, errp); + } } void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) @@ -974,7 +993,7 @@ void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) return; } - migrate_params_apply(params); + migrate_params_apply(params, errp); } @@ -1405,15 +1424,12 @@ void qmp_migrate_continue(MigrationStatus state, Error **errp) void qmp_migrate_set_cache_size(int64_t value, Error **errp) { - MigrationState *s = migrate_get_current(); - int64_t new_size; - - new_size = xbzrle_cache_resize(value, errp); - if (new_size < 0) { - return; - } + MigrateSetParameters p = { + .has_xbzrle_cache_size = true, + .xbzrle_cache_size = value, + }; - s->xbzrle_cache_size = new_size; + qmp_migrate_set_parameters(&p, errp); } int64_t qmp_query_migrate_cache_size(Error **errp) @@ -1589,7 +1605,7 @@ int64_t migrate_xbzrle_cache_size(void) s = migrate_get_current(); - return s->xbzrle_cache_size; + return s->parameters.xbzrle_cache_size; } bool migrate_use_block(void) @@ -2407,6 +2423,9 @@ static Property migration_properties[] = { DEFINE_PROP_INT64("x-multifd-page-count", MigrationState, parameters.x_multifd_page_count, DEFAULT_MIGRATE_MULTIFD_PAGE_COUNT), + DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState, + parameters.xbzrle_cache_size, + DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE), /* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), @@ -2450,7 +2469,6 @@ static void migration_instance_init(Object *obj) MigrationParameters *params = &ms->parameters; ms->state = MIGRATION_STATUS_NONE; - ms->xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE; ms->mbps = -1; qemu_sem_init(&ms->pause_sem, 0); qemu_mutex_init(&ms->error_mutex); @@ -2470,6 +2488,7 @@ static void migration_instance_init(Object *obj) params->has_block_incremental = true; params->has_x_multifd_channels = true; params->has_x_multifd_page_count = true; + params->has_xbzrle_cache_size = true; } /* diff --git a/migration/migration.h b/migration/migration.h index 8ccdd7a577..663415fe48 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -107,7 +107,6 @@ struct MigrationState int64_t downtime; int64_t expected_downtime; bool enabled_capabilities[MIGRATION_CAPABILITY__MAX]; - int64_t xbzrle_cache_size; int64_t setup_time; /* Flag set once the migration has been asked to enter postcopy */ diff --git a/migration/page_cache.c b/migration/page_cache.c index 9a9d13d6a2..96268c3aea 100644 --- a/migration/page_cache.c +++ b/migration/page_cache.c @@ -58,6 +58,13 @@ PageCache *cache_init(int64_t new_size, size_t page_size, Error **errp) return NULL; } + /* round down to the nearest power of 2 */ + if (!is_power_of_2(num_pages)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "is not a power of two number of pages"); + return NULL; + } + /* We prefer not to abort if there is no memory */ cache = g_try_malloc(sizeof(*cache)); if (!cache) { @@ -65,11 +72,6 @@ PageCache *cache_init(int64_t new_size, size_t page_size, Error **errp) "Failed to allocate cache"); return NULL; } - /* round down to the nearest power of 2 */ - if (!is_power_of_2(num_pages)) { - num_pages = pow2floor(num_pages); - DPRINTF("rounding down to %" PRId64 "\n", num_pages); - } cache->page_size = page_size; cache->num_items = 0; cache->max_num_items = num_pages; diff --git a/migration/ram.c b/migration/ram.c index 7f6327f708..8620aa400a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -112,15 +112,15 @@ static void XBZRLE_cache_unlock(void) * migration may be using the cache and might finish during this call, * hence changes to the cache are protected by XBZRLE.lock(). * - * Returns the new_size or negative in case of error. + * Returns 0 for success or -1 for error * * @new_size: new cache size * @errp: set *errp if the check failed, with reason */ -int64_t xbzrle_cache_resize(int64_t new_size, Error **errp) +int xbzrle_cache_resize(int64_t new_size, Error **errp) { PageCache *new_cache; - int64_t ret; + int64_t ret = 0; /* Check for truncation */ if (new_size != (size_t)new_size) { @@ -129,19 +129,14 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp) return -1; } - /* Cache should not be larger than guest ram size */ - if (new_size > ram_bytes_total()) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "exceeds guest ram size"); - return -1; + if (new_size == migrate_xbzrle_cache_size()) { + /* nothing to do */ + return 0; } XBZRLE_cache_lock(); if (XBZRLE.cache != NULL) { - if (pow2floor(new_size) == migrate_xbzrle_cache_size()) { - goto out_new_size; - } new_cache = cache_init(new_size, TARGET_PAGE_SIZE, errp); if (!new_cache) { ret = -1; @@ -151,9 +146,6 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp) cache_fini(XBZRLE.cache); XBZRLE.cache = new_cache; } - -out_new_size: - ret = pow2floor(new_size); out: XBZRLE_cache_unlock(); return ret; diff --git a/migration/ram.h b/migration/ram.h index f9f7eef894..64d81e9f1d 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -35,7 +35,7 @@ extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; -int64_t xbzrle_cache_resize(int64_t new_size, Error **errp); +int xbzrle_cache_resize(int64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); |