Skip to content

Commit 769dd6d

Browse files
committed
plumb migration pages through
1 parent 0dfb1f4 commit 769dd6d

File tree

4 files changed

+70
-18
lines changed

4 files changed

+70
-18
lines changed

ocaml/xapi-idl/memory/memory.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ type memory_config = {
185185
; shadow_mib: int64
186186
; required_host_free_mib: int64
187187
; overhead_mib: int64
188+
; build_claim_pages: int64
188189
}
189190

190191
module Memory_model (D : MEMORY_MODEL_DATA) = struct
@@ -226,14 +227,16 @@ module Memory_model (D : MEMORY_MODEL_DATA) = struct
226227
let shadow_multiplier_default = 1.0
227228

228229
let full_config static_max_mib video_mib target_mib vcpus shadow_multiplier =
230+
let build_start_mib = build_start_mib static_max_mib target_mib video_mib in
229231
{
230232
build_max_mib= build_max_mib static_max_mib video_mib
231-
; build_start_mib= build_start_mib static_max_mib target_mib video_mib
233+
; build_start_mib
232234
; xen_max_mib= xen_max_mib static_max_mib
233235
; shadow_mib= shadow_mib static_max_mib vcpus shadow_multiplier
234236
; required_host_free_mib=
235237
footprint_mib target_mib static_max_mib vcpus shadow_multiplier
236238
; overhead_mib= overhead_mib static_max_mib vcpus shadow_multiplier
239+
; build_claim_pages= pages_of_mib build_start_mib
237240
}
238241
end
239242

ocaml/xenopsd/xc/domain.ml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ type builder_spec_info =
150150
type build_info = {
151151
memory_max: int64 (** memory max in kilobytes *)
152152
; memory_target: int64 (** memory target in kilobytes *)
153+
; memory_total_source: int64 option
154+
(** amount of memory to claim (during migration) *)
153155
; kernel: string (** in hvm case, point to hvmloader *)
154156
; vcpus: int (** vcpus max *)
155157
; priv: builder_spec_info
@@ -1003,7 +1005,7 @@ let numa_placement domid ~vcpus ~cores ~memory affinity =
10031005
__FUNCTION__ domid ;
10041006
None
10051007
in
1006-
let nr_pages = (Int64.div memory 4096L |> Int64.to_int) (*- 32*) in
1008+
let nr_pages = Int64.div memory 4096L |> Int64.to_int (*- 32*) in
10071009
try
10081010
D.debug "NUMAClaim domid %d: local claim on node %d: %d pages" domid
10091011
node nr_pages ;
@@ -1029,11 +1031,13 @@ let numa_placement domid ~vcpus ~cores ~memory affinity =
10291031
let build_pre ~xc ~xs ~vcpus ~memory ~hard_affinity domid =
10301032
let open Memory in
10311033
let uuid = get_uuid ~xc domid in
1032-
debug "VM = %s, build_max_mib = %Ld, build_start_mib = %Ld, xen_max_mib =
1033-
%Ld, shadow_mib = %Ld, required_host_free_mib = %Ld, overhead_mib = %Ld"
1034-
(Uuidx.to_string uuid)
1035-
memory.build_max_mib memory.build_start_mib memory.xen_max_mib
1036-
memory.shadow_mib memory.required_host_free_mib memory.overhead_mib;
1034+
debug
1035+
"VM = %s, build_max_mib = %Ld, build_start_mib = %Ld, xen_max_mib =\n\
1036+
\ %Ld, shadow_mib = %Ld, required_host_free_mib = %Ld, overhead_mib = \
1037+
%Ld"
1038+
(Uuidx.to_string uuid) memory.build_max_mib memory.build_start_mib
1039+
memory.xen_max_mib memory.shadow_mib memory.required_host_free_mib
1040+
memory.overhead_mib ;
10371041
debug "VM = %s; domid = %d; waiting for %Ld MiB of free host memory"
10381042
(Uuidx.to_string uuid) domid memory.required_host_free_mib ;
10391043
(* CA-39743: Wait, if necessary, for the Xen scrubber to catch up. *)
@@ -1121,9 +1125,14 @@ let build_pre ~xc ~xs ~vcpus ~memory ~hard_affinity domid =
11211125
and cores =
11221126
Xenops_server.cores_of_numa_affinity_policy pin ~vcpus
11231127
in
1124-
let memory =
1125-
Int64.(mul memory.build_start_mib (shift_left 1L 20))
1128+
1129+
let build_claim_bytes =
1130+
Memory.bytes_of_pages memory.build_claim_pages
11261131
in
1132+
D.debug "VM = %s; domid = %d; will claim %Ld bytes = %Ld pages"
1133+
(Uuidx.to_string uuid) domid build_claim_bytes
1134+
memory.build_claim_pages ;
1135+
let memory = build_claim_bytes in
11271136
match numa_placement domid ~vcpus ~cores ~memory affinity with
11281137
| None ->
11291138
(* Always perform a global claim when NUMA placement is
@@ -1138,7 +1147,8 @@ let build_pre ~xc ~xs ~vcpus ~memory ~hard_affinity domid =
11381147
memory later anyway
11391148
*)
11401149
let nr_pages =
1141-
(Int64.div memory 4096L |> Int64.to_int)(* - 32*)
1150+
Int64.div memory 4096L |> Int64.to_int
1151+
(* - 32*)
11421152
in
11431153
let xcext = Xenctrlext.get_handle () in
11441154
D.debug "NUMAClaim domid %d: global claim: %d pages" domid
@@ -1828,6 +1838,16 @@ let restore (task : Xenops_task.task_handle) ~xc ~xs ~dm ~timeoffset ~extras
18281838
maybe_ca_140252_workaround ~xc ~vcpus domid ;
18291839
(memory, vm_stuff, `pvh)
18301840
in
1841+
let memory =
1842+
match info.memory_total_source with
1843+
| None ->
1844+
memory
1845+
| Some bytes ->
1846+
let build_claim_pages = Memory.pages_of_bytes_used bytes in
1847+
debug "Domid %d: memory_total_source = %Ld bytes = %Ld pages" domid
1848+
bytes build_claim_pages ;
1849+
Memory.{memory with build_claim_pages}
1850+
in
18311851
let store_port, console_port, numa_placements =
18321852
build_pre ~xc ~xs ~memory ~vcpus ~hard_affinity:info.hard_affinity domid
18331853
in

ocaml/xenopsd/xc/domain.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ val builder_spec_info : builder_spec_info Rpc.Types.def
130130
type build_info = {
131131
memory_max: int64 (** memory max in kilobytes *)
132132
; memory_target: int64 (** memory target in kilobytes *)
133+
; memory_total_source: int64 option
134+
(** memory used on source during migration/resume in kilobytes *)
133135
; kernel: string (** image to load. In HVM case, point to hvmloader *)
134136
; vcpus: int (** vcpus max *)
135137
; priv: builder_spec_info

ocaml/xenopsd/xc/xenops_server_xen.ml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,7 @@ module VM = struct
16241624
{
16251625
Domain.memory_max= vm.memory_static_max /// 1024L
16261626
; memory_target= vm.memory_dynamic_min /// 1024L
1627+
; memory_total_source= None
16271628
; kernel= ""
16281629
; vcpus= vm.vcpu_max
16291630
; priv= builder_spec_info
@@ -1803,34 +1804,40 @@ module VM = struct
18031804
needed. If we are live migrating then we will only know an
18041805
upper bound. If we are starting from scratch then we have a
18051806
free choice. *)
1806-
let min_bytes, max_bytes =
1807+
let min_bytes, max_bytes, memory_total_source_bytes =
18071808
match memory_upper_bound with
18081809
| Some x ->
18091810
debug "VM = %s; using memory_upper_bound = %Ld" vm.Vm.id x ;
1810-
(x, x)
1811+
(x, x, Some x)
18111812
| None ->
18121813
if resuming then (
18131814
debug "VM = %s; using stored suspend_memory_bytes = %Ld"
18141815
vm.Vm.id persistent.VmExtra.suspend_memory_bytes ;
18151816
( persistent.VmExtra.suspend_memory_bytes
18161817
, persistent.VmExtra.suspend_memory_bytes
1818+
, Some persistent.VmExtra.suspend_memory_bytes
18171819
)
18181820
) else (
18191821
debug
18201822
"VM = %s; using memory_dynamic_min = %Ld and \
18211823
memory_dynamic_max = %Ld"
18221824
vm.Vm.id vm.memory_dynamic_min vm.memory_dynamic_max ;
1823-
(vm.memory_dynamic_min, vm.memory_dynamic_max)
1825+
(vm.memory_dynamic_min, vm.memory_dynamic_max, None)
18241826
)
18251827
in
18261828
let min_kib = kib_of_bytes_used (min_bytes +++ overhead_bytes)
1829+
and memory_total_source_kib =
1830+
Option.map kib_of_bytes_used memory_total_source_bytes
18271831
and max_kib = kib_of_bytes_used (max_bytes +++ overhead_bytes) in
18281832
(* XXX: we would like to be able to cancel an in-progress
18291833
with_reservation *)
18301834
let dbg = Xenops_task.get_dbg task in
18311835
Mem.with_reservation dbg min_kib max_kib
18321836
(fun target_plus_overhead_kib reservation_id ->
1833-
debug "VM = %s, memory [%Ld KiB, %Ld KiB], target_plus_overhead=%Ld KiB" vm.Vm.id min_kib max_kib target_plus_overhead_kib;
1837+
debug
1838+
"VM = %s, memory [%Ld KiB, %Ld KiB], \
1839+
target_plus_overhead=%Ld KiB"
1840+
vm.Vm.id min_kib max_kib target_plus_overhead_kib ;
18341841
let domain_config, persistent =
18351842
match persistent.VmExtra.domain_config with
18361843
| Some dc ->
@@ -1871,9 +1878,26 @@ module VM = struct
18711878
let target_bytes =
18721879
target_plus_overhead_bytes --- overhead_bytes
18731880
in
1874-
debug "VM = %s, memory target_bytes = %Ld, dynamic max = %Ld" vm.Vm.id target_bytes vm.memory_dynamic_max;
1881+
debug
1882+
"VM = %s, memory target_bytes = %Ld, dynamic max = %Ld"
1883+
vm.Vm.id target_bytes vm.memory_dynamic_max ;
18751884
min vm.memory_dynamic_max target_bytes
18761885
in
1886+
let persistent =
1887+
match persistent with
1888+
| {VmExtra.build_info= Some x; _} as t ->
1889+
{
1890+
t with
1891+
build_info=
1892+
Some
1893+
{
1894+
x with
1895+
memory_total_source= memory_total_source_kib
1896+
}
1897+
}
1898+
| _ ->
1899+
persistent
1900+
in
18771901
set_initial_target ~xs domid (Int64.div initial_target 1024L) ;
18781902
(* Log uses of obsolete option *)
18791903
if vm.suppress_spurious_page_faults then
@@ -2347,6 +2371,7 @@ module VM = struct
23472371
{
23482372
Domain.memory_max= static_max_kib
23492373
; memory_target= initial_target
2374+
; memory_total_source= None
23502375
; kernel
23512376
; vcpus= vm.vcpu_max
23522377
; priv
@@ -2969,7 +2994,7 @@ module VM = struct
29692994
| _ ->
29702995
""
29712996
in
2972-
debug "VM = %s, initial_target = %Ld" vm.Vm.id initial_target;
2997+
debug "VM = %s, initial_target = %Ld" vm.Vm.id initial_target ;
29732998
({x with Domain.memory_target= initial_target}, timeoffset)
29742999
in
29753000
let vtpm = vtpm_of ~vm in
@@ -3110,7 +3135,8 @@ module VM = struct
31103135
let pages = Int64.of_nativeint di.Xenctrl.total_memory_pages in
31113136
let kib = Xenctrl.pages_to_kib pages in
31123137
let bytes = Memory.bytes_of_kib kib in
3113-
D.debug "VM %s memory actual: %Ld pages = %Ld KiB = %Ld bytes" (Uuidm.to_string uuid) pages kib bytes;
3138+
D.debug "VM %s memory actual: %Ld pages = %Ld KiB = %Ld bytes"
3139+
(Uuidm.to_string uuid) pages kib bytes ;
31143140
bytes
31153141
in
31163142
let memory_limit =
@@ -3135,7 +3161,8 @@ module VM = struct
31353161
(* CA-31764: may be larger than static_max if maxmem has been
31363162
increased to initial-reservation. *)
31373163
let result = max memory_actual max_memory_bytes in
3138-
D.debug "VM %s memory limit = %Ld bytes" (Uuidm.to_string uuid) result;
3164+
D.debug "VM %s memory limit = %Ld bytes" (Uuidm.to_string uuid)
3165+
result ;
31393166
result
31403167
in
31413168
let rtc =

0 commit comments

Comments
 (0)