Skip to content

Commit 1a68634

Browse files
authored
xenopsd/xc: upstream more NUMA changes (#6554)
These commits allow to minimize the differences between the versions that use a xen with the NUMA-enabled claim_pages, and the ones that are not. Now it's a single patch with 4 lines of code: - 2 lines to change the C binding for domain_claim_pages (ocaml/xenopsd/c_stubs/xenctrlext_stubs.c) - 2 lines to remove the raising of exception to try to use the C binding with a single NUMA node (ocaml/xenopsd/xc/xenctrlext.ml)
2 parents 1f346bd + 43a7ab2 commit 1a68634

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

ocaml/xenopsd/xc/domain.ml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ let numa_placement domid ~vcpus ~memory affinity =
886886
Array.map2 NUMAResource.min_memory (Array.of_list nodes) a
887887
in
888888
numa_resources := Some nodea ;
889-
let _ =
889+
let memory_plan =
890890
match Softaffinity.plan ~vm host nodea with
891891
| None ->
892892
D.debug "NUMA-aware placement failed for domid %d" domid ;
@@ -898,10 +898,34 @@ let numa_placement domid ~vcpus ~memory affinity =
898898
done ;
899899
mem_plan
900900
in
901-
(* Neither xenguest nor emu-manager allow allocating pages to a single
902-
NUMA node, don't return any NUMA in any case. Claiming the memory
903-
would be done here, but it conflicts with DMC. *)
904-
None
901+
(* Xen only allows a single node when using memory claims, or none at all. *)
902+
let* numa_node, node =
903+
match memory_plan with
904+
| [Node node] ->
905+
Some (Xenctrlext.NumaNode.from node, node)
906+
| [] | _ :: _ :: _ ->
907+
D.debug
908+
"%s: domain %d can't fit a single NUMA node, falling back to \
909+
default behaviour"
910+
__FUNCTION__ domid ;
911+
None
912+
in
913+
let nr_pages = Int64.div memory 4096L |> Int64.to_int in
914+
try
915+
Xenctrlext.domain_claim_pages xcext domid ~numa_node nr_pages ;
916+
Some (node, memory)
917+
with
918+
| Xenctrlext.Not_available ->
919+
(* Xen does not provide the interface to claim pages from a single NUMA
920+
node, ignore the error and continue. *)
921+
None
922+
| Xenctrlext.Unix_error (errno, _) ->
923+
D.info
924+
"%s: unable to claim enough memory, domain %d won't be hosted in a \
925+
single NUMA node. (error %s)"
926+
__FUNCTION__ domid
927+
Unix.(error_message errno) ;
928+
None
905929
)
906930

907931
let build_pre ~xc ~xs ~vcpus ~memory ~hard_affinity domid =

ocaml/xenopsd/xc/xenctrlext.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,9 @@ module NumaNode = struct
125125
let from = Fun.id
126126
end
127127

128+
exception Not_available
129+
128130
let domain_claim_pages handle domid ?(numa_node = NumaNode.none) nr_pages =
131+
if numa_node <> NumaNode.none then
132+
raise Not_available ;
129133
stub_domain_claim_pages handle domid numa_node nr_pages

ocaml/xenopsd/xc/xenctrlext.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,9 @@ module NumaNode : sig
102102
val from : int -> t
103103
end
104104

105+
exception Not_available
106+
105107
val domain_claim_pages : handle -> domid -> ?numa_node:NumaNode.t -> int -> unit
106-
(** Raises {Unix_error} if there's not enough memory to claim in the system *)
108+
(** Raises {Unix_error} if there's not enough memory to claim in the system.
109+
Raises {Not_available} if a single numa node is requested and xen does not
110+
provide page claiming for single numa nodes. *)

0 commit comments

Comments
 (0)