WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [PATCH][v2.6.29][XEN] Return unused memory to hypervisor

To: Miroslav Rezanina <mrezanin@xxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH][v2.6.29][XEN] Return unused memory to hypervisor
From: Jeremy Fitzhardinge <jeremy@xxxxxxxx>
Date: Wed, 19 Aug 2009 09:16:33 -0700
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Gianluca Guida <gianluca.guida@xxxxxxxxxx>
Delivery-date: Wed, 19 Aug 2009 09:17:00 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1962776416.772071250687130436.JavaMail.root@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1962776416.772071250687130436.JavaMail.root@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090814 Fedora/3.0-2.6.b3.fc11 Lightning/1.0pre Thunderbird/3.0b3
On 08/19/09 06:05, Miroslav Rezanina wrote:
> 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.
>   

The idea is sound, but I think it might be better to walk the e820
table, and remove any memory ranges which aren't marked as E820_RAM. 
That makes it possible to carve holes in the address space as well as
simply truncate it.

Also, something appears to have smashed your indentation.

    J

> Miroslav Rezanina <mrezanin@xxxxxxxxxx>
> --
> 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@xxxxxxxxxx>
> + * 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@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel