Skip to content

Commit

Permalink
Merge pull request xapi-project#41 from zli/CA-173605
Browse files Browse the repository at this point in the history
CA-173605
  • Loading branch information
thomassa committed Jan 15, 2016
2 parents 31f11a1 + 5c9c286 commit df7630f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/memory_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions src/squeeze_xen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions src/squeezed_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/"

Expand All @@ -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)

0 comments on commit df7630f

Please sign in to comment.