Commit a0a3fd60f66bfdef38da835e7382b0bfbe05bafc

Authored by Glauber Costa
Committed by Anthony Liguori
1 parent 8c14c173

add non-arbitrary migration stop condition

Currently, we're entering migration's stage 3 when
a treshold of 10 pages remain to be transferred in the system.

This has hurt some users. However, any proposed threshold is
arbitrary by nature, and would only shift the annoyance.

The proposal of this patch is to define a max_downtime variable,
which represents the maximum downtime a migration user is willing
to suffer. Then, based on the bandwidth of last iteration, we
calculate how much data we can transfer in such a window of time.

Whenever we reach that value (or lower), we know is safe to enter
stage3.

This has largely improved the situation for me.
On localhost migrations, where one would expect things to go as
quickly as me running away from the duty of writting software for
windows, a kernel compile was enough to get the migration stuck.

It takes 20 ~ 30 iterations now.

Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
migration.c
... ... @@ -107,6 +107,17 @@ void do_migrate_set_speed(Monitor *mon, const char *value)
107 107  
108 108 }
109 109  
  110 +/* amount of nanoseconds we are willing to wait for migration to be down.
  111 + * the choice of nanoseconds is because it is the maximum resolution that
  112 + * get_clock() can achieve. It is an internal measure. All user-visible
  113 + * units must be in seconds */
  114 +static uint64_t max_downtime = 30000000;
  115 +
  116 +uint64_t migrate_max_downtime(void)
  117 +{
  118 + return max_downtime;
  119 +}
  120 +
110 121 void do_info_migrate(Monitor *mon)
111 122 {
112 123 MigrationState *s = current_migration;
... ...
migration.h
... ... @@ -55,6 +55,8 @@ void do_migrate_cancel(Monitor *mon);
55 55  
56 56 void do_migrate_set_speed(Monitor *mon, const char *value);
57 57  
  58 +uint64_t migrate_max_downtime(void);
  59 +
58 60 void do_info_migrate(Monitor *mon);
59 61  
60 62 int exec_start_incoming_migration(const char *host_port);
... ...
... ... @@ -3188,7 +3188,6 @@ static int ram_save_block(QEMUFile *f)
3188 3188 return found;
3189 3189 }
3190 3190  
3191   -static ram_addr_t ram_save_threshold = 10;
3192 3191 static uint64_t bytes_transferred = 0;
3193 3192  
3194 3193 static ram_addr_t ram_save_remaining(void)
... ... @@ -3222,6 +3221,9 @@ uint64_t ram_bytes_total(void)
3222 3221 static int ram_save_live(QEMUFile *f, int stage, void *opaque)
3223 3222 {
3224 3223 ram_addr_t addr;
  3224 + uint64_t bytes_transferred_last;
  3225 + double bwidth = 0;
  3226 + uint64_t expected_time = 0;
3225 3227  
3226 3228 if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
3227 3229 qemu_file_set_error(f);
... ... @@ -3241,6 +3243,9 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
3241 3243 qemu_put_be64(f, last_ram_offset | RAM_SAVE_FLAG_MEM_SIZE);
3242 3244 }
3243 3245  
  3246 + bytes_transferred_last = bytes_transferred;
  3247 + bwidth = get_clock();
  3248 +
3244 3249 while (!qemu_file_rate_limit(f)) {
3245 3250 int ret;
3246 3251  
... ... @@ -3250,6 +3255,14 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
3250 3255 break;
3251 3256 }
3252 3257  
  3258 + bwidth = get_clock() - bwidth;
  3259 + bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
  3260 +
  3261 + /* if we haven't transferred anything this round, force expected_time to a
  3262 + * a very high value, but without crashing */
  3263 + if (bwidth == 0)
  3264 + bwidth = 0.000001;
  3265 +
3253 3266 /* try transferring iterative blocks of memory */
3254 3267  
3255 3268 if (stage == 3) {
... ... @@ -3263,7 +3276,9 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
3263 3276  
3264 3277 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
3265 3278  
3266   - return (stage == 2) && (ram_save_remaining() < ram_save_threshold);
  3279 + expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
  3280 +
  3281 + return (stage == 2) && (expected_time <= migrate_max_downtime());
3267 3282 }
3268 3283  
3269 3284 static int ram_load_dead(QEMUFile *f, void *opaque)
... ...