mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gianluca Guida <gianluca.guida@citrix.com>
To: Miroslav Rezanina <mrezanin@redhat.com>
Cc: "jeremy@goop.org" <jeremy@goop.org>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [Xen-devel] [PATCH][v2.6.29][XEN] Return unused memory to hypervisor
Date: Thu, 20 Aug 2009 10:31:34 +0100	[thread overview]
Message-ID: <19085.6134.99317.256150@gianluca.uk.xensource.com> (raw)
In-Reply-To: <1962776416.772071250687130436.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>

Miroslav Rezanina writes:
 > Hi,
 > 
 > when running linux as XEN guest and use boot parameter mem= to set memory lower then is assigned to guest, not used memory should be returned to hypervisor as free. This is working with kernel available on xen.org pages, but is not working with kernel 2.6.29. Comparing both kernels I found code for returning unused memory to hypervisor is missing. Following patch add this functionality to 2.6.29 kernel.
 > 

A good idea would be to avoid putting this code in the generic kernel
code. For now just placing it in at the end of Xen's post-allocator
init would make it completely transparent to the non-xen kernel.

There's a patch in Jeremy's rebase/master (at the moment reverted)
that allows guest to boot ballooned (which is the opposite of this
case, roughly) which does this kind of calculations while walking the
e820 table. Perhaps this can be moved there after things get to work
again.

Thanks,
Gianluca

 > Miroslav Rezanina <mrezanin@redhat.com>
 > --
 > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
 > index 6a8811a..fd6b0e7 100644
 > --- a/arch/x86/kernel/setup.c
 > +++ b/arch/x86/kernel/setup.c
 > @@ -118,6 +118,10 @@ struct boot_params __initdata boot_params;
 >  struct boot_params boot_params;
 >  #endif
 >  
 > +#ifdef CONFIG_XEN
 > +void __init xen_return_unused_mem(void);
 > +#endif
 > +
 >  /*
 >   * Machine setup..
 >   */
 > @@ -920,6 +924,9 @@ void __init setup_arch(char **cmdline_p)
 >  	paging_init();
 >  	paravirt_pagetable_setup_done(swapper_pg_dir);
 >  	paravirt_post_allocator_init();
 > +#ifdef CONFIG_XEN
 > +	xen_return_unused_mem();
 > +#endif
 >  
 >  #ifdef CONFIG_X86_64
 >  	map_vsyscall();
 > diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
 > index 15c6c68..bc5d2bc 100644
 > --- a/arch/x86/xen/setup.c
 > +++ b/arch/x86/xen/setup.c
 > @@ -20,6 +20,7 @@
 >  #include <xen/page.h>
 >  #include <xen/interface/callback.h>
 >  #include <xen/interface/physdev.h>
 > +#include <xen/interface/memory.h>
 >  #include <xen/features.h>
 >  
 >  #include "xen-ops.h"
 > @@ -34,6 +35,36 @@ extern void xen_syscall32_target(void);
 >  
 >  
 >  /**
 > + * Author: Miroslav Rezanina <mrezanin@redhat.com>
 > + * Function retuns unused memory to hypevisor
 > + **/
 > +void __init xen_return_unused_mem(void)
 > +{
 > +	if (xen_start_info->nr_pages > max_pfn) {
 > +        /*
 > +	* the max_pfn was shrunk (probably by mem=
 > +	* kernel parameter); shrink reservation with the HV
 > +	*/
 > +	struct xen_memory_reservation reservation = {
 > +	.address_bits = 0,
 > +	.extent_order = 0,
 > +	.domid = DOMID_SELF
 > +	};
 > +	unsigned int difference;
 > +	int ret;
 > +
 > +	difference = xen_start_info->nr_pages - max_pfn;
 > +
 > +	set_xen_guest_handle(reservation.extent_start,
 > +		((unsigned long *)xen_start_info->mfn_list) + max_pfn);
 > +	reservation.nr_extents = difference;
 > +	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
 > +		&reservation);
 > +	BUG_ON (ret != difference);
 > +	}
 > +}
 > +
 > +/**
 >   * machine_specific_memory_setup - Hook for machine specific memory setup.
 >   **/
 >  
 > 
 > _______________________________________________
 > Xen-devel mailing list
 > Xen-devel@lists.xensource.com
 > http://lists.xensource.com/xen-devel

  parent reply	other threads:[~2009-08-20 10:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <131246341.771871250687008542.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
2009-08-19 13:05 ` Miroslav Rezanina
2009-08-19 16:16   ` Jeremy Fitzhardinge
2009-08-20  7:47     ` Miroslav Rezanina
2009-08-20 16:39       ` Jeremy Fitzhardinge
2009-09-07 12:41         ` Miroslav Rezanina
2009-09-08 18:58           ` Jeremy Fitzhardinge
2009-08-20  9:31   ` Gianluca Guida [this message]
2009-08-20 11:36     ` [PATCH v2][v2.6.29][XEN] " Miroslav Rezanina
2009-09-03 23:26   ` [PATCH][v2.6.29][XEN] " Jeremy Fitzhardinge
2009-09-04  5:29     ` Miroslav Rezanina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19085.6134.99317.256150@gianluca.uk.xensource.com \
    --to=gianluca.guida@citrix.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mrezanin@redhat.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome