[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH] imported patch ca-35152-fix-the-fix



 ocaml/xapi/memory_check.ml |  51 ++++++++++++++++++++++++---------------------
 1 files changed, 27 insertions(+), 24 deletions(-)


# HG changeset patch
# User Matthias Goergens <matthias.goergens@xxxxxxxxxx>
# Date 1287674687 -3600
# Node ID bcef42a441473e7db163f0979f7903ce49ba6ede
# Parent  2dcda97ccb52332974cfbddd749b2b1063b623b3
imported patch ca-35152-fix-the-fix

diff --git a/ocaml/xapi/memory_check.ml b/ocaml/xapi/memory_check.ml
--- a/ocaml/xapi/memory_check.ml
+++ b/ocaml/xapi/memory_check.ml
@@ -62,6 +62,15 @@ type accounting_policy =
        | Dynamic_min
                (** use dynamic_min: liberal: assumes that guests always 
co-operate. *)
 
+(** Common logic of vm_compute_start_memory and vm_compute_used_memory *)
+let choose_memory_required ~policy ~ballooning_enabled ~memory_dynamic_min 
~memory_dynamic_max ~memory_static_max =
+       match (ballooning_enabled, policy) with
+               | (true, Dynamic_min) -> memory_dynamic_min
+               | (true, Dynamic_max) -> memory_dynamic_max
+               | (false, Dynamic_min)
+               | (false, Dynamic_max)
+               | (_, Static_max) -> memory_static_max
+
 (** Calculates the amount of memory required in both 'normal' and 'shadow'
 memory, to start a VM. If the given VM is a PV guest and if memory ballooning
 is enabled, this function returns values derived from the VM's dynamic memory
@@ -70,40 +79,34 @@ ballooning is not enabled or if the VM i
 values derived from the VM's static memory maximum (since currently HVM guests
 are not able to start in a pre-ballooned state). *)
 let vm_compute_start_memory ~__context ?(policy=Dynamic_min) vm_record =
-       if Xapi_fist.disable_memory_checks () then (0L, 0L) else
-       let ballooning_enabled =
-               Helpers.ballooning_enabled_for_vm ~__context vm_record in
-       let memory_static_max = vm_record.API.vM_memory_static_max in
-       let memory_dynamic_min = vm_record.API.vM_memory_dynamic_min in
-       let memory_dynamic_max = vm_record.API.vM_memory_dynamic_max in
-
-       let memory_required = match (ballooning_enabled, policy) with
-               | (true, Dynamic_min) -> memory_dynamic_min
-               | (true, Dynamic_max) -> memory_dynamic_max
-               | (_, _) -> memory_dynamic_max in
-       vm_compute_required_memory vm_record
-               (Memory.kib_of_bytes_used memory_required)
+       if Xapi_fist.disable_memory_checks ()
+       then (0L, 0L)
+       else
+               let memory_required = choose_memory_required
+                       ~policy: policy
+                       ~ballooning_enabled: (Helpers.ballooning_enabled_for_vm 
~__context vm_record)
+                       ~memory_dynamic_min: vm_record.API.vM_memory_dynamic_min
+                       ~memory_dynamic_max: vm_record.API.vM_memory_dynamic_max
+                       ~memory_static_max:  vm_record.API.vM_memory_static_max 
in
+               vm_compute_required_memory vm_record
+                       (Memory.kib_of_bytes_used memory_required)
 
 (** Calculates the amount of memory required in both 'normal' and 'shadow'
 memory, for a running VM. If the VM is currently subject to a memory balloon
 operation, this function returns the maximum amount of memory that the VM will
 need between now, and the point in future time when the operation completes. *)
-(* ToDo: Refactor out common functionality of vm_compute_used_memory and 
vm_compute_start_memory. *)
 let vm_compute_used_memory ~__context policy vm_ref =
        if Xapi_fist.disable_memory_checks () then 0L else
        let vm_main_record = Db.VM.get_record ~__context ~self:vm_ref in
        let vm_boot_record = Helpers.get_boot_record ~__context ~self:vm_ref in
-       let memory_static_max = vm_boot_record.API.vM_memory_static_max in
-       let memory_dynamic_min = vm_main_record.API.vM_memory_dynamic_min in
-       (* ToDo: Is vm_main_record or vm_boot_record the right thing here? *)
-       let memory_dynamic_max = vm_main_record.API.vM_memory_dynamic_max in
 
-       let ballooning_enabled =
-               Helpers.ballooning_enabled_for_vm ~__context vm_boot_record in
-       let memory_required = match (ballooning_enabled, policy) with
-               | (true, Dynamic_min) -> memory_dynamic_min
-               | (true, Dynamic_max) -> memory_dynamic_max
-               | (_, _) -> memory_dynamic_max in
+       let memory_required = choose_memory_required
+               ~policy: policy
+               ~ballooning_enabled: (Helpers.ballooning_enabled_for_vm 
~__context vm_boot_record)
+               ~memory_dynamic_min: vm_main_record.API.vM_memory_dynamic_min
+               (* ToDo: Is vm_main_record or vm_boot_record the right thing 
for dynamic_max? *)
+               ~memory_dynamic_max: vm_main_record.API.vM_memory_dynamic_max 
+               ~memory_static_max:  vm_boot_record.API.vM_memory_static_max in
        memory_required +++ vm_main_record.API.vM_memory_overhead
 
 let vm_compute_resume_memory ~__context vm_ref =
_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.