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

Re: [PATCH 2/2] xen/balloon: improve accuracy of initial balloon target for dom0


  • To: Jürgen Groß <jgross@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 28 Jan 2026 12:54:25 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=g34bGOa3m840N64Ln1MeYtZ3Vit5X0stVySF50CdSH4=; b=POvTSOukIPyU1QqxwvfCckvzmqhF8sb5dWHGLgZiT1MughdWqv0mt5OQyRZu7Jiki+MYb2A/8B1uBNLKLSa0Y5ioxpPi0DCpoI8DKbLSaDDHqdctR3J/Pk9UcPXcQildEjATr+iT8YMP9xEInSAOHIkXqmLS8f3gSF1Rfa7IX/VbWEZTL5OrC6ViDm3CfseufCnk4EEvXbuyPZau8u+G0VL//Z7pjvswhMeePWEjjf8/UTEBaEA1fDaN9JjopxTyfTmj4zQQpp3rYppaBf01yWpvXLqTQdp5KDe0I+jzes9PasCvr25NsLpfHBx4HVcjhP3GmN2sCuMWwdE5gtci9w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cZPWpCRtaX/EfAGKbPWZmCNsU2vhh6oyVHiFe333nNBAXO/ae0udbJji7fXyYmHORkuQexTu82G70Z08xEvCUGrb3yFlSph2aR/ymT5dYt9i88a2OwB0KQPfa0nQdT39gioCPUUZP4OJErN1N413VN10Cfc/EdsgYonhvIxU9JYjJST1PIbehxp14iT4d709tZODDFNfexYvx3aUJdWtFuh6gbgGsNMjEeDUxerDpiRqgQMfv42iTaozla++Ihzdl91cOyYFuTfb2DFQBfIKCLTFd3AxJ1r6jDRHi021xQRDcX60xDfyY9P2ZnYPO3ULDuP0fyoUeoUWoJ51/AU+7g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
  • Delivery-date: Wed, 28 Jan 2026 11:54:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, Jan 28, 2026 at 12:31:13PM +0100, Jürgen Groß wrote:
> On 28.01.26 12:05, Roger Pau Monne wrote:
> > The dom0 balloon target set by the toolstack is the value returned by
> > XENMEM_current_reservation.  Do the same in the kernel balloon driver and
> > set the current allocation to the value returned by
> > XENMEM_current_reservation.  On my test system this causes the kernel
> > balloon driver target to exactly match the value set by the toolstack in
> > xenstore.
> > 
> > Note this approach can be used by both PV and PVH dom0s, as the toolstack
> > always uses XENMEM_current_reservation to set the initial target regardless
> > of the dom0 type.
> > 
> > Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> > ---
> >   drivers/xen/balloon.c | 27 +++++++++++++++++----------
> >   1 file changed, 17 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
> > index 8c44a25a7d2b..9b6531eb28b6 100644
> > --- a/drivers/xen/balloon.c
> > +++ b/drivers/xen/balloon.c
> > @@ -724,7 +724,8 @@ static int __init balloon_add_regions(void)
> >   static int __init balloon_init(void)
> >   {
> >     struct task_struct *task;
> > -   unsigned long current_pages;
> > +   long current_pages = 0;
> > +   domid_t domid = DOMID_SELF;
> >     int rc;
> >     if (!xen_domain())
> > @@ -732,15 +733,21 @@ static int __init balloon_init(void)
> >     pr_info("Initialising balloon driver\n");
> > -   if (xen_pv_domain()) {
> > -           if (xen_released_pages >= xen_start_info->nr_pages)
> > -                   goto underflow;
> > -           current_pages = min(xen_start_info->nr_pages -
> > -                               xen_released_pages, max_pfn);
> > -   } else {
> > -           if (xen_unpopulated_pages >= get_num_physpages())
> > -                   goto underflow;
> > -           current_pages = get_num_physpages() - xen_unpopulated_pages;
> > +   if (xen_initial_domain())
> > +           current_pages = HYPERVISOR_memory_op(XENMEM_current_reservation,
> > +                                                &domid);
> 
> Is there any specific reason why this should be limited to dom0?
> 
> I _think_ this should work for other domains, too.

Sadly it doesn't, I've already tested.  The value returned by
XENMEM_current_reservation on PV guests is slightly different than
what's in xen_start_info->nr_pages, which exactly what the toolstack
writes in xenstore.  I assume there's some other stuff that's
accounted for in d->tot_pages, but don't really know what I'm afraid.

And in the HVM/PVH case using XENMEM_current_reservation for domUs
would also take into account the Video memory, which skews the target.

This is the best I could do I'm afraid, at the expense of having so
many different way to fetch the information.

Thanks, Roger.



 


Rackspace

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