Skip to content

Commit 9324f70

Browse files
authored
Merge pull request xapi-project#3136 from Frezzle/SCTX-2565
CA-258652/SCTX-2565: Get initial host memory from squeezed
2 parents 951ce75 + 821bde0 commit 9324f70

File tree

4 files changed

+7
-56
lines changed

4 files changed

+7
-56
lines changed

ocaml/xapi/dbsync_slave.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,16 @@ let record_host_memory_properties ~__context =
140140

141141
let metrics = Db.Host.get_metrics ~__context ~self in
142142
Db.Host_metrics.set_memory_total ~__context ~self:metrics ~value:total_memory_bytes;
143-
let boot_memory_file = Xapi_globs.initial_host_free_memory_file in
144-
let boot_memory_string =
143+
let boot_memory_bytes =
145144
try
146-
Some (Unixext.string_of_file boot_memory_file)
145+
let dbg = Context.string_of_task __context in
146+
Some (Memory_client.Client.get_host_initial_free_memory dbg)
147147
with e ->
148-
warn "Could not read host free memory file. This may prevent \
149-
VMs from being started on this host. (%s)" (Printexc.to_string e);
148+
warn "Failed to get host free memory from ballooning service. This may \
149+
prevent VMs from being started on this host. (%s)" (Printexc.to_string e);
150150
None in
151151
maybe
152-
(fun boot_memory_string ->
153-
let boot_memory_bytes = Int64.of_string boot_memory_string in
152+
(fun boot_memory_bytes ->
154153
(* Host memory overhead comes from multiple sources: *)
155154
(* 1. obvious overhead: (e.g. Xen, crash kernel). *)
156155
(* appears as used memory. *)
@@ -174,7 +173,7 @@ let record_host_memory_properties ~__context =
174173
Db.Host.set_memory_overhead ~__context ~self ~value:
175174
(obvious_overhead_memory_bytes ++ nonobvious_overhead_memory_bytes);
176175
)
177-
boot_memory_string
176+
boot_memory_bytes
178177

179178
(* -- used this for testing uniqueness constraints executed on slave do not kill connection.
180179
Committing commented out vsn of this because it might be useful again..

ocaml/xapi/xapi.ml

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -482,50 +482,6 @@ let resynchronise_ha_state () =
482482
(* Critical that we don't continue as a master and use shared resources *)
483483
error "Caught exception resynchronising state of HA system: %s" (ExnHelper.string_of_exn e)
484484

485-
(* Calculates the amount of free memory on the host at boot time. *)
486-
(* Returns a result that is equivalent to (T - X), where: *)
487-
(* T = total memory in host. *)
488-
(* X = host virtualization overhead: *)
489-
(* memory used by Xen code, heap and crash kernel. *)
490-
(* Actually returns the current value of (F + S + Z), where: *)
491-
(* F = host free memory. *)
492-
(* S = host scrub memory. *)
493-
(* Z = host memory used by domain 0. *)
494-
(* This relies on the equivalence (T = X + F + S + Z). *)
495-
(* Warning! This function assumes that: *)
496-
(* 1. Domain 0 is currently in an unballooned state. *)
497-
(* 2. No other domains have been started. *)
498-
let calculate_boot_time_host_free_memory () =
499-
let ( + ) = Nativeint.add in
500-
let open Xenctrl in
501-
let host_info = with_intf (fun xc -> physinfo xc) in
502-
let host_free_pages = host_info.free_pages in
503-
let host_scrub_pages = host_info.scrub_pages in
504-
match Create_misc.read_dom0_memory_usage () with
505-
| None -> failwith "can't query balloon driver"
506-
| Some domain0_bytes ->
507-
let domain0_total_pages = XenopsMemory.pages_of_bytes_used domain0_bytes in
508-
let boot_time_host_free_pages =
509-
host_free_pages + host_scrub_pages + (Int64.to_nativeint domain0_total_pages) in
510-
let boot_time_host_free_kib =
511-
pages_to_kib (Int64.of_nativeint boot_time_host_free_pages) in
512-
Int64.mul 1024L boot_time_host_free_kib
513-
514-
(* Read the free memory on the host and record this in the db. This is used *)
515-
(* as the baseline for memory calculations in the message forwarding layer. *)
516-
let record_boot_time_host_free_memory () =
517-
if not (Unixext.file_exists Xapi_globs.initial_host_free_memory_file) then begin
518-
try
519-
let free_memory = calculate_boot_time_host_free_memory () in
520-
Unixext.mkdir_rec (Filename.dirname Xapi_globs.initial_host_free_memory_file) 0o700;
521-
Unixext.write_string_to_file
522-
Xapi_globs.initial_host_free_memory_file
523-
(Int64.to_string free_memory)
524-
with e ->
525-
error "Could not record host free memory. This may prevent VMs from being started on this host. (%s)"
526-
(Printexc.to_string e)
527-
end
528-
529485
(** Reset the networking-related metadata for this host if the command [xe-reset-networking]
530486
* was executed before the restart. *)
531487
let check_network_reset () =

ocaml/xapi/xapi_globs.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ let http_realm = "xapi"
8686
let log_config_file = ref (Filename.concat "/etc/xensource" "log.conf")
8787
let remote_db_conf_fragment_path = ref (Filename.concat "/etc/xensource" "remote.db.conf")
8888
let cpu_info_file = ref (Filename.concat "/etc/xensource" "boot_time_cpus")
89-
let initial_host_free_memory_file = "/var/run/nonpersistent/xapi/boot_time_memory"
9089
let requires_reboot_file = "/var/run/nonpersistent/xapi/host-requires-reboot"
9190
let using_rrds = ref false
9291

ocaml/xapi/xapi_main.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,4 @@ let _ =
3636
Stdext.Unixext.mkdir_rec (Filename.concat "/var/lib/xcp" "debug") 0o700;
3737
Unix.chdir (Filename.concat "/var/lib/xcp" "debug");
3838

39-
(* WARNING! Never move this function call into the list of startup tasks. *)
40-
record_boot_time_host_free_memory ();
41-
4239
watchdog server_init

0 commit comments

Comments
 (0)