mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miroslav Rezanina <mrezanin@redhat.com>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xensource.com
Subject: Re: [PATCH][v2.6.29][XEN] Return unused memory to hypervisor
Date: Wed, 16 Sep 2009 03:56:17 -0400 (EDT)	[thread overview]
Message-ID: <1250041003.152221253087777235.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> (raw)
In-Reply-To: <1582654680.152201253087647836.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>

> From: "Jeremy Fitzhardinge" <jeremy@goop.org>
> To: "Miroslav Rezanina" <mrezanin@redhat.com>
> Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xensource.com
> Sent: Friday, September 4, 2009 1:26:24 AM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
> Subject: Re: [PATCH][v2.6.29][XEN] Return unused memory to hypervisor
>
> 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.
> >   
> 
> Are you planning on submitting a revised patch along the lines I
> suggested?
> 
> Thanks,
>     J
General version of patch. This version checks the e820 map for holes
and returns all memory that is not mapped.

Patch:
===========
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index b58e963..acc9166 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -31,6 +31,7 @@
 #include <xen/interface/version.h>
 #include <xen/interface/physdev.h>
 #include <xen/interface/vcpu.h>
+#include <xen/interface/memory.h>
 #include <xen/features.h>
 #include <xen/page.h>
 #include <xen/hvc-console.h>
@@ -122,6 +123,59 @@ static int have_vcpu_info_placement =
 #endif
 	;
 
+void __init xen_return_unused_memory(void)
+{
+	static struct e820map holes = {
+		.nr_map = 0
+	};
+	struct xen_memory_reservation reservation = {
+		.address_bits = 0,
+		.extent_order = 0,
+		.domid        = DOMID_SELF
+	};
+	unsigned long last_end = 0;
+	int i;
+
+	for(i=0;i<e820.nr_map;i++) {
+		if (e820.map[i].addr > last_end) {
+			holes.map[holes.nr_map].addr = last_end;
+			holes.map[holes.nr_map].size =
+				e820.map[i].addr - last_end;
+			holes.nr_map++;
+		}		
+		last_end = e820.map[i].addr + e820.map[i].size;
+	}
+
+	if (last_end < PFN_PHYS((u64)xen_start_info->nr_pages)) {
+		holes.map[holes.nr_map].addr=last_end;
+		holes.map[holes.nr_map].size =
+			PFN_PHYS((u64)xen_start_info->nr_pages) - last_end;
+		holes.nr_map++;
+	}
+
+	if (holes.nr_map == 0)
+		return;
+
+	for(i=0;i<holes.nr_map;i++) {
+		unsigned long spfn = holes.map[i].addr >> PAGE_SHIFT;
+		unsigned long epfn = ((holes.map[i].addr + holes.map[i].size) >> PAGE_SHIFT);
+		int ret;
+
+		if (spfn % PAGE_SIZE != 0)
+			spfn++;
+
+		if (spfn >= epfn)
+			continue;
+
+		set_xen_guest_handle(reservation.extent_start,
+			((unsigned long *)xen_start_info->mfn_list) + spfn);
+
+		reservation.nr_extents = epfn - spfn;
+		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
+			&reservation);
+		BUG_ON (ret != epfn - spfn);
+	}
+}
 
 static void xen_vcpu_setup(int cpu)
 {
@@ -1057,6 +1111,8 @@ static __init void xen_post_allocator_init(void)
 	SetPagePinned(virt_to_page(level3_user_vsyscall));
 #endif
 	xen_mark_init_mm_pinned();
+
+/*	xen_return_unused_memory(); */
 }
 
 /* This is called once we have the cpu_possible_map */
-- 
Miroslav Rezanina
Software Engineer - Virtualization Team - XEN kernel


       reply	other threads:[~2009-09-16  7:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1582654680.152201253087647836.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
2009-09-16  7:56 ` Miroslav Rezanina [this message]
2009-09-16 13:24   ` [Xen-devel] " Konrad Rzeszutek Wilk
     [not found] <1152394510.61021250842386600.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
2009-08-21  8:14 ` Miroslav Rezanina
2009-08-21 11:51   ` Gianluca Guida
     [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-09-03 23:26   ` 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=1250041003.152221253087777235.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com \
    --to=mrezanin@redhat.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --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