From: David Vrabel <david.vrabel@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Daniel Kiper <daniel.kiper@oracle.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
David Vrabel <david.vrabel@citrix.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>
Subject: [PATCHv2 04/10] xen/balloon: find non-conflicting regions to place hotplugged memory
Date: Fri, 24 Jul 2015 12:47:42 +0100 [thread overview]
Message-ID: <1437738468-24110-5-git-send-email-david.vrabel__12008.4372735166$1437738567$gmane$org@citrix.com> (raw)
In-Reply-To: <1437738468-24110-1-git-send-email-david.vrabel@citrix.com>
Instead of placing hotplugged memory at the end of RAM (which may
conflict with PCI devices or reserved regions) use allocate_resource()
to get a new, suitably aligned resource that does not conflict.
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
drivers/xen/balloon.c | 64 +++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 54 insertions(+), 10 deletions(-)
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index fd93369..29aeb8f 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -54,6 +54,7 @@
#include <linux/memory.h>
#include <linux/memory_hotplug.h>
#include <linux/percpu-defs.h>
+#include <linux/slab.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
@@ -208,6 +209,43 @@ static bool balloon_is_inflated(void)
return false;
}
+static struct resource *additional_memory_resource(phys_addr_t size)
+{
+ struct resource *res;
+ int ret;
+
+ res = kzalloc(sizeof(*res), GFP_KERNEL);
+ if (!res)
+ return NULL;
+
+ res->name = "System RAM";
+ res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+
+ ret = allocate_resource(&iomem_resource, res,
+ size, 0, -1,
+ PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL);
+ if (ret < 0) {
+ pr_err("Cannot allocate new System RAM resource\n");
+ kfree(res);
+ return NULL;
+ }
+
+ return res;
+}
+
+static void release_memory_resource(struct resource *resource)
+{
+ if (!resource)
+ return;
+
+ /*
+ * No need to reset region to identity mapped since we now
+ * know that no I/O can be in this region
+ */
+ release_resource(resource);
+ kfree(resource);
+}
+
/*
* reserve_additional_memory() adds memory region of size >= credit above
* max_pfn. New region is section aligned and size is modified to be multiple
@@ -221,13 +259,17 @@ static bool balloon_is_inflated(void)
static enum bp_state reserve_additional_memory(long credit)
{
+ struct resource *resource;
int nid, rc;
- u64 hotplug_start_paddr;
- unsigned long balloon_hotplug = credit;
+ unsigned long balloon_hotplug;
+
+ balloon_hotplug = round_up(credit, PAGES_PER_SECTION);
+
+ resource = additional_memory_resource(balloon_hotplug * PAGE_SIZE);
+ if (!resource)
+ goto err;
- hotplug_start_paddr = PFN_PHYS(SECTION_ALIGN_UP(max_pfn));
- balloon_hotplug = round_up(balloon_hotplug, PAGES_PER_SECTION);
- nid = memory_add_physaddr_to_nid(hotplug_start_paddr);
+ nid = memory_add_physaddr_to_nid(resource->start);
#ifdef CONFIG_XEN_HAVE_PVMMU
/*
@@ -242,21 +284,20 @@ static enum bp_state reserve_additional_memory(long credit)
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
unsigned long pfn, i;
- pfn = PFN_DOWN(hotplug_start_paddr);
+ pfn = PFN_DOWN(resource->start);
for (i = 0; i < balloon_hotplug; i++) {
if (!set_phys_to_machine(pfn + i, INVALID_P2M_ENTRY)) {
pr_warn("set_phys_to_machine() failed, no memory added\n");
- return BP_ECANCELED;
+ goto err;
}
}
}
#endif
- rc = add_memory(nid, hotplug_start_paddr, balloon_hotplug << PAGE_SHIFT);
-
+ rc = add_memory_resource(nid, resource);
if (rc) {
pr_warn("Cannot add additional memory (%i)\n", rc);
- return BP_ECANCELED;
+ goto err;
}
balloon_hotplug -= credit;
@@ -265,6 +306,9 @@ static enum bp_state reserve_additional_memory(long credit)
balloon_stats.balloon_hotplug = balloon_hotplug;
return BP_DONE;
+ err:
+ release_memory_resource(resource);
+ return BP_ECANCELED;
}
static void xen_online_page(struct page *page)
--
2.1.4
next prev parent reply other threads:[~2015-07-24 11:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1437738468-24110-1-git-send-email-david.vrabel@citrix.com>
2015-07-24 11:47 ` [PATCHv2 01/10] mm: memory hotplug with an existing resource David Vrabel
2015-07-24 11:47 ` [PATCHv2 02/10] xen/balloon: remove scratch page left overs David Vrabel
2015-07-24 11:47 ` [PATCHv2 03/10] x86/xen: discard RAM regions above the maximum reservation David Vrabel
2015-07-24 11:47 ` David Vrabel [this message]
2015-07-24 11:47 ` [PATCHv2 05/10] xen/balloon: rationalize memory hotplug stats David Vrabel
2015-07-24 11:47 ` [PATCHv2 06/10] xen/balloon: only hotplug additional memory if required David Vrabel
2015-07-24 11:47 ` [PATCHv2 07/10] xen/balloon: make alloc_xenballoon_pages() always allocate low pages David Vrabel
2015-07-24 11:47 ` [PATCHv2 08/10] xen/balloon: use hotplugged pages for foreign mappings etc David Vrabel
2015-07-24 11:47 ` [PATCHv2 09/10] x86/xen: export xen_alloc_p2m_entry() David Vrabel
2015-07-24 11:47 ` [PATCHv2 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages David Vrabel
[not found] ` <1437738468-24110-10-git-send-email-david.vrabel@citrix.com>
2015-07-24 18:51 ` [PATCHv2 09/10] x86/xen: export xen_alloc_p2m_entry() Konrad Rzeszutek Wilk
2015-07-29 16:10 ` Daniel Kiper
[not found] ` <1437738468-24110-6-git-send-email-david.vrabel@citrix.com>
2015-07-24 18:54 ` [PATCHv2 05/10] xen/balloon: rationalize memory hotplug stats Konrad Rzeszutek Wilk
2015-07-28 15:22 ` Daniel Kiper
[not found] ` <1437738468-24110-9-git-send-email-david.vrabel@citrix.com>
2015-07-24 18:55 ` [PATCHv2 08/10] xen/balloon: use hotplugged pages for foreign mappings etc Konrad Rzeszutek Wilk
[not found] ` <20150724185545.GD12824@l.oracle.com>
2015-07-27 10:18 ` David Vrabel
[not found] ` <1437738468-24110-11-git-send-email-david.vrabel@citrix.com>
2015-07-24 23:21 ` [PATCHv2 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages Julien Grall
[not found] ` <55B2C882.8050903@citrix.com>
2015-07-27 9:30 ` David Vrabel
[not found] ` <55B5FA39.8000401@citrix.com>
2015-07-27 11:01 ` Julien Grall
[not found] ` <55B60F6E.3040901@citrix.com>
2015-07-27 12:40 ` David Vrabel
2015-07-27 19:37 ` [PATCHv2 00/10] mm, xen/balloon: memory hotplug improvements Daniel Kiper
[not found] ` <1437738468-24110-2-git-send-email-david.vrabel@citrix.com>
2015-07-28 14:54 ` [PATCHv2 01/10] mm: memory hotplug with an existing resource Daniel Kiper
[not found] ` <1437738468-24110-7-git-send-email-david.vrabel@citrix.com>
2015-07-29 15:55 ` [PATCHv2 06/10] xen/balloon: only hotplug additional memory if required Daniel Kiper
[not found] ` <20150729155535.GL3492@olila.local.net-space.pl>
2015-07-29 16:02 ` David Vrabel
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='1437738468-24110-5-git-send-email-david.vrabel__12008.4372735166$1437738567$gmane$org@citrix.com' \
--to=david.vrabel@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=daniel.kiper@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=xen-devel@lists.xenproject.org \
/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;
as well as URLs for NNTP newsgroup(s).