Make xbzrle_cache_size a migration parameter
v3 cover Make xbzrle_cache_size a migration parameter
Hi
On v3:
- rebase on top of last migration pull requset
- improve comments (dave suggestion)
- always return 0 in case of error
- checked with ovirt/openstack/libvirt people that making value a power of two is not a problem.
- should I drop the last patch, or sent it?
Please revieww.
[v2]
- rebase
- fix comments about power of 2 instead of multiple of two
- minor typo on error message
- use Error * when setting values
After asking people of libvirt/ovirt/openstack, it appears that there is no problem about restricting cache_size to real values. We give back one error and they had to handle errors already.
Please review, Juan.
[v1]
I started looking at xbzrle_cache_size and saw that it was not a parameter. How difficult could it be? HaHa
- x-multifd-page-count and x-multifd-channels were not o migrate_test_apply
- page_cache.c has parameters that were not used (max_item_age)
- page cache types were random. Move almost all to int/size_t as appropiate
- error handling was split in three functions:
xbzrle_cache_resize
cache_init
qmp_set_cache_size
Make some sense of it and use Error*
- We pass one value to qmp_migrate_cache_size it asigned pow2log() of that value, and cache_init() used a power of two. Make sure that the value passed is right.
- Now I am able to make xbzrle_cache_size a parameter!!!!
- Now that I have arrived here, I tried to make the json types for migartion parameters the real ones instead of everything is an int64. I will be happy if libvirt people checked this.
Please review, Juan.
*** BLURB HERE ***
Juan Quintela (5):
migration: Make sure that we pass the right cache size
migration: Don't play games with the requested cache size
migration: No need to return the size of the cache
migration: Make xbzrle_cache_size a migration parameter
migration: [RFC] Use proper types in json
hmp.c | 34 ++++++++++++------ migration/migration.c | 94 ++++++++++++++++++++++++++++---------------------- migration/migration.h | 1 - migration/page_cache.c | 12 ++++--- migration/ram.c | 20 ++++------- migration/ram.h | 2 +- qapi/migration.json | 44 ++++++++++++++++------- 7 files changed, 122 insertions(+), 85 deletions(-)
Signature · 1 line
2.13.6
PATCH v3 1/5 migration: Make sure that we pass the right cache size
Instead of passing silently round down the number of pages, make it an error that the cache size is not a power of 2.
--- migration/page_cache.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
migration/page_cache.c +7 -5
@@ -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;
Signature · 1 line
2.13.6
PATCH v3 2/5 migration: Don't play games with the requested cache size
In reply to Juan QuintelaNow that we check that the value passed is a power of 2, we don't need to play games when comparing what is the size that is going to take the cache.
--- migration/ram.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
migration/ram.c +6 -5
@@ -136,12 +136,14 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp)return -1 ; } +if (new_size ==migrate_xbzrle_cache_size ()) { +/* nothing to do */ +return new_size; + } +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 ;
@@ -152,8 +154,7 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp)XBZRLE .cache = new_cache; } -out_new_size: - ret =pow2floor (new_size); + ret = new_size; out:XBZRLE_cache_unlock ();return ret;
Signature · 1 line
2.13.6
PATCH v3 3/5 migration: No need to return the size of the cache
In reply to Juan QuintelaAfter the previous commits, we make sure that the value passed is right, or we just drop an error. So now we return if there is one error or we have setup correctly the value passed.
--
Improve error messasge
Return 0 always for success
--- migration/migration.c | 6 ++---- migration/ram.c | 10 ++++------ migration/ram.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-)
migration/migration.c +2 -4
@@ -1406,14 +1406,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 ) { +if (xbzrle_cache_resize (value, errp) <0 ) {return ; } - s->xbzrle_cache_size = new_size; + s->xbzrle_cache_size = value; }int64_t qmp_query_migrate_cache_size (Error **errp)
migration/ram.c +4 -6
@@ -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) {
@@ -138,7 +138,7 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp)if (new_size ==migrate_xbzrle_cache_size ()) {/* nothing to do */ -return new_size; +return 0 ; }XBZRLE_cache_lock ();
@@ -153,8 +153,6 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp)cache_fini (XBZRLE .cache);XBZRLE .cache = new_cache; } - - ret = new_size; out:XBZRLE_cache_unlock ();return ret;
migration/ram.h +1 -1
@@ -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 );
Signature · 1 line
2.13.6
PATCH v3 4/5 migration: Make xbzrle_cache_size a migration parameter
In reply to Juan QuintelaRight now it is a variable in MigrationState instead of a MigrationParameter. The change allows to set it as the rest of the Migration parameters, from the command line, with query_migration_paramters, set_migrate_parameters, etc.
--- hmp.c | 14 ++++++++++++++ migration/migration.c | 43 ++++++++++++++++++++++++++++++++----------- migration/migration.h | 1 - migration/ram.c | 7 ------- qapi/migration.json | 26 +++++++++++++++++++++++--- 5 files changed, 69 insertions(+), 22 deletions(-)
hmp.c +14 -0
@@ -342,6 +342,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon,"%s: %" PRId64"\n" ,MigrationParameter_str (MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT ), params->x_multifd_page_count); +monitor_printf (mon,"%s: %" PRId64"\n" , +MigrationParameter_str (MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE ), + params->xbzrle_cache_size); }qapi_free_MigrationParameters (params);
@@ -1578,6 +1581,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)Visitor *v =string_input_visitor_new (valuestr);MigrateSetParameters *p =g_new0 (MigrateSetParameters,1 );uint64_t valuebw =0 ; +uint64_t cache_size;Error *err =NULL ;int val, ret;
@@ -1653,6 +1657,16 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_x_multifd_page_count = true;visit_type_int (v, param, &p->x_multifd_page_count, &err);break ; +case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE : + p->has_xbzrle_cache_size = true; +visit_type_size (v, param, &cache_size, &err); +if (err || cache_size >INT64_MAX + || (size_t )cache_size != cache_size) { +error_setg (&err,"Invalid size %s" , valuestr); +break ; + } + p->xbzrle_cache_size = cache_size; +break ;default :assert (0 ); }
migration/migration.c +32 -11
112 lines not on this page · raw message
migration/migration.h +0 -1
@@ -107,7 +107,6 @@ struct MigrationStateint64_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 */
migration/ram.c +0 -7
@@ -129,13 +129,6 @@ int 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 ;
qapi/migration.json +23 -3
@@ -483,6 +483,11 @@ # @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # +# @xbzrle-cache-size: cache size to be used by XBZRLE migration. It +# needs to be a multiple of the target page size +# and a power of 2 +# (Since 2.11) +# # Since: 2.4 ## { 'enum': 'MigrationParameter',
@@ -490,7 +495,8 @@ 'cpu-throttle-initial', 'cpu-throttle-increment', 'tls-creds', 'tls-hostname', 'max-bandwidth', 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', - 'x-multifd-channels', 'x-multifd-page-count' ] } + 'x-multifd-channels', 'x-multifd-page-count', + 'xbzrle-cache-size' ] } ## # @MigrateSetParameters:
@@ -554,6 +560,10 @@ # @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # +# @xbzrle-cache-size: cache size to be used by XBZRLE migration. It +# needs to be a multiple of the target page size +# and a power of 2 +# (Since 2.11) # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make
@@ -571,7 +581,8 @@ '*x-checkpoint-delay': 'int', '*block-incremental': 'bool', '*x-multifd-channels': 'int', - '*x-multifd-page-count': 'int' } } + '*x-multifd-page-count': 'int', + '*xbzrle-cache-size': 'size' } } ## # @migrate-set-parameters:
@@ -650,6 +661,10 @@ # @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # +# @xbzrle-cache-size: cache size to be used by XBZRLE migration. It +# needs to be a multiple of the target page size +# and a power of 2 +# (Since 2.11) # Since: 2.4 ## { 'struct': 'MigrationParameters',
@@ -665,7 +680,8 @@ '*x-checkpoint-delay': 'int', '*block-incremental': 'bool' , '*x-multifd-channels': 'int', - '*x-multifd-page-count': 'int' } } + '*x-multifd-page-count': 'int', + '*xbzrle-cache-size': 'size' } } ## # @query-migrate-parameters:
@@ -947,6 +963,8 @@ # # Returns: nothing on success # +# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# # Since: 1.2 # # Example:
@@ -965,6 +983,8 @@ # # Returns: XBZRLE cache size in bytes # +# Notes: This command is deprecated in favor of 'query-migrate-parameters' +# # Since: 1.2 # # Example:
Signature · 1 line
2.13.6
PATCH v3 5/5 migration: [RFC] Use proper types in json
In reply to Juan QuintelaWe use int for everything (int64_t), and then we check that value is between 0 and 255. Change it to the valid types.
For qmp, the only real change is that now max_bandwidth allows to use the k/M/G suffixes.
--- hmp.c | 22 +++++++++++----------- migration/migration.c | 49 ++++++++++++++++++++----------------------------- qapi/migration.json | 20 ++++++++++---------- 3 files changed, 41 insertions(+), 50 deletions(-)
hmp.c +11 -11
@@ -293,23 +293,23 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)if (params) {assert (params->has_compress_level); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_COMPRESS_LEVEL ), params->compress_level);assert (params->has_compress_threads); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_COMPRESS_THREADS ), params->compress_threads);assert (params->has_decompress_threads); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_DECOMPRESS_THREADS ), params->decompress_threads);assert (params->has_cpu_throttle_initial); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL ), params->cpu_throttle_initial);assert (params->has_cpu_throttle_increment); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT ), params->cpu_throttle_increment);assert (params->has_tls_creds);
@@ -321,28 +321,28 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)MigrationParameter_str (MIGRATION_PARAMETER_TLS_HOSTNAME ), params->tls_hostname);assert (params->has_max_bandwidth); -monitor_printf (mon,"%s: %" PRId64" bytes/second\n" , +monitor_printf (mon,"%s: %" PRIu64" bytes/second\n" ,MigrationParameter_str (MIGRATION_PARAMETER_MAX_BANDWIDTH ), params->max_bandwidth);assert (params->has_downtime_limit); -monitor_printf (mon,"%s: %" PRId64" milliseconds\n" , +monitor_printf (mon,"%s: %" PRIu64" milliseconds\n" ,MigrationParameter_str (MIGRATION_PARAMETER_DOWNTIME_LIMIT ), params->downtime_limit);assert (params->has_x_checkpoint_delay); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_X_CHECKPOINT_DELAY ), params->x_checkpoint_delay);assert (params->has_block_incremental);monitor_printf (mon,"%s: %s\n" ,MigrationParameter_str (MIGRATION_PARAMETER_BLOCK_INCREMENTAL ), params->block_incremental ?"on" :"off" ); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_X_MULTIFD_CHANNELS ), params->x_multifd_channels); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT ), params->x_multifd_page_count); -monitor_printf (mon,"%s: %" PRId64"\n" , +monitor_printf (mon,"%s: %" PRIu64"\n" ,MigrationParameter_str (MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE ), params->xbzrle_cache_size); }
migration/migration.c +20 -29
113 lines not on this page · raw message
qapi/migration.json +10 -10
@@ -668,19 +668,19 @@ # Since: 2.4 ## { 'struct': 'MigrationParameters', - 'data': { '*compress-level': 'int', - '*compress-threads': 'int', - '*decompress-threads': 'int', - '*cpu-throttle-initial': 'int', - '*cpu-throttle-increment': 'int', + 'data': { '*compress-level': 'uint8', + '*compress-threads': 'uint8', + '*decompress-threads': 'uint8', + '*cpu-throttle-initial': 'uint8', + '*cpu-throttle-increment': 'uint8', '*tls-creds': 'str', '*tls-hostname': 'str', - '*max-bandwidth': 'int', - '*downtime-limit': 'int', - '*x-checkpoint-delay': 'int', + '*max-bandwidth': 'size', + '*downtime-limit': 'uint64', + '*x-checkpoint-delay': 'uint32', '*block-incremental': 'bool' , - '*x-multifd-channels': 'int', - '*x-multifd-page-count': 'int', + '*x-multifd-channels': 'uint8', + '*x-multifd-page-count': 'uint32', '*xbzrle-cache-size': 'size' } } ##
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v3 3/5] migration: No need to return the size of the cache
In reply to Juan QuintelaQuoted 70 lines · * Juan Quintela ([email protected]) wrote:
After the previous commits, we make sure that the value passed is right, or we just drop an error. So now we return if there is one error or we have setup correctly the value passed.
Signed-off-by Juan Quintela <[email protected]>--
Improve error messasge
Return 0 always for success--- migration/migration.c | 6 ++---- migration/ram.c | 10 ++++------ migration/ram.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-)migration/migration.c +2
-4@@ -1406,14 +1406,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 ) { +if (xbzrle_cache_resize (value, errp) <0 ) {return ; } - s->xbzrle_cache_size = new_size; + s->xbzrle_cache_size = value; }int64_t qmp_query_migrate_cache_size (Error **errp)migration/ram.c +4
-4@@ -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) {@@ -138,7 +138,7 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp)if (new_size ==migrate_xbzrle_cache_size ()) {/* nothing to do */ -return new_size; +return 0 ; }XBZRLE_cache_lock ();
migration/ram.c int64_t xbzrle_cache_resize(int64_t new_size, Error **errp) · line 158
Quoted 8 lines
migration/ram.c +0
-2@@ -153,8 +153,6 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error **errp)cache_fini (XBZRLE .cache);XBZRLE .cache = new_cache; } - - ret = new_size; out:XBZRLE_cache_unlock ();return ret;
OK, this shares the same oddity as the original which is
XBZRLE.cache = NULL is not an error.
but, since that is the same as the original;
Quoted 16 lines
migration/ram.h +1
-1@@ -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 );Signature · 1 line
2.13.6
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v3 3/5] migration: No need to return the size of the cache
Quoted 11 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Juan Quintela ([email protected]) wrote:
After the previous commits, we make sure that the value passed is right, or we just drop an error. So now we return if there is one error or we have setup correctly the value passed.
Signed-off-by Juan Quintela <[email protected]>OK, this shares the same oddity as the original which is
XBZRLE.cache = NULL is not an error.but, since that is the same as the original;
Hi
It is a normal case. You can change the cache size in the middle of migration or outside migration.
If we are not in the middle of migration, cache is NULL.
Later, Juan.
Dr. David Alan Gilbert
Reviewed-byRe: [Qemu-devel] [PATCH v3 3/5] migration: No need to return the size of the cache
Quoted 11 lines · * Juan Quintela ([email protected]) wrote:
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Juan Quintela ([email protected]) wrote:
After the previous commits, we make sure that the value passed is right, or we just drop an error. So now we return if there is one error or we have setup correctly the value passed.
Signed-off-by Juan Quintela <[email protected]>OK, this shares the same oddity as the original which is
XBZRLE.cache = NULL is not an error.
Quoted 8 lines
Quoted 1 line
but, since that is the same as the original;
Hi
It is a normal case. You can change the cache size in the middle of migration or outside migration.
If we are not in the middle of migration, cache is NULL.
Ah OK, so yes,
Quoted 1 line
Later, Juan.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK