Skip to contentSkip to conversation

Fix free() in balloon.py for shortening response time

PATCH New Masaki Kanno 1 participant 1 message Sep 25, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix free() in balloon.py for shortening response time

Hi,

My machine has only 1024MB physical memories. When I required domain memory sizes larger than the physical memory size for creating a guest domain, the response time of xm create command was as follows.

# xm create /xen/vm1.conf memory=1025
Using config file "/xen/vm1.conf".
  << wait 23 seconds >>
Error: I need 1049600 KiB, but dom0_min_mem is 262144 and shrinking to 262144 KiB would leave only 765888 KiB free.
# xm create /xen/vm1.conf memory=10000
Using config file "/xen/vm1.conf".
  << wait 6 minutes 20 seconds >>
Error: I need 10240000 KiB, but dom0_min_mem is 262144 and shrinking to 262144 KiB would leave only 765888 KiB free.
# xm create /xen/vm1.conf memory=100000
Using config file "/xen/vm1.conf".
  << wait 1 hour 8 minutes >>
Error: I need 102400000 KiB, but dom0_min_mem is 262144 and shrinking to 262144 KiB would leave only 765888 KiB free.

If users require domain memory size larger than a physical memory size, I think that we do not need waiting for ballooning, and should cause xm create command error right away.
This patch fixes free() in balloon.py. It does not wait ballooning if users require domain memory size larger than a physical memory size.

Best regards,
Kan

tools/python/xen/xend/balloon.py +16 -0
diff -r a00cc97b392a tools/python/xen/xend/balloon.py
@@ -100,12 +100,28 @@ def free(need_mem):
 
     try:
         dom0_min_mem = xoptions.get_dom0_min_mem() * 1024
+        dom0_alloc = get_dom0_current_alloc()
 
         retries = 0
         sleep_time = SLEEP_TIME_GROWTH
+        new_alloc = 0
         last_new_alloc = None
         last_free = None
         rlimit = RETRY_LIMIT
+
+        # If unreasonable memory size is required, we give up waiting
+        # for ballooning or scrubbing, as if had retried.
+        physinfo = xc.physinfo()
+        free_mem = physinfo['free_memory']
+        scrub_mem = physinfo['scrub_memory']
+        total_mem = physinfo['total_memory']
+        if dom0_min_mem > 0:
+            max_free_mem = total_mem - dom0_min_mem
+        else:
+            max_free_mem = total_mem - dom0_alloc
+        if need_mem >= max_free_mem:
+            retries = rlimit
+
         while retries < rlimit:
             physinfo = xc.physinfo()
             free_mem = physinfo['free_memory']

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel