Skip to content

Commit 25e4a88

Browse files
committed
xenopsd: Don't balloon down memory on same-host migration
When the VM (and its memory) isn't actually going to be moved anywhere (like in VDI migration to another SR), there's no point in ballooning down, it's actually likely to make VDI migration take longer if swap is engaged. Signed-off-by: Andrii Sultanov <andriy.sultanov@vates.tech>
1 parent 8b5bdf7 commit 25e4a88

3 files changed

Lines changed: 34 additions & 20 deletions

File tree

ocaml/xapi-idl/xen/xenops_interface.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ module XenopsAPI (R : RPC) = struct
718718
~description:["when true, verify remote server certificate"]
719719
Types.bool
720720
in
721+
let localhost_migration =
722+
Param.mk ~name:"localhost_migration"
723+
~description:["when true, localhost migration is being performed"]
724+
Types.bool
725+
in
721726
declare "VM.migrate" []
722727
(debug_info_p
723728
@-> vm_id_p
@@ -727,6 +732,7 @@ module XenopsAPI (R : RPC) = struct
727732
@-> xenops_url
728733
@-> compress
729734
@-> verify_dest
735+
@-> localhost_migration
730736
@-> returning task_id_p err
731737
)
732738

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ let assert_licensed_storage_motion ~__context =
244244

245245
let rec migrate_with_retries ~__context ~queue_name ~max ~try_no ~dbg:_ ~vm_uuid
246246
~xenops_vdi_map ~xenops_vif_map ~xenops_vgpu_map ~xenops_url ~compress
247-
~verify_cert =
247+
~verify_cert ~localhost_migration =
248248
let open Xapi_xenops_queue in
249249
let module Client = (val make_client queue_name : XENOPS) in
250250
let dbg = Context.string_of_task_and_tracing __context in
@@ -254,7 +254,7 @@ let rec migrate_with_retries ~__context ~queue_name ~max ~try_no ~dbg:_ ~vm_uuid
254254
progress := "Client.VM.migrate" ;
255255
let t1 =
256256
Client.VM.migrate dbg vm_uuid xenops_vdi_map xenops_vif_map
257-
xenops_vgpu_map xenops_url compress verify_dest
257+
xenops_vgpu_map xenops_url compress verify_dest localhost_migration
258258
in
259259
progress := "sync_with_task" ;
260260
ignore (Xapi_xenops.sync_with_task __context queue_name t1)
@@ -281,7 +281,7 @@ let rec migrate_with_retries ~__context ~queue_name ~max ~try_no ~dbg:_ ~vm_uuid
281281
(Printexc.to_string e) !progress try_no max ;
282282
migrate_with_retries ~__context ~queue_name ~max ~try_no:(try_no + 1)
283283
~dbg ~vm_uuid ~xenops_vdi_map ~xenops_vif_map ~xenops_vgpu_map
284-
~xenops_url ~compress ~verify_cert
284+
~xenops_url ~compress ~verify_cert ~localhost_migration
285285
(* Something else went wrong *)
286286
| e ->
287287
debug
@@ -374,7 +374,8 @@ let pool_migrate ~__context ~vm ~host ~options =
374374
Pool_features.assert_enabled ~__context ~f:Features.Xen_motion ;
375375
let dbg = Context.string_of_task __context in
376376
let localhost = Helpers.get_localhost ~__context in
377-
if host = localhost then
377+
let localhost_migration = host = localhost in
378+
if localhost_migration then
378379
info "This is a localhost migration" ;
379380
let open Xapi_xenops_queue in
380381
let queue_name = queue_of_vm ~__context ~self:vm in
@@ -431,7 +432,7 @@ let pool_migrate ~__context ~vm ~host ~options =
431432
let verify_cert = Stunnel_client.pool () in
432433
migrate_with_retry ~__context ~queue_name ~dbg ~vm_uuid
433434
~xenops_vdi_map:[] ~xenops_vif_map:[] ~xenops_vgpu_map
434-
~xenops_url ~compress ~verify_cert ;
435+
~xenops_url ~compress ~verify_cert ~localhost_migration ;
435436
(* Delete all record of this VM locally (including caches) *)
436437
Xapi_xenops.Xenopsd_metadata.delete ~__context vm_uuid
437438
)
@@ -1586,7 +1587,8 @@ let migrate_send' ~__context ~vm ~dest ~live:_ ~vdi_map ~vif_map ~vgpu_map
15861587
let dbg = Context.string_of_task __context in
15871588
migrate_with_retry ~__context ~queue_name ~dbg ~vm_uuid
15881589
~xenops_vdi_map ~xenops_vif_map ~xenops_vgpu_map
1589-
~xenops_url:remote.xenops_url ~compress ~verify_cert ;
1590+
~xenops_url:remote.xenops_url ~compress ~verify_cert
1591+
~localhost_migration:is_same_host ;
15901592
Xapi_xenops.Xenopsd_metadata.delete ~__context vm_uuid
15911593
)
15921594
with

ocaml/xenopsd/lib/xenops_server.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ type vm_migrate_op = {
297297
; vmm_tmp_dest_id: Vm.id
298298
; vmm_compress: bool
299299
; vmm_verify_dest: bool
300+
; vmm_localhost_migration: bool
300301
}
301302
[@@deriving rpcty]
302303

@@ -2628,19 +2629,23 @@ and perform_exn ?result (op : operation) (t : Xenops_task.task_handle) : unit =
26282629
~path:(Uri.path_unencoded url ^ snippet ^ id_str)
26292630
~query:(Uri.query url) ()
26302631
in
2631-
(* CA-78365: set the memory dynamic range to a single value to stop
2632-
ballooning. *)
2633-
let atomic =
2634-
VM_set_memory_dynamic_range
2635-
(id, vm.Vm.memory_dynamic_min, vm.Vm.memory_dynamic_min)
2636-
in
2637-
let (_ : unit) =
2638-
perform_atomic ~progress_callback:(fun _ -> ()) atomic t
2639-
in
2640-
(* Waiting here is not essential but adds a degree of safety and
2641-
reducess unnecessary memory copying. *)
2642-
( try B.VM.wait_ballooning t vm
2643-
with Xenopsd_error Ballooning_timeout_before_migration -> ()
2632+
(* CA-78365: set the memory dynamic range to a single value to stop ballooning.
2633+
2634+
There's no need to balloon down when doing localhost migration - we're
2635+
not copying any memory in the first place. This would likely increase VDI
2636+
migration time as swap would be engaged *)
2637+
( if not vmm.vmm_localhost_migration then
2638+
let atomic =
2639+
VM_set_memory_dynamic_range
2640+
(id, vm.Vm.memory_dynamic_min, vm.Vm.memory_dynamic_min)
2641+
in
2642+
let (_ : unit) =
2643+
perform_atomic ~progress_callback:(fun _ -> ()) atomic t
2644+
in
2645+
(* Waiting here is not essential but adds a degree of safety and
2646+
reducess unnecessary memory copying. *)
2647+
try B.VM.wait_ballooning t vm
2648+
with Xenopsd_error Ballooning_timeout_before_migration -> ()
26442649
) ;
26452650
(* Find out the VM's current memory_limit: this will be used to allocate
26462651
memory on the receiver *)
@@ -3597,7 +3602,7 @@ module VM = struct
35973602
let s3resume _ dbg id = queue_operation dbg id (Atomic (VM_s3resume id))
35983603

35993604
let migrate _context dbg id vmm_vdi_map vmm_vif_map vmm_vgpu_pci_map vmm_url
3600-
(compress : bool) (verify_dest : bool) =
3605+
(compress : bool) (localhost_migration : bool) (verify_dest : bool) =
36013606
let tmp_uuid_of uuid ~kind =
36023607
Printf.sprintf "%s00000000000%c" (String.sub uuid 0 24)
36033608
(match kind with `dest -> '1' | `src -> '0')
@@ -3614,6 +3619,7 @@ module VM = struct
36143619
; vmm_tmp_dest_id= tmp_uuid_of id ~kind:`dest
36153620
; vmm_compress= compress
36163621
; vmm_verify_dest= verify_dest
3622+
; vmm_localhost_migration= localhost_migration
36173623
}
36183624
)
36193625

0 commit comments

Comments
 (0)