Bug 619037

Summary: balloon.free: dom0_alloc should be in KiB
Product: Red Hat Enterprise Linux 5 Reporter: Andrew Jones <drjones>
Component: xenAssignee: Xen Maintainance List <xen-maint>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 5.5CC: mjenner, mrezanin, xen-maint, yuzhang
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: xen-3.0.3-115.el5 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-01-13 22:23:16 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
balloon.free: dom0_alloc should be in KiB
none
balloon.free: dom0_alloc should be in KiB none

Description Andrew Jones 2010-07-28 12:31:16 UTC
dom0_alloc is getting set in MiB, but all uses of it expect it to be in
KiB, except for the setMemoryTarget() call. A fresh look at dom0's
allocation should be used at that point anyway. Change dom0_alloc to KiB
and change the setMemoryTarget() to use the current allocation divided
by 1024. This change matches upstream.

Comment 1 Andrew Jones 2010-07-28 12:54:05 UTC
Created attachment 434998 [details]
balloon.free: dom0_alloc should be in KiB

Comment 2 Andrew Jones 2010-07-28 14:32:04 UTC
Created attachment 435035 [details]
balloon.free: dom0_alloc should be in KiB

Comment 3 Andrew Jones 2010-07-28 14:33:05 UTC
I self NACKed the original version of this patch since the dom0_origMem concept makes more sense. We should reset dom0's memory back that way it was if the dom0 ballooning fails.

Comment 4 Miroslav Rezanina 2010-07-29 11:54:30 UTC
Fix for BZ #580509 miss the dom0_alloc assignment. So this patch fixes regression introduced by that fix.

Comment 9 Andrew Jones 2010-08-19 14:34:06 UTC
Note to QA how to test:

1) Disable dom0 ballooning by setting (dom0-min-mem 0) to zero in /etc/xen/xend-config.sxp
2) Set dom0's memory with 'xm mem-set' to "total memory" - 750M
3) Boot a guest with 500M memory
4) Attempt to 'xm mem-set' the guest to 1G
5) The ballooning will fail with our without the patch (there's not enough free memory and no dom0 ballooning enabled)
6) Check the xend logs and you should see without the patch that we attempt multiple times to get the memory since we didn't know we should fail immediately due to the improper calculation, with the patch it should fail immediately

I didn't try this myself, but I'm pretty sure that's what will happen based on the code.

Drew

Comment 11 Yufang Zhang 2010-08-24 12:51:41 UTC
(In reply to comment #9)
> Note to QA how to test:
> 
> 1) Disable dom0 ballooning by setting (dom0-min-mem 0) to zero in
> /etc/xen/xend-config.sxp
> 2) Set dom0's memory with 'xm mem-set' to "total memory" - 750M
> 3) Boot a guest with 500M memory
> 4) Attempt to 'xm mem-set' the guest to 1G
> 5) The ballooning will fail with our without the patch (there's not enough free
> memory and no dom0 ballooning enabled)
> 6) Check the xend logs and you should see without the patch that we attempt
> multiple times to get the memory since we didn't know we should fail
> immediately due to the improper calculation, with the patch it should fail
> immediately
> 
> I didn't try this myself, but I'm pretty sure that's what will happen based on
> the code.
> 
> Drew

Hi Andrew, 

I am confused about your steps. If dom0-min-mem is set as 0, code path will never get to dom0.setMemoryTarget(dom0_origMem / 1024), but just throw out a exception. Am I right?

Yufang

Comment 12 Andrew Jones 2010-08-24 13:18:18 UTC
(In reply to comment #11)
> I am confused about your steps. If dom0-min-mem is set as 0, code path will
> never get to dom0.setMemoryTarget(dom0_origMem / 1024), but just throw out a
> exception. Am I right?

We're not testing

dom0.setMemoryTarget(dom0_origMem / 1024)

That part of the patch is just a necessary change in order to correct the size there, after truly correcting the size above.

We're testing

132         if dom0_min_mem > 0:
133             max_free_mem = total_mem - dom0_min_mem
134         else:
135             max_free_mem = total_mem - dom0_alloc

which is broken without this patch (since total_mem is in KB), and then max_free_mem is used to calculate 'retries' which is used to decide whether or not we even try to balloon. As I outlined above in my test steps, before this patch we will try multiple times and then fail (you need to look in the logs to see that). With this patch we will fail immediately (no trying logs). In both cases you'll fail with 

"Not enough free memory and dom0_min_mem is 0"

which is probably the exception you're referring to.  Please check the code again and you'll see what I mean.

Andrew

Comment 13 Yufang Zhang 2010-08-25 06:02:30 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > I am confused about your steps. If dom0-min-mem is set as 0, code path will
> > never get to dom0.setMemoryTarget(dom0_origMem / 1024), but just throw out a
> > exception. Am I right?
> 
> We're not testing
> 
> dom0.setMemoryTarget(dom0_origMem / 1024)
> 
> That part of the patch is just a necessary change in order to correct the size
> there, after truly correcting the size above.
> 
> We're testing
> 
> 132         if dom0_min_mem > 0:
> 133             max_free_mem = total_mem - dom0_min_mem
> 134         else:
> 135             max_free_mem = total_mem - dom0_alloc
> 
> which is broken without this patch (since total_mem is in KB), and then
> max_free_mem is used to calculate 'retries' which is used to decide whether or
> not we even try to balloon. As I outlined above in my test steps, before this
> patch we will try multiple times and then fail (you need to look in the logs to
> see that). With this patch we will fail immediately (no trying logs). In both
> cases you'll fail with 
> 
> "Not enough free memory and dom0_min_mem is 0"
> 
> which is probably the exception you're referring to.  Please check the code
> again and you'll see what I mean.
> 
> Andrew

Thanks Andrew, I got what you mean. Testing this bug with xen-3.0.3-114 and xen-3.0.3-115 according to your steps in comment #9:

1. Disable dom0 ballooning by setting (dom0-min-mem 0) to zero in
/etc/xen/xend-config.sxp
2. Set dom0's memory with 'xm mem-set' to "total memory" - 4096M
3. Create a guest with memory set as 512M  

ballooning failed on both xen-3.0.3-114 and xen-3.0.3-115. But for xen-3.0.3-114, ballooning tried for 20 times until failed, as shown in xend.log:

[2010-08-24 22:52:25 xend 2596] DEBUG (balloon:154) Balloon: 391432 KiB free; 0 to scrub; need 524288; retries: 20.
[2010-08-24 22:52:46 xend.XendDomainInfo 2596] ERROR (XendDomainInfo:219) Domain construction failed
Traceback (most recent call last):
  File "/usr/lib64/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 212, in create
    vm.initDomain()
  File "/usr/lib64/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 2078, in initDomain
    balloon.free(memory + shadow + vtd_mem)
  File "/usr/lib64/python2.4/site-packages/xen/xend/balloon.py", line 181, in free
    raise VmError(('Not enough free memory and dom0_min_mem is 0, so '

For xen-3.0.3-115, ballooning failed immediately.

So change this bug to VERIFIED.

Comment 15 errata-xmlrpc 2011-01-13 22:23:16 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0031.html