Skip to content

Commit f98bb9e

Browse files
committed
xenopsd: expose a best-effort mode that set the hard affinity mask (CP-54234)
This allows xapi to "hard-pin" instead of "soft-pin". This is useful to restrict the scheduler to a single numa node, instead of letting it to move the vpus across nodes. This must be used with care because the effect of overprovisioning CPUs in this mode is unknown and will probalby have undesired effects. Signed-off-by: Pau Ruiz Safont <[email protected]>
1 parent 6bb19d8 commit f98bb9e

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

ocaml/xapi-idl/xen/xenops_interface.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,12 @@ module Host = struct
496496
[@@deriving rpcty]
497497

498498
type numa_affinity_policy =
499-
| Any (** VMs may run on any NUMA nodes. This is the default in 8.2CU1 *)
499+
| Any (** VMs may run on any NUMA nodes. *)
500500
| Best_effort
501-
(** best effort placement on the smallest number of NUMA nodes where possible *)
501+
(** Best-effort placement. Assigns the memory of the VM to a single
502+
node, and soft-pins its VCPUs to the node, if possible. Otherwise
503+
behaves like Any. *)
504+
| Best_effort_hard (** Like Best_effort, but hard-pins the VCPUs *)
502505
[@@deriving rpcty]
503506

504507
type numa_affinity_policy_opt = numa_affinity_policy option [@@deriving rpcty]

ocaml/xenopsd/lib/xenops_server.ml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3570,8 +3570,21 @@ let default_numa_affinity_policy = ref Xenops_interface.Host.Best_effort
35703570

35713571
let numa_placement = ref !default_numa_affinity_policy
35723572

3573+
type affinity = Soft | Hard
3574+
35733575
let string_of_numa_affinity_policy =
3574-
Xenops_interface.Host.(function Any -> "any" | Best_effort -> "best-effort")
3576+
let open Xenops_interface.Host in
3577+
function
3578+
| Any ->
3579+
"any"
3580+
| Best_effort ->
3581+
"best-effort"
3582+
| Best_effort_hard ->
3583+
"best-effort-hard"
3584+
3585+
let affinity_of_numa_affinity_policy =
3586+
let open Xenops_interface.Host in
3587+
function Any | Best_effort -> Soft | Best_effort_hard -> Hard
35753588

35763589
module HOST = struct
35773590
let stat _ dbg =

ocaml/xenopsd/xc/domain.ml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,13 @@ let numa_init () =
857857
)
858858
mem
859859

860-
let numa_placement domid ~vcpus ~memory =
860+
let set_affinity = function
861+
| Xenops_server.Hard ->
862+
Xenctrlext.vcpu_setaffinity_hard
863+
| Xenops_server.Soft ->
864+
Xenctrlext.vcpu_setaffinity_soft
865+
866+
let numa_placement domid ~vcpus ~memory affinity =
861867
let open Xenctrlext in
862868
let open Topology in
863869
with_lock numa_mutex (fun () ->
@@ -888,7 +894,7 @@ let numa_placement domid ~vcpus ~memory =
888894
| Some (cpu_affinity, mem_plan) ->
889895
let cpus = CPUSet.to_mask cpu_affinity in
890896
for i = 0 to vcpus - 1 do
891-
Xenctrlext.vcpu_setaffinity_soft xcext domid i cpus
897+
set_affinity affinity xcext domid i cpus
892898
done ;
893899
mem_plan
894900
in
@@ -978,14 +984,18 @@ let build_pre ~xc ~xs ~vcpus ~memory ~hard_affinity domid =
978984
match !Xenops_server.numa_placement with
979985
| Any ->
980986
None
981-
| Best_effort ->
987+
| (Best_effort | Best_effort_hard) as pin ->
982988
log_reraise (Printf.sprintf "NUMA placement") (fun () ->
983989
if hard_affinity <> [] then (
984990
D.debug "VM has hard affinity set, skipping NUMA optimization" ;
985991
None
986992
) else
993+
let affinity =
994+
Xenops_server.affinity_of_numa_affinity_policy pin
995+
in
987996
numa_placement domid ~vcpus
988997
~memory:(Int64.mul memory.xen_max_mib 1048576L)
998+
affinity
989999
|> Option.map fst
9901000
)
9911001
in

0 commit comments

Comments
 (0)