From: Wei Liu Subject: Re: [PATCH v3] libxl: Wait for ballooning if free memory is increasing Date: Fri, 13 Feb 2015 11:01:41 +0000 Message-ID: <20150213110141.GM13644@zion.uk.xensource.com> References: <1422651660-17368-1-git-send-email-mlatimer@suse.com> <3430541.QsN59YLM4l@mlatimer1.dnsdhcp.provo.novell.com> <1423140353.24924.105.camel@citrix.com> <3778105.vVBu11sfGz@mlatimer1.dnsdhcp.provo.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <3778105.vVBu11sfGz@mlatimer1.dnsdhcp.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Mike Latimer Cc: wei.liu2@citrix.com, Ian Campbell , Stefano.Stabellini@eu.citrix.com, george.dunlap@eu.citrix.com, Ian.Jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Tue, Feb 10, 2015 at 09:17:23PM -0700, Mike Latimer wrote: > On Thursday, February 05, 2015 12:45:53 PM Ian Campbell wrote: > > On Mon, 2015-02-02 at 08:17 -0700, Mike Latimer wrote: > > > On Monday, February 02, 2015 02:35:39 PM Ian Campbell wrote: > > > > On Fri, 2015-01-30 at 14:01 -0700, Mike Latimer wrote: > > > > > During domain startup, all required memory ballooning must complete > > > > > within a maximum window of 33 seconds (3 retries, 11 seconds of > > > > > delay). > > > > > If not, domain creation is aborted with a 'failed to free memory' > > > > > error. > ... > > Thanks, applied. > > Unfortunately, I just found an issue with this codepath... > > In tools/libxl/xl_cmdimpl.c:freemem, the following call sets the memory target > for dom0: > > rc = libxl_set_memory_target(ctx, 0, free_memkb - need_memkb, 1, 0); > > This reduces the memory target of dom0 by the amount of memory still needed - > relative to the amount of memory currently free. In other words, during each > iteration of the loop, dom0's target memory is set lower, and lower, and > lower... > > Prior to my changes, this issue would only be noticed when starting very large > domains - due to the loop being limited to 3 iterations. (For example, when > ballooning 512G, dom0 memory could be reduced up to 1.5T.) With my changes, > this loop can take several more iterations (10 or many more in testing). With > each iteration lowering dom0's target, the end result can be dom0 ballooning > down 100's of gigabytes, just to satisfy a much smaller request. (On one > machine, a 64G guest can result in dom0 ballooning down 500G.) > I'm curious why freemem doesn't not return when dom0 is ballooned down 64G? I.e. I think libxl_wait_for_free_memory should return 0 in that case and freeme should just return. Does it suggest there are other domains competing for free memory and dom0 is doing the right thing? Wei. > It seems like a proper fix would be to use libxl_get_memory_target to first > check dom0's target and see if: > > (free_memory + (dom0_current_mem - dom0_target_mem)) >= needed_memory > > If so, there will be sufficient memory when dom0 reaches the target, so don't > change it. Before going down that road, I'd like a sanity check on that > theory, and any advice on the overall picture (including my thread on freemem- > slack). > > I'll leave it up to you if my patch should be reverted until a new patch is > created. > > Thanks! > Mike