From: Daniel Kiper <daniel.kiper@oracle.com>
To: David Vrabel <david.vrabel@citrix.com>
Cc: xen-devel@lists.xenproject.org,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCHv1 4/8] xen/balloon: find non-conflicting regions to place hotplugged memory
Date: Thu, 25 Jun 2015 20:16:51 +0200 [thread overview]
Message-ID: <20150625181651.GL14050@olila.local.net-space.pl> (raw)
In-Reply-To: <1435252263-31952-5-git-send-email-david.vrabel@citrix.com>
On Thu, Jun 25, 2015 at 06:10:59PM +0100, David Vrabel wrote:
> 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>
In general Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
but two nitpicks below...
> ---
> drivers/xen/balloon.c | 63 +++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 53 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
> index fd93369..d0121ee 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,42 @@ 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;
Please add one empty line here.
> + /*
> + * 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 +258,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 +283,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 +305,9 @@ static enum bp_state reserve_additional_memory(long credit)
> balloon_stats.balloon_hotplug = balloon_hotplug;
>
> return BP_DONE;
Ditto.
> + err:
> + release_memory_resource(resource);
> + return BP_ECANCELED;
> }
>
> static void xen_online_page(struct page *page)
> --
> 1.7.10.4
Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-06-25 18:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-25 17:10 [PATCHv1 0/8] mm,xen/balloon: memory hotplug improvements David Vrabel
2015-06-25 17:10 ` [PATCHv1 1/8] mm: memory hotplug with an existing resource David Vrabel
2015-06-25 18:01 ` Daniel Kiper
2015-06-25 17:10 ` [PATCHv1 2/8] xen/balloon: remove scratch page left overs David Vrabel
2015-06-25 18:01 ` Daniel Kiper
2015-06-25 17:10 ` [PATCHv1 3/8] x86/xen: discard RAM regions above the maximum reservation David Vrabel
2015-06-25 18:03 ` Daniel Kiper
2015-06-25 17:10 ` [PATCHv1 4/8] xen/balloon: find non-conflicting regions to place hotplugged memory David Vrabel
2015-06-25 18:16 ` Daniel Kiper [this message]
2015-06-25 17:11 ` [PATCHv1 5/8] xen/balloon: rationalize memory hotplug stats David Vrabel
2015-06-25 18:38 ` Daniel Kiper
2015-06-25 18:54 ` Daniel Kiper
2015-06-25 21:31 ` Daniel Kiper
2015-06-26 8:59 ` [Xen-devel] " David Vrabel
2015-06-25 17:11 ` [PATCHv1 6/8] xen/balloon: only hotplug additional memory if required David Vrabel
2015-06-25 21:18 ` Daniel Kiper
2015-06-26 8:56 ` [Xen-devel] " David Vrabel
2015-06-26 12:46 ` Daniel Kiper
2015-06-26 13:14 ` David Vrabel
2015-06-25 17:11 ` [PATCHv1 7/8] xen/balloon: make alloc_xenballoon_pages() always allocate low pages David Vrabel
2015-06-25 21:36 ` Daniel Kiper
2015-06-25 17:11 ` [PATCHv1 8/8] xen/balloon: use hotplugged pages for foreign mappings etc David Vrabel
2015-06-25 21:49 ` Daniel Kiper
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=20150625181651.GL14050@olila.local.net-space.pl \
--to=daniel.kiper@oracle.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=konrad.wilk@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