diff --git a/src/memory_server.ml b/src/memory_server.ml index 8e5bb9755..6cbed1460 100644 --- a/src/memory_server.ml +++ b/src/memory_server.ml @@ -129,10 +129,12 @@ let transfer_reservation_to_domain _ dbg session_id reservation_id domid = Xenctrl.with_intf (fun xc -> try - let kib = Client.immediate (get_client ()) (fun xs -> Client.read xs (reservation_path _service session_id reservation_id)) in + let reservation_id_path = reservation_path _service session_id reservation_id in + let kib = Client.immediate (get_client ()) (fun xs -> Client.read xs reservation_id_path) in (* This code is single-threaded, no need to make this transactional: *) Client.immediate (get_client ()) (fun xs -> Client.write xs (Printf.sprintf "/local/domain/%d/memory/initial-reservation" domid) kib); - Client.immediate (get_client ()) (fun xs -> Client.write xs (Printf.sprintf "/local/domain/%d/memory/reservation-id" domid) reservation_id); + Client.immediate (get_client ()) (fun xs -> Client.write xs (Printf.sprintf "/local/domain/%d/memory/reservation-id" domid) reservation_id); + Client.immediate (get_client ()) (fun xs -> Client.write xs (path [reservation_id_path; "in-transfer"]) (string_of_int domid)); Opt.iter (fun maxmem -> Squeeze_xen.Domain.set_maxmem_noexn xc domid maxmem) (try Some (Int64.of_string kib) with _ -> None); diff --git a/src/squeeze_xen.ml b/src/squeeze_xen.ml index 4e56e38db..935ddb67a 100644 --- a/src/squeeze_xen.ml +++ b/src/squeeze_xen.ml @@ -439,17 +439,6 @@ let make_host ~verbose ~xc = then domain_infolist else List.filter (fun di -> di.Xenctrl.domid > 0) domain_infolist in - (* - For the host free memory we sum the free pages and the pages needing - scrubbing: we don't want to adjust targets simply because the scrubber - is slow. - *) - let physinfo = Xenctrl.physinfo xc in - let free_pages_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.free_pages) - and scrub_pages_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.scrub_pages) - and total_pages_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.total_pages) in - let free_mem_kib = free_pages_kib +* scrub_pages_kib in - let cnx = xc in let domains = List.concat (List.map @@ -559,8 +548,19 @@ let make_host ~verbose ~xc = domain_infolist ) in + (* + For the host free memory we sum the free pages and the pages needing + scrubbing: we don't want to adjust targets simply because the scrubber + is slow. + *) + let physinfo = Xenctrl.physinfo xc in + let free_pages_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.free_pages) + and scrub_pages_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.scrub_pages) + and total_pages_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.total_pages) in + let free_mem_kib = free_pages_kib +* scrub_pages_kib in + (* Sum up the 'reservations' which exist separately from domains *) - let non_domain_reservations = Squeezed_state.total_reservations Squeezed_state._service in + let non_domain_reservations = Squeezed_state.total_reservations Squeezed_state._service domain_infolist in if verbose && non_domain_reservations <> 0L then debug "Total non-domain reservations = %Ld" non_domain_reservations; reserved_kib := Int64.add !reserved_kib non_domain_reservations; diff --git a/src/squeezed_state.ml b/src/squeezed_state.ml index 51232f426..45a153095 100644 --- a/src/squeezed_state.ml +++ b/src/squeezed_state.ml @@ -23,6 +23,7 @@ let _service = "squeezed" let listdir path = try List.filter (fun x -> x <> "") (Client.immediate (get_client ()) (fun xs -> Client.directory xs path)) with Xs_protocol.Enoent _ -> [] let xs_read path = try Client.immediate (get_client ()) (fun xs -> Client.read xs path) with Xs_protocol.Enoent _ as e -> begin debug "xenstsore-read %s returned ENOENT" path; raise e end +let xs_read_option path = try Some (Client.immediate (get_client ()) (fun xs -> Client.read xs path)) with Xs_protocol.Enoent _ -> None let path = String.concat "/" @@ -42,9 +43,14 @@ let del_reservation service session_id reservation_id = Client.immediate (get_client ()) (fun xs -> Client.rm xs (reservation_path service session_id reservation_id)) (** Return the total amount of memory reserved *) -let total_reservations service = - let session_ids = listdir (path [ ""; service; "state" ]) in - let session_total session_id = - let rids = listdir (path [ ""; service; "state"; session_id ]) in - List.fold_left Int64.add 0L (List.map (fun r -> Int64.of_string (xs_read (path [ ""; service; "state"; session_id; r]))) rids) in - List.fold_left Int64.add 0L (List.map session_total session_ids) +let total_reservations service domain_infolist = + let dom_list = List.map (fun di -> di.Xenctrl.domid) domain_infolist in + let session_ids = listdir (path [ ""; service; "state" ]) in + let already_counted sid rid = + match xs_read_option (path [ ""; service; "state"; sid; rid; "in-transfer"]) with + | Some domid when List.mem (int_of_string domid) dom_list -> true + | _ -> false in + let session_total sid = + let rids = listdir (path [ ""; service; "state"; sid ]) in + List.fold_left Int64.add 0L (List.map (fun rid -> if already_counted sid rid then 0L else Int64.of_string (xs_read (path [ ""; service; "state"; sid; rid]))) rids) in + List.fold_left Int64.add 0L (List.map session_total session_ids)