From: Martin Kletzander Subject: Re: [libvirt] [PATCH V2] libxl: fix dom0 balloon logic Date: Tue, 31 Mar 2015 16:30:00 +0200 Message-ID: <20150331143000.GA25002@wheatley> References: <1427229822-13837-1-git-send-email-jfehlig@suse.com> <20150331082810.GA4488@wheatley> <551AAC29.3020302@suse.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0551911536246803899==" Return-path: In-Reply-To: <551AAC29.3020302@suse.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: Jim Fehlig Cc: wei.liu2@citrix.com, ian.campbell@citrix.com, Stefano.Stabellini@eu.citrix.com, libvir-list@redhat.com, Ian.Jackson@eu.citrix.com, xen-devel@lists.xen.org, mlatimer@suse.com List-Id: xen-devel@lists.xenproject.org --===============0551911536246803899== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gBBFr7Ir9EOA20Yy" Content-Disposition: inline --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On Tue, Mar 31, 2015 at 08:16:09AM -0600, Jim Fehlig wrote: >Martin Kletzander wrote: >> On Tue, Mar 24, 2015 at 02:43:42PM -0600, Jim Fehlig wrote: >>> Recent testing on large memory systems revealed a bug in the Xen xl >>> tool's freemem() function. When autoballooning is enabled, freemem() >>> is used to ensure enough memory is available to start a domain, >>> ballooning dom0 if necessary. When ballooning large amounts of memory >>> from dom0, freemem() would exceed its self-imposed wait time and >>> return an error. Meanwhile, dom0 continued to balloon. Starting the >>> domain later, after sufficient memory was ballooned from dom0, would >>> succeed. The libvirt implementation in libxlDomainFreeMem() suffers >>> the same bug since it is modeled after freemem(). >>> >>> In the end, the best place to fix the bug on the Xen side was to >>> slightly change the behavior of libxl_wait_for_memory_target(). >>> Instead of failing after caller-provided wait_sec, the function now >>> blocks as long as dom0 memory ballooning is progressing. It will return >>> failure only when more memory is needed to reach the target and wait_sec >>> have expired with no progress being made. See xen.git commit fd3aa246. >>> There was a dicussion on how this would affect other libxl apps like >>> libvirt >>> >>> http://lists.xen.org/archives/html/xen-devel/2015-03/msg00739.html >>> >>> If libvirt containing this patch was build against a Xen containing >>> the old libxl_wait_for_memory_target() behavior, libxlDomainFreeMem() >>> will fail after 30 sec and domain creation will be terminated. >>> Without this patch and with old libxl_wait_for_memory_target() behavior, >>> libxlDomainFreeMem() does not succeed after 30 sec, but returns success >>> anyway. Domain creation continues resulting in all sorts of fun stuff >>> like cpu soft lockups in the guest OS. It was decided to properly fix >>> libxl_wait_for_memory_target(), and if anything improve the default >>> behavior of apps using the freemem reference impl in xl. >>> >>> xl was patched to accommodate the change in >>> libxl_wait_for_memory_target() >>> with xen.git commit 883b30a0. This patch does the same in the libxl >>> driver. While at it, I changed the logic to essentially match >>> freemem() in $xensrc/tools/libxl/xl_cmdimpl.c. It was a bit cleaner >>> IMO and will make it easier to spot future, potentially interesting >>> divergences. >>> >>> Signed-off-by: Jim Fehlig >>> --- >>> >>> V2: Actually use libxl_wait_for_memory_target(), instead of >>> libxl_wait_for_free_memory() >>> >>> src/libxl/libxl_domain.c | 55 >>> +++++++++++++++++++++++------------------------- >>> 1 file changed, 26 insertions(+), 29 deletions(-) >>> >>> diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c >>> index 407a9bd..a1739aa 100644 >>> --- a/src/libxl/libxl_domain.c >>> +++ b/src/libxl/libxl_domain.c >>> @@ -1121,38 +1121,39 @@ libxlDomainFreeMem(libxlDomainObjPrivatePtr >>> priv, libxl_domain_config *d_config) >>> { >>> uint32_t needed_mem; >>> uint32_t free_mem; >>> - size_t i; >>> - int ret = -1; >>> + int ret; >> >> This variable is unnecessary and confusing since you don't return it. >> And without this, you can make ... >> >>> int tries = 3; >>> int wait_secs = 10; >>> >>> - if ((ret = libxl_domain_need_memory(priv->ctx, &d_config->b_info, >>> - &needed_mem)) >= 0) { >>> - for (i = 0; i < tries; ++i) { >>> - if ((ret = libxl_get_free_memory(priv->ctx, &free_mem)) >>> < 0) >>> - break; >>> + ret = libxl_domain_need_memory(priv->ctx, &d_config->b_info, >>> &needed_mem); >>> + if (ret < 0) >>> + goto error; >>> >> >> ... these conditions smaller, e.g.: >> >> if (libxl_domain_need_memory(priv->ctx, &d_config->b_info, >> &needed_mem) < 0) >> goto error; > >Yeah, too much copy and paste. I'll fix this up and send a V3. > >> Do you need this for the release? (sorry for noticing that late) > >No, this can wait. From a Xen perspective, more useful work for the >release would have been this series > >https://www.redhat.com/archives/libvir-list/2015-March/msg01337.html > >But I think it is a bit too late now :-(. > I missed that, sorry. I'll have a look at it tomorrow. Not being that Xen-knowledgeable, I probably haven't felt that confident reviewing that. >Regards, >Jim > >-- >libvir-list mailing list >libvir-list@redhat.com >https://www.redhat.com/mailman/listinfo/libvir-list --gBBFr7Ir9EOA20Yy Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJVGq9oAAoJEAgfwp8kF4bdqxwQAJpok30a8u+7znx41IXhw0SS ahTT6CSVWH4m5Lki1gxVfwxSpWgUzAn1p2+wfcFHth4RAgTKx8PfOyayNhyXcxrt AeWY6hRLmwzb9D3of8arAAYAJriRc2W6j9DSoPmT+s37Lp+VfIxR0g+bSUGp0KqS f5PBuK0oxzsd626N48JbOd4+SYu/2piY3lDhg3k6H1zxJqUdj+vPZdTllindsgSk CnNDej1wg6kkgB9SkWYBRfn9XCK787tuYIRx77RAe3GO5ymIE6bivuSuCBxrqRQQ OZMYEjALMzGkorABsVjxIMt3fVeYS72KZdtdHlXzWRfWO4E59Mj6tUWG5TkfM+Rk kJvkzaZkBk7b2FOZTbgp3hWtHmOl5c31F1g1DFiBYacar0HTikdBGQ3aOKV9il5R DoLJFq49RrMd+9S7Zwu4yMMhX5rvEEysG75h91Lhgs1cAXWV4cfpKyp5vYGxFmN0 6nTzHHHf9aP1Qi5aoeNbRrrMsjvzNnBkH+UzW5IsnTN540skpXyFwlaK6OHSwUt0 cewj+yJwMQ8Q/9mn3rGO0kVrzNPCHfgL3Ts113AnSOKrWURKs4HYv8RrAHCmXMYB F9p6Bgq2DZWxPcErfGI54z3vm3D0OwNZR0g5vRi4hMhU9zFjGvnVz9aQhACPJ0aI yFIx8/ZotqhjmUQefXGf =Pvy2 -----END PGP SIGNATURE----- --gBBFr7Ir9EOA20Yy-- --===============0551911536246803899== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============0551911536246803899==--