Skip to content

Commit f05fa58

Browse files
authored
CP-310822: upstream patchqueue entries for XS9 (#6845)
This PR contains the same patches for XS9 that were present in the patchqueue. I organised the PR so that each merge corresponds to an entry in the patchqueue: * 0004-rrd3.patch * 0003-CP-53658-adapt-claim_pages-to-version-in-xen-4.21-wi.patch * 0005-xenopsd-xc-do-not-try-keep-track-of-free-memory-when.patch * 0005-rrd4.patch The behaviour is unchanged compared to the patchqueue (the code is the same). Tested with BVT 233166. Verified that the RRD metrics in the patches are preserved as expected, using: ``` # xe vm-list params=all| grep numa numa-optimised ( RO): true numa-nodes ( RO): 1 numa-node-memory (MRO): 0: 2149572608; 1: 0 # rrd2csv AVERAGE:::numa_nodes timestamp, AVERAGE:vm:5d9459d1-7209-ee36-e404-c6b537aa2cd3:numa_nodes 2026-01-19T13:30:15Z, 1 2026-01-19T13:30:20Z, 1 ^C [# rrd2csv AVERAGE:::memory_numa_node timestamp, AVERAGE:vm:5d9459d1-7209-ee36-e404-c6b537aa2cd3:memory_numa_node_1, AVERAGE:vm:5d9459d1-7209-ee36-e404-c6b537aa2cd3:memory_numa_node_0 2026-01-19T13:30:25Z, 0, 2149572608 2026-01-19T13:30:30Z, 0, 2149572608 2026-01-19T13:30:35Z, 0, 2149572608 ^C ```
2 parents 8116cf5 + 4eb2ca1 commit f05fa58

File tree

7 files changed

+97
-14
lines changed

7 files changed

+97
-14
lines changed

ocaml/libs/xenctrl-ext/xenctrlext.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ end
124124
exception Not_available
125125

126126
let domain_claim_pages handle domid ?(numa_node = NumaNode.none) nr_pages =
127-
if numa_node <> NumaNode.none then raise Not_available ;
128127
stub_domain_claim_pages handle domid numa_node nr_pages
129128

130129
let get_nr_nodes handle =

ocaml/libs/xenctrl-ext/xenctrlext.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ val get_nr_nodes : handle -> int
109109
(** Returns the count of NUMA nodes available in the system. *)
110110

111111
module DomainNuma : sig
112+
type domain_numainfo_node_pages = {
113+
tot_pages_per_node: int64 array (* page=4k bytes *)
114+
}
115+
116+
external domain_get_numa_info_node_pages :
117+
handle -> int -> domain_numainfo_node_pages
118+
= "stub_xc_domain_numa_get_node_pages_wrapper"
119+
112120
type t = {optimised: bool; nodes: int; memory: int64 array (* bytes *)}
113121

114122
val state : handle -> domid:int -> t

ocaml/libs/xenctrl-ext/xenctrlext_stubs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,15 @@ CAMLprim value stub_xenctrlext_domain_claim_pages(value xch_val, value domid_val
678678
value numa_node_val, value nr_pages_val)
679679
{
680680
CAMLparam4(xch_val, domid_val, numa_node_val, nr_pages_val);
681+
#ifdef XEN_DOMCTL_NUMA_OP_GET_NODE_PAGES
681682
int retval, the_errno;
682683
xc_interface* xch = xch_of_val(xch_val);
683684
uint32_t domid = Int_val(domid_val);
684-
// unsigned int numa_node = Int_val(numa_node_val);
685+
unsigned int numa_node = Int_val(numa_node_val);
685686
unsigned long nr_pages = Long_val(nr_pages_val);
686687

687688
caml_release_runtime_system();
688-
retval = xc_domain_claim_pages(xch, domid, /*numa_node,*/ nr_pages);
689+
retval = xc_domain_claim_pages_node(xch, domid, numa_node, nr_pages);
689690
the_errno = errno;
690691
caml_acquire_runtime_system();
691692

@@ -694,6 +695,9 @@ CAMLprim value stub_xenctrlext_domain_claim_pages(value xch_val, value domid_val
694695
"Error when trying to claim memory pages");
695696
}
696697
CAMLreturn(Val_unit);
698+
#else
699+
raise_unix_errno_msg(ENOSYS, "xc_domain_claim_pages_node");
700+
#endif
697701
}
698702

699703
#ifdef XEN_DOMCTL_NUMA_OP_GET_NODE_PAGES

ocaml/xcp-rrdd/bin/rrdp-cpu/rrdp_cpu.ml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ let dss_vcpus xc doms =
8080
)
8181
]
8282
in
83+
let nonaffine_vcpus_ds =
84+
match ri.Xenctrl.Runstateinfo.V2.running with
85+
| 0L ->
86+
[]
87+
| _ ->
88+
[
89+
( Rrd.VM uuid
90+
, Ds.ds_make ~name:"numa_node_nonaffine_vcpus"
91+
~units:"(fraction)"
92+
~value:
93+
(Rrd.VT_Float
94+
(Int64.to_float ri.Xenctrl.Runstateinfo.V2.nonaffine
95+
/. 1.0e9
96+
)
97+
)
98+
~description:
99+
"Fraction of vCPU time running outside of vCPU \
100+
soft-affinity"
101+
~ty:Rrd.Derive ~default:false ~min:0.0 ~max:1.0 ()
102+
)
103+
]
104+
in
83105
( Rrd.VM uuid
84106
, Ds.ds_make ~name:"runstate_fullrun" ~units:"(fraction)"
85107
~value:
@@ -172,6 +194,7 @@ let dss_vcpus xc doms =
172194
)
173195
:: dss
174196
@ runnable_vcpus_ds
197+
@ nonaffine_vcpus_ds
175198
with _ -> dss
176199
in
177200
try cpus 0 dss with _ -> dss

ocaml/xcp-rrdd/bin/rrdp-squeezed/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
xapi-log
1414
xapi-rrd
1515
xenctrl
16+
xenctrl_ext
1617
xenstore
1718
xenstore.unix
1819
xenstore_transport

ocaml/xcp-rrdd/bin/rrdp-squeezed/rrdp_squeezed.ml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,62 @@ let free_other uuid free =
252252
~value:(Rrd.VT_Int64 free) ~ty:Rrd.Gauge ~min:0.0 ~default:true ()
253253
)
254254

255+
let dss_numa_info uuid domid =
256+
try
257+
let handle = Xenctrlext.get_handle () in
258+
let host_nr_nodes = Xenctrlext.get_nr_nodes handle in
259+
let vm_nodes =
260+
Xenctrlext.DomainNuma.domain_get_numa_info_node_pages handle domid
261+
in
262+
let dss_memory_numa_nodes_of_vm (dss, nr_nodes_used_by_vm)
263+
(node_id, tot_pages_per_node) =
264+
(*
265+
for each numa node used by the host, show the
266+
corresponding amount of memory used by the vm
267+
*)
268+
let is_node_used_by_vm = tot_pages_per_node > 4096L in
269+
let is_node_used_by_host = node_id < host_nr_nodes in
270+
if is_node_used_by_host then
271+
( ( Rrd.VM uuid
272+
, Ds.ds_make
273+
~name:(Printf.sprintf "memory_numa_node_%d" node_id)
274+
~units:"B"
275+
~description:
276+
(Printf.sprintf "Memory from NUMA node %d used by VM" node_id)
277+
~value:(Rrd.VT_Int64 (Int64.mul tot_pages_per_node 4096L))
278+
~min:0.0 ~ty:Rrd.Gauge ~default:false ()
279+
)
280+
:: dss
281+
(* remember the number of nodes used by vm *)
282+
, nr_nodes_used_by_vm
283+
+
284+
if is_node_used_by_vm then
285+
1
286+
else
287+
0
288+
)
289+
else
290+
(dss, nr_nodes_used_by_vm)
291+
in
292+
let dss_numa_nodes_of_vm (dss, nr_nodes_used_by_vm) =
293+
( Rrd.VM uuid
294+
, Ds.ds_make
295+
~name:(Printf.sprintf "numa_nodes")
296+
~units:"count"
297+
~description:(Printf.sprintf "Number of NUMA nodes used by VM")
298+
~value:(Rrd.VT_Int64 (Int64.of_int nr_nodes_used_by_vm))
299+
~min:0.0 ~ty:Rrd.Gauge ~default:false ()
300+
)
301+
:: List.rev dss
302+
in
303+
vm_nodes.Xenctrlext.DomainNuma.tot_pages_per_node
304+
|> Array.mapi (fun i x -> (i, x))
305+
|> Array.fold_left dss_memory_numa_nodes_of_vm ([], 0)
306+
|> dss_numa_nodes_of_vm
307+
with e ->
308+
D.debug "dss_numa_info: %s" (Printexc.to_string e) ;
309+
[]
310+
255311
let get_list f = Option.to_list (f ())
256312

257313
let generate_vm_sources domains =
@@ -288,14 +344,15 @@ let generate_vm_sources domains =
288344
~value:(Rrd.VT_Int64 memory) ~ty:Rrd.Gauge ~min:0.0 ~default:true ()
289345
)
290346
in
347+
let get_list_numa_info = dss_numa_info uuid domid in
291348
(* CA-34383: Memory updates from paused domains serve no useful purpose.
292349
During a migrate such updates can also cause undesirable
293350
discontinuities in the observed value of memory_actual. Hence, we
294351
ignore changes from paused domains: *)
295352
if dom.Xenctrl.paused then
296353
[]
297354
else
298-
get_list target @ get_list free @ get_list total
355+
get_list target @ get_list free @ get_list total @ get_list_numa_info
299356
in
300357

301358
List.concat_map metrics_of domains

ocaml/xenopsd/xc/domain.ml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,6 @@ let numa_hierarchy =
987987

988988
let numa_mutex = Mutex.create ()
989989

990-
let numa_resources = ref None
991-
992990
let numa_init () =
993991
let xcext = Xenctrlext.get_handle () in
994992
let host = Lazy.force numa_hierarchy in
@@ -1022,14 +1020,7 @@ let numa_placement domid ~vcpus ~cores ~memory affinity =
10221020
(NUMA.nodes host) numa_meminfo
10231021
in
10241022
let vm = NUMARequest.make ~memory ~vcpus ~cores in
1025-
let nodea =
1026-
match !numa_resources with
1027-
| None ->
1028-
Array.of_seq nodes
1029-
| Some a ->
1030-
Array.map2 NUMAResource.min_memory (Array.of_seq nodes) a
1031-
in
1032-
numa_resources := Some nodea ;
1023+
let nodea = Array.of_seq nodes in
10331024
let cpu_affinity, memory_plan =
10341025
match Softaffinity.plan ~vm host nodea with
10351026
| None ->

0 commit comments

Comments
 (0)