migration: optimize the downtime
PATCH v2 1/1 migration: optimize the downtime
Qemu_savevm_state_cleanup takes about 300ms in my ram migration tests with a 8U24G vm(20G is really occupied), the main cost comes from KVM_SET_USER_MEMORY_REGION ioctl when mem.memory_size = 0 in kvm_set_user_memory_region. In kmod, the main cost is kvm_zap_obsolete_pages, which traverses the active_mmu_pages list to zap the unsync sptes.
It can be optimized by delaying memory_global_dirty_log_stop to the next vm_start.
Changes v1->v2:
- create a VMChangeStateHandler in memory.c to reduce the coupling [Paolo]
--- memory.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
memory.c +26 -1
@@ -2357,8 +2357,14 @@ void memory_global_dirty_log_sync(void) } } +static VMChangeStateEntry *vmstate_change; +void memory_global_dirty_log_start (void ) { +if (vmstate_change) { +qemu_del_vm_change_state_handler (vmstate_change); + } + global_dirty_log = true;MEMORY_LISTENER_CALL_GLOBAL (log_global_start, Forward);
@@ -2369,7 +2375,7 @@ void memory_global_dirty_log_start(void)memory_region_transaction_commit (); } -void memory_global_dirty_log_stop (void ) +static void memory_global_dirty_log_do_stop (void ) { global_dirty_log = false;
@@ -2381,6 +2387,25 @@ void memory_global_dirty_log_stop(void)MEMORY_LISTENER_CALL_GLOBAL (log_global_stop, Reverse); } +static void memory_vm_change_state_handler (void *opaque,int running, +RunState state) +{ +if (running) { +memory_global_dirty_log_do_stop (); + } +} + +void memory_global_dirty_log_stop (void ) +{ +if (!runstate_is_running ()) { + vmstate_change =qemu_add_vm_change_state_handler ( + memory_vm_change_state_handler,NULL ); +return ; + } + +memory_global_dirty_log_do_stop (); +} +static void listener_add_address_space (MemoryListener *listener,AddressSpace *as) {
Signature · 1 line
1.8.3.1
Quoted 7 lines · Jay Zhou
Qemu_savevm_state_cleanuptakes about 300ms in my ram migration tests with a 8U24G vm(20G is really occupied), the main cost comes fromKVM_SET_USER_MEMORY_REGIONioctl when mem.memory_size = 0 inkvm_set_user_memory_region. In kmod, the main cost iskvm_zap_obsolete_pages, which traverses theactive_mmu_pageslist to zap the unsync sptes.
Quoted 7 lines
It can be optimized by delaying
memory_global_dirty_log_stopto the nextvm_start.Changes
v1->v2:
- create a VMChangeStateHandler inmemory.cto reduce the coupling [Paolo]Signed-off-by Jay Zhou <[email protected]>
memory_vm_change_state_handler should delete the handler.
Apart from that, because there is no protection against nested invocations of memory_global_dirty_log_start/stop, a little more work is needed.
Quoted 9 lines
--- memory.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)memory.c +0
-0
memory.c void memory_global_dirty_log_sync(void) · line 2365
Quoted 9 lines
memory.c +4
-0@@ -2357,8 +2357,14 @@ void memory_global_dirty_log_sync(void) } } +static VMChangeStateEntry *vmstate_change; +void memory_global_dirty_log_start (void ) { +if (vmstate_change) { +qemu_del_vm_change_state_handler (vmstate_change);
This should also NULL vmstate_change, so that you can detect the case where the handler is already installed.
Quoted 15 lines
memory.c +3
-1+ } + global_dirty_log = true;MEMORY_LISTENER_CALL_GLOBAL (log_global_start, Forward);@@ -2369,7 +2375,7 @@ void memory_global_dirty_log_start(void)memory_region_transaction_commit (); } -void memory_global_dirty_log_stop (void ) +static void memory_global_dirty_log_do_stop (void ) { global_dirty_log = false;
memory.c void memory_global_dirty_log_stop(void) · line 2394
Quoted 8 lines
memory.c +5
-0@@ -2381,6 +2387,25 @@ void memory_global_dirty_log_stop(void)MEMORY_LISTENER_CALL_GLOBAL (log_global_stop, Reverse); } +static void memory_vm_change_state_handler (void *opaque,int running, +RunState state) +{ +if (running) { +memory_global_dirty_log_do_stop ();
Because this will delete the handler, it should also NULL vmstate_change.
memory.c void memory_global_dirty_log_stop(void) · line 2402
Quoted 8 lines
memory.c +8
-0+ } +} + +void memory_global_dirty_log_stop (void ) +{ +if (!runstate_is_running ()) { + vmstate_change =qemu_add_vm_change_state_handler ( + memory_vm_change_state_handler,NULL );
And this needs to exit immediately if you have an installed handler.
Thanks,
Paolo
Quoted 10 lines
memory.c +6
-0+return ; + } + +memory_global_dirty_log_do_stop (); +} +static void listener_add_address_space (MemoryListener *listener,AddressSpace *as) {
Hi Paolo,
Quoted 14 lines · Paolo Bonzini
Quoted 13 lines · Jay Zhou
Qemu_savevm_state_cleanuptakes about 300ms in my ram migration tests with a 8U24G vm(20G is really occupied), the main cost comes fromKVM_SET_USER_MEMORY_REGIONioctl when mem.memory_size = 0 inkvm_set_user_memory_region. In kmod, the main cost iskvm_zap_obsolete_pages, which traverses theactive_mmu_pageslist to zap the unsync sptes.It can be optimized by delaying
memory_global_dirty_log_stopto the nextvm_start.Changes
v1->v2:
- create a VMChangeStateHandler inmemory.cto reduce the coupling [Paolo]
Quoted 7 lines
Quoted 1 line
Signed-off-by Jay Zhou <[email protected]>
memory_vm_change_state_handlershould delete the handler.Apart from that, because there is no protection against nested invocations of memory_global_dirty_log_start/stop, a little more work is needed.
Thank for your patience and pointing everything out, I will fix all of them.
Jay
Quoted 77 lines
Quoted 9 lines
--- memory.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)memory.c +0
-0memory.c void memory_global_dirty_log_sync(void) · line 2365
Quoted 9 lines
memory.c +4
-0@@ -2357,8 +2357,14 @@ void memory_global_dirty_log_sync(void) } } +static VMChangeStateEntry *vmstate_change; +void memory_global_dirty_log_start (void ) { +if (vmstate_change) { +qemu_del_vm_change_state_handler (vmstate_change);This should also NULL
vmstate_change, so that you can detect the case where the handler is already installed.Quoted 15 lines
memory.c +3
-1+ } + global_dirty_log = true;MEMORY_LISTENER_CALL_GLOBAL (log_global_start, Forward);@@ -2369,7 +2375,7 @@ void memory_global_dirty_log_start(void)memory_region_transaction_commit (); } -void memory_global_dirty_log_stop (void ) +static void memory_global_dirty_log_do_stop (void ) { global_dirty_log = false;memory.c void memory_global_dirty_log_stop(void) · line 2394
Quoted 8 lines
memory.c +5
-0@@ -2381,6 +2387,25 @@ void memory_global_dirty_log_stop(void)MEMORY_LISTENER_CALL_GLOBAL (log_global_stop, Reverse); } +static void memory_vm_change_state_handler (void *opaque,int running, +RunState state) +{ +if (running) { +memory_global_dirty_log_do_stop ();Because this will delete the handler, it should also NULL
vmstate_change.memory.c void memory_global_dirty_log_stop(void) · line 2402
Quoted 8 lines
memory.c +8
-0+ } +} + +void memory_global_dirty_log_stop (void ) +{ +if (!runstate_is_running ()) { + vmstate_change =qemu_add_vm_change_state_handler ( + memory_vm_change_state_handler,NULL );And this needs to exit immediately if you have an installed handler.
Thanks,
Paolo
memory.c void memory_global_dirty_log_stop(void) · line 2411
Quoted 10 lines
memory.c +6
-0+return ; + } + +memory_global_dirty_log_do_stop (); +} +static void listener_add_address_space (MemoryListener *listener,AddressSpace *as) {.