This is potentially dangerous: the reason we attempt to cap the memory usage of an unresponsive domain is to prevent it suddenly waking up and allocating at a bad moment, resulting in either a transient OOM or loss of low memory. With this change the cap will be 'loose', where target can be higher than memory_actual.
Signed-off-by: David Scott <dave.scott@eu.citrix.com>
let maxmems = IntMap.mapi
(fun domid domain ->
if List.mem domid declared_inactive_domids
- then min domain.target_kib domain.memory_actual_kib
+ then
+ (* CA-41832: clip the target of an 'inactive' domain to within the dynamic min-max range.
+ The danger here is that a domain might be using less than dynamic min now, but might
+ suddenly wake up and allocate memory belonging to someone else later. *)
+ let ideal_kib = min domain.target_kib domain.memory_actual_kib in
+ min domain.dynamic_max_kib (max domain.dynamic_min_kib ideal_kib)
else
if List.mem_assoc domid new_targets
then List.assoc domid new_targets