From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f169.google.com (mail-yk0-f169.google.com [209.85.160.169]) by kanga.kvack.org (Postfix) with ESMTP id 71FBE6B0255 for ; Thu, 30 Jul 2015 13:04:18 -0400 (EDT) Received: by ykdu72 with SMTP id u72so39075294ykd.2 for ; Thu, 30 Jul 2015 10:04:18 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id t123si1305303ywe.6.2015.07.30.10.04.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:16 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 00/10] mm, xen/balloon: memory hotplug improvements Date: Thu, 30 Jul 2015 18:03:02 +0100 Message-ID: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper The series improves the use of hotplug memory in the Xen balloon driver. - Reliably find a non-conflicting location for the hotplugged memory (this fixes memory hotplug in a number of cases, particularly in dom0). - Use hotplugged memory for alloc_xenballooned_pages() (keeping more memory available for the domain and reducing fragmentation of the p2m). Changes in v3: - xen.balloon.hotplug_unpopulated sysctl to enable using hotplug to provide unpopulated (ballooned) pages. - Fix xen_alloc_p2m_entry() for auto-translated guests. Changes in v2: - New BP_WAIT state to signal the balloon process to wait for userspace to online the new memory. - Preallocate P2M entries in alloc_xenballooned_pages() so they do not need allocated later (in a context where GFP_KERNEL allocations are not possible). David -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f176.google.com (mail-yk0-f176.google.com [209.85.160.176]) by kanga.kvack.org (Postfix) with ESMTP id B3BF36B0256 for ; Thu, 30 Jul 2015 13:04:19 -0400 (EDT) Received: by ykay190 with SMTP id y190so39039466yka.3 for ; Thu, 30 Jul 2015 10:04:19 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id t123si1305303ywe.6.2015.07.30.10.04.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:18 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 04/10] xen/balloon: find non-conflicting regions to place hotplugged memory Date: Thu, 30 Jul 2015 18:03:06 +0100 Message-ID: <1438275792-5726-5-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper 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 Reviewed-by: Daniel Kiper --- v3: - Remove stale comment. --- drivers/xen/balloon.c | 73 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index fd93369..7ecbbc5 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -208,26 +209,56 @@ static bool balloon_is_inflated(void) return false; } -/* - * reserve_additional_memory() adds memory region of size >= credit above - * max_pfn. New region is section aligned and size is modified to be multiple - * of section size. Those features allow optimal use of address space and - * establish proper alignment when this function is called first time after - * boot (last section not fully populated at boot time contains unused memory - * pages with PG_reserved bit not set; online_pages_range() does not allow page - * onlining in whole range if first onlined page does not have PG_reserved - * bit set). Real size of added memory is established at page onlining stage. - */ +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); +} 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 +273,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 +295,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 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f174.google.com (mail-yk0-f174.google.com [209.85.160.174]) by kanga.kvack.org (Postfix) with ESMTP id 02CC16B0258 for ; Thu, 30 Jul 2015 13:04:22 -0400 (EDT) Received: by ykax123 with SMTP id x123so39165154yka.1 for ; Thu, 30 Jul 2015 10:04:21 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id o142si1264864ywd.173.2015.07.30.10.04.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:19 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 05/10] xen/balloon: rationalize memory hotplug stats Date: Thu, 30 Jul 2015 18:03:07 +0100 Message-ID: <1438275792-5726-6-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper The stats used for memory hotplug make no sense and are fiddled with in odd ways. Remove them and introduce total_pages to track the total number of pages (both populated and unpopulated) including those within hotplugged regions (note that this includes not yet onlined pages). This will be used in a subsequent commit (xen/balloon: only hotplug additional memory if required) when deciding whether additional memory needs to be hotplugged. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- drivers/xen/balloon.c | 75 +++++++++------------------------------------------ include/xen/balloon.h | 5 +--- 2 files changed, 13 insertions(+), 67 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 7ecbbc5..932d232 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -194,21 +194,6 @@ static enum bp_state update_schedule(enum bp_state state) } #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG -static long current_credit(void) -{ - return balloon_stats.target_pages - balloon_stats.current_pages - - balloon_stats.hotplug_pages; -} - -static bool balloon_is_inflated(void) -{ - if (balloon_stats.balloon_low || balloon_stats.balloon_high || - balloon_stats.balloon_hotplug) - return true; - else - return false; -} - static struct resource *additional_memory_resource(phys_addr_t size) { struct resource *res; @@ -289,10 +274,7 @@ static enum bp_state reserve_additional_memory(long credit) goto err; } - balloon_hotplug -= credit; - - balloon_stats.hotplug_pages += credit; - balloon_stats.balloon_hotplug = balloon_hotplug; + balloon_stats.total_pages += balloon_hotplug; return BP_DONE; err: @@ -308,11 +290,6 @@ static void xen_online_page(struct page *page) __balloon_append(page); - if (balloon_stats.hotplug_pages) - --balloon_stats.hotplug_pages; - else - --balloon_stats.balloon_hotplug; - mutex_unlock(&balloon_mutex); } @@ -329,32 +306,22 @@ static struct notifier_block xen_memory_nb = { .priority = 0 }; #else -static long current_credit(void) +static enum bp_state reserve_additional_memory(long credit) { - unsigned long target = balloon_stats.target_pages; - - target = min(target, - balloon_stats.current_pages + - balloon_stats.balloon_low + - balloon_stats.balloon_high); - - return target - balloon_stats.current_pages; + balloon_stats.target_pages = balloon_stats.current_pages; + return BP_DONE; } +#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ -static bool balloon_is_inflated(void) +static long current_credit(void) { - if (balloon_stats.balloon_low || balloon_stats.balloon_high) - return true; - else - return false; + return balloon_stats.target_pages - balloon_stats.current_pages; } -static enum bp_state reserve_additional_memory(long credit) +static bool balloon_is_inflated(void) { - balloon_stats.target_pages = balloon_stats.current_pages; - return BP_DONE; + return balloon_stats.balloon_low || balloon_stats.balloon_high; } -#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ static enum bp_state increase_reservation(unsigned long nr_pages) { @@ -367,15 +334,6 @@ static enum bp_state increase_reservation(unsigned long nr_pages) .domid = DOMID_SELF }; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - if (!balloon_stats.balloon_low && !balloon_stats.balloon_high) { - nr_pages = min(nr_pages, balloon_stats.balloon_hotplug); - balloon_stats.hotplug_pages += nr_pages; - balloon_stats.balloon_hotplug -= nr_pages; - return BP_DONE; - } -#endif - if (nr_pages > ARRAY_SIZE(frame_list)) nr_pages = ARRAY_SIZE(frame_list); @@ -438,15 +396,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) .domid = DOMID_SELF }; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - if (balloon_stats.hotplug_pages) { - nr_pages = min(nr_pages, balloon_stats.hotplug_pages); - balloon_stats.hotplug_pages -= nr_pages; - balloon_stats.balloon_hotplug += nr_pages; - return BP_DONE; - } -#endif - if (nr_pages > ARRAY_SIZE(frame_list)) nr_pages = ARRAY_SIZE(frame_list); @@ -636,6 +585,8 @@ static void __init balloon_add_region(unsigned long start_pfn, don't subtract from it. */ __balloon_append(page); } + + balloon_stats.total_pages += extra_pfn_end - start_pfn; } static int __init balloon_init(void) @@ -653,6 +604,7 @@ static int __init balloon_init(void) balloon_stats.target_pages = balloon_stats.current_pages; balloon_stats.balloon_low = 0; balloon_stats.balloon_high = 0; + balloon_stats.total_pages = balloon_stats.current_pages; balloon_stats.schedule_delay = 1; balloon_stats.max_schedule_delay = 32; @@ -660,9 +612,6 @@ static int __init balloon_init(void) balloon_stats.max_retry_count = RETRY_UNLIMITED; #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - balloon_stats.hotplug_pages = 0; - balloon_stats.balloon_hotplug = 0; - set_online_page_callback(&xen_online_page); register_memory_notifier(&xen_memory_nb); #endif diff --git a/include/xen/balloon.h b/include/xen/balloon.h index cc2e1a7..c8aee7a 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -11,14 +11,11 @@ struct balloon_stats { /* Number of pages in high- and low-memory balloons. */ unsigned long balloon_low; unsigned long balloon_high; + unsigned long total_pages; unsigned long schedule_delay; unsigned long max_schedule_delay; unsigned long retry_count; unsigned long max_retry_count; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - unsigned long hotplug_pages; - unsigned long balloon_hotplug; -#endif }; extern struct balloon_stats balloon_stats; -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f172.google.com (mail-yk0-f172.google.com [209.85.160.172]) by kanga.kvack.org (Postfix) with ESMTP id 40B446B025A for ; Thu, 30 Jul 2015 13:04:24 -0400 (EDT) Received: by ykax123 with SMTP id x123so39166046yka.1 for ; Thu, 30 Jul 2015 10:04:24 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id t123si1305303ywe.6.2015.07.30.10.04.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:19 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 01/10] mm: memory hotplug with an existing resource Date: Thu, 30 Jul 2015 18:03:03 +0100 Message-ID: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper , Andrew Morton Add add_memory_resource() to add memory using an existing "System RAM" resource. This is useful if the memory region is being located by finding a free resource slot with allocate_resource(). Xen guests will make use of this in their balloon driver to hotplug arbitrary amounts of memory in response to toolstack requests. Signed-off-by: David Vrabel Cc: Andrew Morton --- include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 6ffa0ac..c76d371 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -11,6 +11,7 @@ struct zone; struct pglist_data; struct mem_section; struct memory_block; +struct resource; #ifdef CONFIG_MEMORY_HOTPLUG @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); extern int add_memory(int nid, u64 start, u64 size); +extern int add_memory_resource(int nid, struct resource *resource); extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); extern int arch_add_memory(int nid, u64 start, u64 size); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 003dbe4..169770a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) } /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int __ref add_memory(int nid, u64 start, u64 size) +int __ref add_memory_resource(int nid, struct resource *res) { + u64 start, size; pg_data_t *pgdat = NULL; bool new_pgdat; bool new_node; - struct resource *res; int ret; + start = res->start; + size = resource_size(res); + ret = check_hotplug_memory_range(start, size); if (ret) return ret; - res = register_memory_resource(start, size); - ret = -EEXIST; - if (!res) - return ret; - { /* Stupid hack to suppress address-never-null warning */ void *p = NODE_DATA(nid); new_pgdat = !p; @@ -1290,6 +1288,22 @@ out: mem_hotplug_done(); return ret; } +EXPORT_SYMBOL_GPL(add_memory_resource); + +int __ref add_memory(int nid, u64 start, u64 size) +{ + struct resource *res; + int ret; + + res = register_memory_resource(start, size); + if (!res) + return -EEXIST; + + ret = add_memory_resource(nid, res); + if (ret < 0) + release_memory_resource(res); + return ret; +} EXPORT_SYMBOL_GPL(add_memory); #ifdef CONFIG_MEMORY_HOTREMOVE -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f180.google.com (mail-yk0-f180.google.com [209.85.160.180]) by kanga.kvack.org (Postfix) with ESMTP id B1A436B025C for ; Thu, 30 Jul 2015 13:04:26 -0400 (EDT) Received: by ykba194 with SMTP id a194so39222683ykb.0 for ; Thu, 30 Jul 2015 10:04:26 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id t123si1305303ywe.6.2015.07.30.10.04.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:19 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 08/10] xen/balloon: use hotplugged pages for foreign mappings etc. Date: Thu, 30 Jul 2015 18:03:10 +0100 Message-ID: <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper alloc_xenballooned_pages() is used to get ballooned pages to back foreign mappings etc. Instead of having to balloon out real pages, use (if supported) hotplugged memory. This makes more memory available to the guest and reduces fragmentation in the p2m. This is only enabled if the xen.balloon.hotplug_unpopulated sysctl is set to 1. This sysctl defaults to 0 in case the udev rules to automatically online hotplugged memory do not exist. Signed-off-by: David Vrabel --- v3: - Add xen.balloon.hotplug_unpopulated sysctl to enable use of hotplug for unpopulated pages. --- drivers/xen/balloon.c | 87 +++++++++++++++++++++++++++++++++++++++++++++------ include/xen/balloon.h | 1 + 2 files changed, 79 insertions(+), 9 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 2a01da7..3094f38f 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,46 @@ #include #include +static int xen_hotplug_unpopulated; + +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG + +static int zero; +static int one = 1; + +static struct ctl_table balloon_table[] = { + { + .procname = "hotplug_unpopulated", + .data = &xen_hotplug_unpopulated, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + { } +}; + +static struct ctl_table balloon_root[] = { + { + .procname = "balloon", + .mode = 0555, + .child = balloon_table, + }, + { } +}; + +static struct ctl_table xen_root[] = { + { + .procname = "xen", + .mode = 0555, + .child = balloon_root, + }, + { } +}; + +#endif + /* * balloon_process() state: * @@ -99,6 +140,7 @@ static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)]; /* List of ballooned pages, threaded through the mem_map array. */ static LIST_HEAD(ballooned_pages); +static DECLARE_WAIT_QUEUE_HEAD(balloon_wq); /* Main work function, always executed in process context. */ static void balloon_process(struct work_struct *work); @@ -127,6 +169,7 @@ static void __balloon_append(struct page *page) list_add(&page->lru, &ballooned_pages); balloon_stats.balloon_low++; } + wake_up(&balloon_wq); } static void balloon_append(struct page *page) @@ -242,7 +285,8 @@ static enum bp_state reserve_additional_memory(void) int nid, rc; unsigned long balloon_hotplug; - credit = balloon_stats.target_pages - balloon_stats.total_pages; + credit = balloon_stats.target_pages + balloon_stats.target_unpopulated + - balloon_stats.total_pages; /* * Already hotplugged enough pages? Wait for them to be @@ -323,7 +367,7 @@ static struct notifier_block xen_memory_nb = { static enum bp_state reserve_additional_memory(void) { balloon_stats.target_pages = balloon_stats.current_pages; - return BP_DONE; + return BP_ECANCELED; } #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ @@ -517,6 +561,28 @@ void balloon_set_new_target(unsigned long target) } EXPORT_SYMBOL_GPL(balloon_set_new_target); +static int add_ballooned_pages(int nr_pages) +{ + enum bp_state st; + + if (xen_hotplug_unpopulated) { + st = reserve_additional_memory(); + if (st != BP_ECANCELED) { + mutex_unlock(&balloon_mutex); + wait_event(balloon_wq, + !list_empty(&ballooned_pages)); + mutex_lock(&balloon_mutex); + return 0; + } + } + + st = decrease_reservation(nr_pages, GFP_USER); + if (st != BP_DONE) + return -ENOMEM; + + return 0; +} + /** * alloc_xenballooned_pages - get pages that have been ballooned out * @nr_pages: Number of pages to get @@ -527,26 +593,26 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; + mutex_lock(&balloon_mutex); + + balloon_stats.target_unpopulated += nr_pages; + while (pgno < nr_pages) { page = balloon_retrieve(true); if (page) { pages[pgno++] = page; } else { - enum bp_state st; - st = decrease_reservation(nr_pages - pgno, GFP_USER); - if (st != BP_DONE) + ret = add_ballooned_pages(nr_pages - pgno); + if (ret < 0) goto out_undo; } } mutex_unlock(&balloon_mutex); return 0; out_undo: - while (pgno) - balloon_append(pages[--pgno]); - /* Free the memory back to the kernel soon */ - schedule_delayed_work(&balloon_worker, 0); mutex_unlock(&balloon_mutex); + free_xenballooned_pages(pgno, pages); return -ENOMEM; } EXPORT_SYMBOL(alloc_xenballooned_pages); @@ -567,6 +633,8 @@ void free_xenballooned_pages(int nr_pages, struct page **pages) balloon_append(pages[i]); } + balloon_stats.target_unpopulated -= nr_pages; + /* The balloon may be too large now. Shrink it if needed. */ if (current_credit()) schedule_delayed_work(&balloon_worker, 0); @@ -624,6 +692,7 @@ static int __init balloon_init(void) #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG set_online_page_callback(&xen_online_page); register_memory_notifier(&xen_memory_nb); + register_sysctl_table(xen_root); #endif /* diff --git a/include/xen/balloon.h b/include/xen/balloon.h index 83efdeb..d1767df 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -8,6 +8,7 @@ struct balloon_stats { /* We aim for 'current allocation' == 'target allocation'. */ unsigned long current_pages; unsigned long target_pages; + unsigned long target_unpopulated; /* Number of pages in high- and low-memory balloons. */ unsigned long balloon_low; unsigned long balloon_high; -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f179.google.com (mail-yk0-f179.google.com [209.85.160.179]) by kanga.kvack.org (Postfix) with ESMTP id 0DDE76B025D for ; Thu, 30 Jul 2015 13:04:29 -0400 (EDT) Received: by ykay190 with SMTP id y190so39043018yka.3 for ; Thu, 30 Jul 2015 10:04:28 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id o142si1264864ywd.173.2015.07.30.10.04.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:20 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 06/10] xen/balloon: only hotplug additional memory if required Date: Thu, 30 Jul 2015 18:03:08 +0100 Message-ID: <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper Now that we track the total number of pages (included hotplugged regions), it is easy to determine if more memory needs to be hotplugged. Add a new BP_WAIT state to signal that the balloon process needs to wait until kicked by the memory add notifier (when the new section is onlined by userspace). Signed-off-by: David Vrabel --- v3: - Return BP_WAIT if enough sections are already hotplugged. v2: - New BP_WAIT status after adding new memory sections. --- drivers/xen/balloon.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 932d232..e8b45e8 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -75,12 +75,14 @@ * balloon_process() state: * * BP_DONE: done or nothing to do, + * BP_WAIT: wait to be rescheduled, * BP_EAGAIN: error, go to sleep, * BP_ECANCELED: error, balloon operation canceled. */ enum bp_state { BP_DONE, + BP_WAIT, BP_EAGAIN, BP_ECANCELED }; @@ -167,6 +169,9 @@ static struct page *balloon_next_page(struct page *page) static enum bp_state update_schedule(enum bp_state state) { + if (state == BP_WAIT) + return BP_WAIT; + if (state == BP_ECANCELED) return BP_ECANCELED; @@ -231,12 +236,22 @@ static void release_memory_resource(struct resource *resource) kfree(resource); } -static enum bp_state reserve_additional_memory(long credit) +static enum bp_state reserve_additional_memory(void) { + long credit; struct resource *resource; int nid, rc; unsigned long balloon_hotplug; + credit = balloon_stats.target_pages - balloon_stats.total_pages; + + /* + * Already hotplugged enough pages? Wait for them to be + * onlined. + */ + if (credit <= 0) + return BP_WAIT; + balloon_hotplug = round_up(credit, PAGES_PER_SECTION); resource = additional_memory_resource(balloon_hotplug * PAGE_SIZE); @@ -276,7 +291,7 @@ static enum bp_state reserve_additional_memory(long credit) balloon_stats.total_pages += balloon_hotplug; - return BP_DONE; + return BP_WAIT; err: release_memory_resource(resource); return BP_ECANCELED; @@ -306,7 +321,7 @@ static struct notifier_block xen_memory_nb = { .priority = 0 }; #else -static enum bp_state reserve_additional_memory(long credit) +static enum bp_state reserve_additional_memory(void) { balloon_stats.target_pages = balloon_stats.current_pages; return BP_DONE; @@ -473,7 +488,7 @@ static void balloon_process(struct work_struct *work) if (balloon_is_inflated()) state = increase_reservation(credit); else - state = reserve_additional_memory(credit); + state = reserve_additional_memory(); } if (credit < 0) -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f170.google.com (mail-yk0-f170.google.com [209.85.160.170]) by kanga.kvack.org (Postfix) with ESMTP id 569EF6B025E for ; Thu, 30 Jul 2015 13:04:31 -0400 (EDT) Received: by ykdu72 with SMTP id u72so39080225ykd.2 for ; Thu, 30 Jul 2015 10:04:31 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id o142si1264864ywd.173.2015.07.30.10.04.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:23 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 02/10] xen/balloon: remove scratch page left overs Date: Thu, 30 Jul 2015 18:03:04 +0100 Message-ID: <1438275792-5726-3-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper Commit 0bb599fd30108883b00c7d4a226eeb49111e6932 (xen: remove scratch frames for ballooned pages and m2p override) removed the use of the scratch page for ballooned out pages. Remove some left over function definitions. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- include/xen/balloon.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/xen/balloon.h b/include/xen/balloon.h index a4c1c6a..cc2e1a7 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -29,9 +29,6 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem); void free_xenballooned_pages(int nr_pages, struct page **pages); -struct page *get_balloon_scratch_page(void); -void put_balloon_scratch_page(void); - struct device; #ifdef CONFIG_XEN_SELFBALLOONING extern int register_xen_selfballooning(struct device *dev); -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f173.google.com (mail-yk0-f173.google.com [209.85.160.173]) by kanga.kvack.org (Postfix) with ESMTP id 836F46B025F for ; Thu, 30 Jul 2015 13:04:33 -0400 (EDT) Received: by ykay190 with SMTP id y190so39044663yka.3 for ; Thu, 30 Jul 2015 10:04:33 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id o142si1264864ywd.173.2015.07.30.10.04.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:24 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 09/10] x86/xen: export xen_alloc_p2m_entry() Date: Thu, 30 Jul 2015 18:03:11 +0100 Message-ID: <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper Rename alloc_p2m() to xen_alloc_p2m_entry() and export it. This is useful for ensuring that a p2m entry is allocated (i.e., not a shared missing or identity entry) so that subsequent set_phys_to_machine() calls will require no further allocations. Signed-off-by: David Vrabel --- v3: - Make xen_alloc_p2m_entry() a nop on auto-xlate guests. --- arch/x86/include/asm/xen/page.h | 2 ++ arch/x86/xen/p2m.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h index c44a5d5..960b380 100644 --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h @@ -45,6 +45,8 @@ extern unsigned long *xen_p2m_addr; extern unsigned long xen_p2m_size; extern unsigned long xen_max_p2m_pfn; +extern int xen_alloc_p2m_entry(unsigned long pfn); + extern unsigned long get_phys_to_machine(unsigned long pfn); extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn); extern bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn); diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 8b7f18e..0215897 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -503,7 +503,7 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *pte_pg) * the new pages are installed with cmpxchg; if we lose the race then * simply free the page we allocated and use the one that's there. */ -static bool alloc_p2m(unsigned long pfn) +int xen_alloc_p2m_entry(unsigned long pfn) { unsigned topidx, mididx; unsigned long *top_mfn_p, *mid_mfn; @@ -513,6 +513,9 @@ static bool alloc_p2m(unsigned long pfn) unsigned long addr = (unsigned long)(xen_p2m_addr + pfn); unsigned long p2m_pfn; + if (xen_feature(XENFEAT_auto_translated_physmap)) + return 0; + topidx = p2m_top_index(pfn); mididx = p2m_mid_index(pfn); @@ -524,7 +527,7 @@ static bool alloc_p2m(unsigned long pfn) /* PMD level is missing, allocate a new one */ ptep = alloc_p2m_pmd(addr, pte_pg); if (!ptep) - return false; + return -ENOMEM; } if (p2m_top_mfn) { @@ -541,7 +544,7 @@ static bool alloc_p2m(unsigned long pfn) mid_mfn = alloc_p2m_page(); if (!mid_mfn) - return false; + return -ENOMEM; p2m_mid_mfn_init(mid_mfn, p2m_missing); @@ -567,7 +570,7 @@ static bool alloc_p2m(unsigned long pfn) p2m = alloc_p2m_page(); if (!p2m) - return false; + return -ENOMEM; if (p2m_pfn == PFN_DOWN(__pa(p2m_missing))) p2m_init(p2m); @@ -590,8 +593,9 @@ static bool alloc_p2m(unsigned long pfn) free_p2m_page(p2m); } - return true; + return 0; } +EXPORT_SYMBOL(xen_alloc_p2m_entry); unsigned long __init set_phys_range_identity(unsigned long pfn_s, unsigned long pfn_e) @@ -648,7 +652,10 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn) bool set_phys_to_machine(unsigned long pfn, unsigned long mfn) { if (unlikely(!__set_phys_to_machine(pfn, mfn))) { - if (!alloc_p2m(pfn)) + int ret; + + ret = xen_alloc_p2m_entry(pfn); + if (ret < 0) return false; return __set_phys_to_machine(pfn, mfn); -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f181.google.com (mail-yk0-f181.google.com [209.85.160.181]) by kanga.kvack.org (Postfix) with ESMTP id 9368A6B0260 for ; Thu, 30 Jul 2015 13:04:35 -0400 (EDT) Received: by ykdu72 with SMTP id u72so39081834ykd.2 for ; Thu, 30 Jul 2015 10:04:35 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id t144si1281469ywe.114.2015.07.30.10.04.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:26 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 07/10] xen/balloon: make alloc_xenballoon_pages() always allocate low pages Date: Thu, 30 Jul 2015 18:03:09 +0100 Message-ID: <1438275792-5726-8-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper All users of alloc_xenballoon_pages() wanted low memory pages, so remove the option for high memory. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- arch/x86/xen/grant-table.c | 2 +- drivers/xen/balloon.c | 21 ++++++++------------- drivers/xen/grant-table.c | 2 +- drivers/xen/privcmd.c | 2 +- drivers/xen/xenbus/xenbus_client.c | 3 +-- include/xen/balloon.h | 3 +-- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c index 1580e7a..e079500 100644 --- a/arch/x86/xen/grant-table.c +++ b/arch/x86/xen/grant-table.c @@ -133,7 +133,7 @@ static int __init xlated_setup_gnttab_pages(void) kfree(pages); return -ENOMEM; } - rc = alloc_xenballooned_pages(nr_grant_frames, pages, 0 /* lowmem */); + rc = alloc_xenballooned_pages(nr_grant_frames, pages); if (rc) { pr_warn("%s Couldn't balloon alloc %ld pfns rc:%d\n", __func__, nr_grant_frames, rc); diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index e8b45e8..2a01da7 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -136,17 +136,16 @@ static void balloon_append(struct page *page) } /* balloon_retrieve: rescue a page from the balloon, if it is not empty. */ -static struct page *balloon_retrieve(bool prefer_highmem) +static struct page *balloon_retrieve(bool require_lowmem) { struct page *page; if (list_empty(&ballooned_pages)) return NULL; - if (prefer_highmem) - page = list_entry(ballooned_pages.prev, struct page, lru); - else - page = list_entry(ballooned_pages.next, struct page, lru); + page = list_entry(ballooned_pages.next, struct page, lru); + if (require_lowmem && PageHighMem(page)) + return NULL; list_del(&page->lru); if (PageHighMem(page)) @@ -522,24 +521,20 @@ EXPORT_SYMBOL_GPL(balloon_set_new_target); * alloc_xenballooned_pages - get pages that have been ballooned out * @nr_pages: Number of pages to get * @pages: pages returned - * @highmem: allow highmem pages * @return 0 on success, error otherwise */ -int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem) +int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; mutex_lock(&balloon_mutex); while (pgno < nr_pages) { - page = balloon_retrieve(highmem); - if (page && (highmem || !PageHighMem(page))) { + page = balloon_retrieve(true); + if (page) { pages[pgno++] = page; } else { enum bp_state st; - if (page) - balloon_append(page); - st = decrease_reservation(nr_pages - pgno, - highmem ? GFP_HIGHUSER : GFP_USER); + st = decrease_reservation(nr_pages - pgno, GFP_USER); if (st != BP_DONE) goto out_undo; } diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 62f591f..a4b702c 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -687,7 +687,7 @@ int gnttab_alloc_pages(int nr_pages, struct page **pages) int i; int ret; - ret = alloc_xenballooned_pages(nr_pages, pages, false); + ret = alloc_xenballooned_pages(nr_pages, pages); if (ret < 0) return ret; diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 5a29616..59cfec9 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -401,7 +401,7 @@ static int alloc_empty_pages(struct vm_area_struct *vma, int numpgs) if (pages == NULL) return -ENOMEM; - rc = alloc_xenballooned_pages(numpgs, pages, 0); + rc = alloc_xenballooned_pages(numpgs, pages); if (rc != 0) { pr_warn("%s Could not alloc %d pfns rc:%d\n", __func__, numpgs, rc); diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 9ad3272..2a2da04 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -614,8 +614,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, if (!node) return -ENOMEM; - err = alloc_xenballooned_pages(nr_grefs, node->hvm.pages, - false /* lowmem */); + err = alloc_xenballooned_pages(nr_grefs, node->hvm.pages); if (err) goto out_err; diff --git a/include/xen/balloon.h b/include/xen/balloon.h index c8aee7a..83efdeb 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -22,8 +22,7 @@ extern struct balloon_stats balloon_stats; void balloon_set_new_target(unsigned long target); -int alloc_xenballooned_pages(int nr_pages, struct page **pages, - bool highmem); +int alloc_xenballooned_pages(int nr_pages, struct page **pages); void free_xenballooned_pages(int nr_pages, struct page **pages); struct device; -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f170.google.com (mail-yk0-f170.google.com [209.85.160.170]) by kanga.kvack.org (Postfix) with ESMTP id B8B756B0261 for ; Thu, 30 Jul 2015 13:04:37 -0400 (EDT) Received: by ykdu72 with SMTP id u72so39082651ykd.2 for ; Thu, 30 Jul 2015 10:04:37 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id t144si1281469ywe.114.2015.07.30.10.04.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:04:28 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 03/10] x86/xen: discard RAM regions above the maximum reservation Date: Thu, 30 Jul 2015 18:03:05 +0100 Message-ID: <1438275792-5726-4-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper During setup, discard RAM regions that are above the maximum reservation (instead of marking them as E820_UNUSABLE). This allows hotplug memory to be placed at these addresses. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- arch/x86/xen/setup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 55f388e..32910c5 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -646,6 +646,7 @@ char * __init xen_memory_setup(void) phys_addr_t addr = map[i].addr; phys_addr_t size = map[i].size; u32 type = map[i].type; + bool discard = false; if (type == E820_RAM) { if (addr < mem_end) { @@ -656,10 +657,11 @@ char * __init xen_memory_setup(void) xen_add_extra_mem(addr, size); xen_max_p2m_pfn = PFN_DOWN(addr + size); } else - type = E820_UNUSABLE; + discard = true; } - xen_align_and_add_e820_region(addr, size, type); + if (!discard) + xen_align_and_add_e820_region(addr, size, type); map[i].addr += size; map[i].size -= size; -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f173.google.com (mail-yk0-f173.google.com [209.85.160.173]) by kanga.kvack.org (Postfix) with ESMTP id DF52A9003C7 for ; Thu, 30 Jul 2015 13:15:41 -0400 (EDT) Received: by ykay190 with SMTP id y190so39297929yka.3 for ; Thu, 30 Jul 2015 10:15:41 -0700 (PDT) Received: from SMTP.CITRIX.COM (smtp.citrix.com. [66.165.176.89]) by mx.google.com with ESMTPS id i6si1256352yke.58.2015.07.30.10.15.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 10:15:41 -0700 (PDT) From: David Vrabel Subject: [PATCHv3 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages Date: Thu, 30 Jul 2015 18:03:12 +0100 Message-ID: <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: David Vrabel , linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Daniel Kiper Pages returned by alloc_xenballooned_pages() will be used for grant mapping which will call set_phys_to_machine() (in PV guests). Ballooned pages are set as INVALID_P2M_ENTRY in the p2m and thus may be using the (shared) missing tables and a subsequent set_phys_to_machine() will need to allocate new tables. Since the grant mapping may be done from a context that cannot sleep, the p2m entries must already be allocated. Signed-off-by: David Vrabel --- drivers/xen/balloon.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 3094f38f..e040cf4 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -593,6 +593,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; + int ret = -ENOMEM; mutex_lock(&balloon_mutex); @@ -602,6 +603,11 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) page = balloon_retrieve(true); if (page) { pages[pgno++] = page; +#ifdef CONFIG_XEN_HAVE_PVMMU + ret = xen_alloc_p2m_entry(page_to_pfn(page)); + if (ret < 0) + goto out_undo; +#endif } else { ret = add_ballooned_pages(nr_pages - pgno); if (ret < 0) @@ -613,7 +619,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) out_undo: mutex_unlock(&balloon_mutex); free_xenballooned_pages(pgno, pages); - return -ENOMEM; + return ret; } EXPORT_SYMBOL(alloc_xenballooned_pages); -- 2.1.4 -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by kanga.kvack.org (Postfix) with ESMTP id 393E66B0038 for ; Fri, 31 Jul 2015 19:15:51 -0400 (EDT) Received: by pdjr16 with SMTP id r16so50756027pdj.3 for ; Fri, 31 Jul 2015 16:15:51 -0700 (PDT) Received: from userp1040.oracle.com (userp1040.oracle.com. [156.151.31.81]) by mx.google.com with ESMTPS id bk6si13526401pad.202.2015.07.31.16.15.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 16:15:50 -0700 (PDT) Date: Sat, 1 Aug 2015 01:15:24 +0200 From: Daniel Kiper Subject: Re: [PATCHv3 01/10] mm: memory hotplug with an existing resource Message-ID: <20150731231524.GA3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Andrew Morton On Thu, Jul 30, 2015 at 06:03:03PM +0100, David Vrabel wrote: > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. > > Signed-off-by: David Vrabel > Cc: Andrew Morton Hmmm... Why do you remove my Reviewed-by line from this patch? 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by kanga.kvack.org (Postfix) with ESMTP id E8F066B0038 for ; Fri, 31 Jul 2015 19:18:38 -0400 (EDT) Received: by pabkd10 with SMTP id kd10so47646119pab.2 for ; Fri, 31 Jul 2015 16:18:38 -0700 (PDT) Received: from aserp1040.oracle.com (aserp1040.oracle.com. [141.146.126.69]) by mx.google.com with ESMTPS id pn2si13634180pdb.96.2015.07.31.16.18.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 16:18:37 -0700 (PDT) Date: Sat, 1 Aug 2015 01:18:26 +0200 From: Daniel Kiper Subject: Re: [PATCHv3 06/10] xen/balloon: only hotplug additional memory if required Message-ID: <20150731231826.GB3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky On Thu, Jul 30, 2015 at 06:03:08PM +0100, David Vrabel wrote: > Now that we track the total number of pages (included hotplugged > regions), it is easy to determine if more memory needs to be > hotplugged. > > Add a new BP_WAIT state to signal that the balloon process needs to > wait until kicked by the memory add notifier (when the new section is > onlined by userspace). > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ob0-f169.google.com (mail-ob0-f169.google.com [209.85.214.169]) by kanga.kvack.org (Postfix) with ESMTP id 0669F6B0038 for ; Fri, 31 Jul 2015 19:20:57 -0400 (EDT) Received: by obre1 with SMTP id e1so64577527obr.1 for ; Fri, 31 Jul 2015 16:20:56 -0700 (PDT) Received: from aserp1040.oracle.com (aserp1040.oracle.com. [141.146.126.69]) by mx.google.com with ESMTPS id x79si5539068oix.80.2015.07.31.16.20.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 16:20:53 -0700 (PDT) Date: Sat, 1 Aug 2015 01:20:31 +0200 From: Daniel Kiper Subject: Re: [PATCHv3 08/10] xen/balloon: use hotplugged pages for foreign mappings etc. Message-ID: <20150731232031.GC3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky On Thu, Jul 30, 2015 at 06:03:10PM +0100, David Vrabel wrote: > alloc_xenballooned_pages() is used to get ballooned pages to back > foreign mappings etc. Instead of having to balloon out real pages, > use (if supported) hotplugged memory. > > This makes more memory available to the guest and reduces > fragmentation in the p2m. > > This is only enabled if the xen.balloon.hotplug_unpopulated sysctl is > set to 1. This sysctl defaults to 0 in case the udev rules to > automatically online hotplugged memory do not exist. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by kanga.kvack.org (Postfix) with ESMTP id F25EA6B0038 for ; Fri, 31 Jul 2015 19:22:19 -0400 (EDT) Received: by padck2 with SMTP id ck2so47732940pad.0 for ; Fri, 31 Jul 2015 16:22:19 -0700 (PDT) Received: from aserp1040.oracle.com (aserp1040.oracle.com. [141.146.126.69]) by mx.google.com with ESMTPS id x14si13615349pas.117.2015.07.31.16.22.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 16:22:19 -0700 (PDT) Date: Sat, 1 Aug 2015 01:22:08 +0200 From: Daniel Kiper Subject: Re: [PATCHv3 09/10] x86/xen: export xen_alloc_p2m_entry() Message-ID: <20150731232208.GD3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky On Thu, Jul 30, 2015 at 06:03:11PM +0100, David Vrabel wrote: > Rename alloc_p2m() to xen_alloc_p2m_entry() and export it. > > This is useful for ensuring that a p2m entry is allocated (i.e., not a > shared missing or identity entry) so that subsequent set_phys_to_machine() > calls will require no further allocations. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ob0-f179.google.com (mail-ob0-f179.google.com [209.85.214.179]) by kanga.kvack.org (Postfix) with ESMTP id D2B1D6B0038 for ; Fri, 31 Jul 2015 19:23:59 -0400 (EDT) Received: by obre1 with SMTP id e1so64611680obr.1 for ; Fri, 31 Jul 2015 16:23:59 -0700 (PDT) Received: from userp1040.oracle.com (userp1040.oracle.com. [156.151.31.81]) by mx.google.com with ESMTPS id 67si5528987oid.129.2015.07.31.16.23.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 16:23:59 -0700 (PDT) Date: Sat, 1 Aug 2015 01:23:50 +0200 From: Daniel Kiper Subject: Re: [PATCHv3 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages Message-ID: <20150731232350.GE3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky On Thu, Jul 30, 2015 at 06:03:12PM +0100, David Vrabel wrote: > Pages returned by alloc_xenballooned_pages() will be used for grant > mapping which will call set_phys_to_machine() (in PV guests). > > Ballooned pages are set as INVALID_P2M_ENTRY in the p2m and thus may > be using the (shared) missing tables and a subsequent > set_phys_to_machine() will need to allocate new tables. > > Since the grant mapping may be done from a context that cannot sleep, > the p2m entries must already be allocated. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel PS FYI, next week I am on vacation. -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f173.google.com (mail-yk0-f173.google.com [209.85.160.173]) by kanga.kvack.org (Postfix) with ESMTP id BB6E06B0255 for ; Thu, 13 Aug 2015 06:22:23 -0400 (EDT) Received: by ykdt205 with SMTP id t205so37238350ykd.1 for ; Thu, 13 Aug 2015 03:22:23 -0700 (PDT) Received: from SMTP.CITRIX.COM (smtp.citrix.com. [66.165.176.89]) by mx.google.com with ESMTPS id n124si962064ywe.197.2015.08.13.03.22.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Aug 2015 03:22:22 -0700 (PDT) Message-ID: <55CC6FB7.4080600@citrix.com> Date: Thu, 13 Aug 2015 11:21:43 +0100 From: David Vrabel MIME-Version: 1.0 Subject: Re: [Xen-devel] [PATCHv3 01/10] mm: memory hotplug with an existing resource References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Daniel Kiper , linux-mm@kvack.org, Boris Ostrovsky , Andrew Morton On 30/07/15 18:03, David Vrabel wrote: > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. Ping? This enables a useful feature for Xen guests. > Signed-off-by: David Vrabel > Cc: Andrew Morton > --- > include/linux/memory_hotplug.h | 2 ++ > mm/memory_hotplug.c | 28 +++++++++++++++++++++------- > 2 files changed, 23 insertions(+), 7 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 6ffa0ac..c76d371 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -11,6 +11,7 @@ struct zone; > struct pglist_data; > struct mem_section; > struct memory_block; > +struct resource; > > #ifdef CONFIG_MEMORY_HOTPLUG > > @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} > extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, > void *arg, int (*func)(struct memory_block *, void *)); > extern int add_memory(int nid, u64 start, u64 size); > +extern int add_memory_resource(int nid, struct resource *resource); > extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); > extern int arch_add_memory(int nid, u64 start, u64 size); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 003dbe4..169770a 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) > } > > /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ > -int __ref add_memory(int nid, u64 start, u64 size) > +int __ref add_memory_resource(int nid, struct resource *res) > { > + u64 start, size; > pg_data_t *pgdat = NULL; > bool new_pgdat; > bool new_node; > - struct resource *res; > int ret; > > + start = res->start; > + size = resource_size(res); > + > ret = check_hotplug_memory_range(start, size); > if (ret) > return ret; > > - res = register_memory_resource(start, size); > - ret = -EEXIST; > - if (!res) > - return ret; > - > { /* Stupid hack to suppress address-never-null warning */ > void *p = NODE_DATA(nid); > new_pgdat = !p; > @@ -1290,6 +1288,22 @@ out: > mem_hotplug_done(); > return ret; > } > +EXPORT_SYMBOL_GPL(add_memory_resource); > + > +int __ref add_memory(int nid, u64 start, u64 size) > +{ > + struct resource *res; > + int ret; > + > + res = register_memory_resource(start, size); > + if (!res) > + return -EEXIST; > + > + ret = add_memory_resource(nid, res); > + if (ret < 0) > + release_memory_resource(res); > + return ret; > +} > EXPORT_SYMBOL_GPL(add_memory); > > #ifdef CONFIG_MEMORY_HOTREMOVE > -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qg0-f47.google.com (mail-qg0-f47.google.com [209.85.192.47]) by kanga.kvack.org (Postfix) with ESMTP id 4A7A29003C7 for ; Thu, 13 Aug 2015 16:40:06 -0400 (EDT) Received: by qgdd90 with SMTP id d90so39484252qgd.3 for ; Thu, 13 Aug 2015 13:40:06 -0700 (PDT) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id d92si76846qgf.119.2015.08.13.13.40.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Aug 2015 13:40:05 -0700 (PDT) Date: Thu, 13 Aug 2015 13:40:03 -0700 From: Andrew Morton Subject: Re: [Xen-devel] [PATCHv3 01/10] mm: memory hotplug with an existing resource Message-Id: <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> In-Reply-To: <55CC6FB7.4080600@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> <55CC6FB7.4080600@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Daniel Kiper , linux-mm@kvack.org, Boris Ostrovsky , Tang Chen , Yasuaki Ishimatsu On Thu, 13 Aug 2015 11:21:43 +0100 David Vrabel wrote: > On 30/07/15 18:03, David Vrabel wrote: > > Add add_memory_resource() to add memory using an existing "System RAM" > > resource. This is useful if the memory region is being located by > > finding a free resource slot with allocate_resource(). > > > > Xen guests will make use of this in their balloon driver to hotplug > > arbitrary amounts of memory in response to toolstack requests. > > Ping? This enables a useful feature for Xen guests. > Looks OK to me. I've cc'ed some memory_hotplug.c developers. If they're OK with it, please add the patch to the (Xen?) tree which uses it. Add add_memory_resource() to add memory using an existing "System RAM" resource. This is useful if the memory region is being located by finding a free resource slot with allocate_resource(). Xen guests will make use of this in their balloon driver to hotplug arbitrary amounts of memory in response to toolstack requests. Signed-off-by: David Vrabel Cc: Andrew Morton --- include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 6ffa0ac..c76d371 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -11,6 +11,7 @@ struct zone; struct pglist_data; struct mem_section; struct memory_block; +struct resource; #ifdef CONFIG_MEMORY_HOTPLUG @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); extern int add_memory(int nid, u64 start, u64 size); +extern int add_memory_resource(int nid, struct resource *resource); extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); extern int arch_add_memory(int nid, u64 start, u64 size); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 003dbe4..169770a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) } /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int __ref add_memory(int nid, u64 start, u64 size) +int __ref add_memory_resource(int nid, struct resource *res) { + u64 start, size; pg_data_t *pgdat = NULL; bool new_pgdat; bool new_node; - struct resource *res; int ret; + start = res->start; + size = resource_size(res); + ret = check_hotplug_memory_range(start, size); if (ret) return ret; - res = register_memory_resource(start, size); - ret = -EEXIST; - if (!res) - return ret; - { /* Stupid hack to suppress address-never-null warning */ void *p = NODE_DATA(nid); new_pgdat = !p; @@ -1290,6 +1288,22 @@ out: mem_hotplug_done(); return ret; } +EXPORT_SYMBOL_GPL(add_memory_resource); + +int __ref add_memory(int nid, u64 start, u64 size) +{ + struct resource *res; + int ret; + + res = register_memory_resource(start, size); + if (!res) + return -EEXIST; + + ret = add_memory_resource(nid, res); + if (ret < 0) + release_memory_resource(res); + return ret; +} EXPORT_SYMBOL_GPL(add_memory); #ifdef CONFIG_MEMORY_HOTREMOVE -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by kanga.kvack.org (Postfix) with ESMTP id E28B26B0253 for ; Sun, 16 Aug 2015 07:42:44 -0400 (EDT) Received: by pacum4 with SMTP id um4so3292152pac.3 for ; Sun, 16 Aug 2015 04:42:44 -0700 (PDT) Received: from heian.cn.fujitsu.com ([59.151.112.132]) by mx.google.com with ESMTP id ka15si19240495pbb.176.2015.08.16.04.42.42 for ; Sun, 16 Aug 2015 04:42:43 -0700 (PDT) Message-ID: <55D076D5.8070601@cn.fujitsu.com> Date: Sun, 16 Aug 2015 19:41:09 +0800 From: Tang Chen MIME-Version: 1.0 Subject: Re: [Xen-devel] [PATCHv3 01/10] mm: memory hotplug with an existing resource References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> <55CC6FB7.4080600@citrix.com> <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> In-Reply-To: <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton , David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Daniel Kiper , linux-mm@kvack.org, Boris Ostrovsky , Yasuaki Ishimatsu , tangchen@cn.fujitsu.com On 08/14/2015 04:40 AM, Andrew Morton wrote: > On Thu, 13 Aug 2015 11:21:43 +0100 David Vrabel wrote: > >> On 30/07/15 18:03, David Vrabel wrote: >>> Add add_memory_resource() to add memory using an existing "System RAM" >>> resource. This is useful if the memory region is being located by >>> finding a free resource slot with allocate_resource(). >>> >>> Xen guests will make use of this in their balloon driver to hotplug >>> arbitrary amounts of memory in response to toolstack requests. >> Ping? This enables a useful feature for Xen guests. >> > Looks OK to me. I've cc'ed some memory_hotplug.c developers. If > they're OK with it, please add the patch to the (Xen?) tree which uses > it. > > > > > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. > > Signed-off-by: David Vrabel > Cc: Andrew Morton > --- > include/linux/memory_hotplug.h | 2 ++ > mm/memory_hotplug.c | 28 +++++++++++++++++++++------- > 2 files changed, 23 insertions(+), 7 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 6ffa0ac..c76d371 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -11,6 +11,7 @@ struct zone; > struct pglist_data; > struct mem_section; > struct memory_block; > +struct resource; > > #ifdef CONFIG_MEMORY_HOTPLUG > > @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} > extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, > void *arg, int (*func)(struct memory_block *, void *)); > extern int add_memory(int nid, u64 start, u64 size); > +extern int add_memory_resource(int nid, struct resource *resource); > extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); > extern int arch_add_memory(int nid, u64 start, u64 size); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 003dbe4..169770a 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) > } > > /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ > -int __ref add_memory(int nid, u64 start, u64 size) > +int __ref add_memory_resource(int nid, struct resource *res) > { > + u64 start, size; > pg_data_t *pgdat = NULL; > bool new_pgdat; > bool new_node; > - struct resource *res; > int ret; > > + start = res->start; > + size = resource_size(res); > + > ret = check_hotplug_memory_range(start, size); > if (ret) > return ret; > > - res = register_memory_resource(start, size); > - ret = -EEXIST; > - if (!res) > - return ret; > - > { /* Stupid hack to suppress address-never-null warning */ > void *p = NODE_DATA(nid); > new_pgdat = !p; > @@ -1290,6 +1288,22 @@ out: > mem_hotplug_done(); > return ret; > } > +EXPORT_SYMBOL_GPL(add_memory_resource); > + > +int __ref add_memory(int nid, u64 start, u64 size) > +{ > + struct resource *res; > + int ret; > + > + res = register_memory_resource(start, size); > + if (!res) > + return -EEXIST; > + > + ret = add_memory_resource(nid, res); > + if (ret < 0) Not a big deal, but I think "if (ret)" is enough. The code looks good. Reviewed-by: Tang Chen Thanks. > + release_memory_resource(res); > + return ret; > +} > EXPORT_SYMBOL_GPL(add_memory); > > #ifdef CONFIG_MEMORY_HOTREMOVE -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f179.google.com (mail-yk0-f179.google.com [209.85.160.179]) by kanga.kvack.org (Postfix) with ESMTP id 84E936B0256 for ; Tue, 29 Sep 2015 12:24:59 -0400 (EDT) Received: by ykdg206 with SMTP id g206so12146671ykd.1 for ; Tue, 29 Sep 2015 09:24:59 -0700 (PDT) Received: from SMTP02.CITRIX.COM (smtp02.citrix.com. [66.165.176.63]) by mx.google.com with ESMTPS id u62si4005559ywu.90.2015.09.29.09.24.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Sep 2015 09:24:58 -0700 (PDT) Message-ID: <560ABB57.6080607@citrix.com> Date: Tue, 29 Sep 2015 17:24:55 +0100 From: David Vrabel MIME-Version: 1.0 Subject: Re: [Xen-devel] [PATCHv3 00/10] mm, xen/balloon: memory hotplug improvements References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: David Vrabel , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper On 30/07/15 18:03, David Vrabel wrote: > The series improves the use of hotplug memory in the Xen balloon > driver. > > - Reliably find a non-conflicting location for the hotplugged memory > (this fixes memory hotplug in a number of cases, particularly in > dom0). > > - Use hotplugged memory for alloc_xenballooned_pages() (keeping more > memory available for the domain and reducing fragmentation of the > p2m). Applied to for-linus-4.4. David -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753627AbbG3RES (ORCPT ); Thu, 30 Jul 2015 13:04:18 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:26248 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750734AbbG3REQ (ORCPT ); Thu, 30 Jul 2015 13:04:16 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438766" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 00/10] mm, xen/balloon: memory hotplug improvements Date: Thu, 30 Jul 2015 18:03:02 +0100 Message-ID: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The series improves the use of hotplug memory in the Xen balloon driver. - Reliably find a non-conflicting location for the hotplugged memory (this fixes memory hotplug in a number of cases, particularly in dom0). - Use hotplugged memory for alloc_xenballooned_pages() (keeping more memory available for the domain and reducing fragmentation of the p2m). Changes in v3: - xen.balloon.hotplug_unpopulated sysctl to enable using hotplug to provide unpopulated (ballooned) pages. - Fix xen_alloc_p2m_entry() for auto-translated guests. Changes in v2: - New BP_WAIT state to signal the balloon process to wait for userspace to online the new memory. - Preallocate P2M entries in alloc_xenballooned_pages() so they do not need allocated later (in a context where GFP_KERNEL allocations are not possible). David From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754801AbbG3REU (ORCPT ); Thu, 30 Jul 2015 13:04:20 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:1057 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750734AbbG3RES (ORCPT ); Thu, 30 Jul 2015 13:04:18 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438780" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper , "Andrew Morton" Subject: [PATCHv3 01/10] mm: memory hotplug with an existing resource Date: Thu, 30 Jul 2015 18:03:03 +0100 Message-ID: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add add_memory_resource() to add memory using an existing "System RAM" resource. This is useful if the memory region is being located by finding a free resource slot with allocate_resource(). Xen guests will make use of this in their balloon driver to hotplug arbitrary amounts of memory in response to toolstack requests. Signed-off-by: David Vrabel Cc: Andrew Morton --- include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 6ffa0ac..c76d371 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -11,6 +11,7 @@ struct zone; struct pglist_data; struct mem_section; struct memory_block; +struct resource; #ifdef CONFIG_MEMORY_HOTPLUG @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); extern int add_memory(int nid, u64 start, u64 size); +extern int add_memory_resource(int nid, struct resource *resource); extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); extern int arch_add_memory(int nid, u64 start, u64 size); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 003dbe4..169770a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) } /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int __ref add_memory(int nid, u64 start, u64 size) +int __ref add_memory_resource(int nid, struct resource *res) { + u64 start, size; pg_data_t *pgdat = NULL; bool new_pgdat; bool new_node; - struct resource *res; int ret; + start = res->start; + size = resource_size(res); + ret = check_hotplug_memory_range(start, size); if (ret) return ret; - res = register_memory_resource(start, size); - ret = -EEXIST; - if (!res) - return ret; - { /* Stupid hack to suppress address-never-null warning */ void *p = NODE_DATA(nid); new_pgdat = !p; @@ -1290,6 +1288,22 @@ out: mem_hotplug_done(); return ret; } +EXPORT_SYMBOL_GPL(add_memory_resource); + +int __ref add_memory(int nid, u64 start, u64 size) +{ + struct resource *res; + int ret; + + res = register_memory_resource(start, size); + if (!res) + return -EEXIST; + + ret = add_memory_resource(nid, res); + if (ret < 0) + release_memory_resource(res); + return ret; +} EXPORT_SYMBOL_GPL(add_memory); #ifdef CONFIG_MEMORY_HOTREMOVE -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754853AbbG3RE3 (ORCPT ); Thu, 30 Jul 2015 13:04:29 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:12697 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754811AbbG3REX (ORCPT ); Thu, 30 Jul 2015 13:04:23 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438798" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 02/10] xen/balloon: remove scratch page left overs Date: Thu, 30 Jul 2015 18:03:04 +0100 Message-ID: <1438275792-5726-3-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 0bb599fd30108883b00c7d4a226eeb49111e6932 (xen: remove scratch frames for ballooned pages and m2p override) removed the use of the scratch page for ballooned out pages. Remove some left over function definitions. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- include/xen/balloon.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/xen/balloon.h b/include/xen/balloon.h index a4c1c6a..cc2e1a7 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -29,9 +29,6 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem); void free_xenballooned_pages(int nr_pages, struct page **pages); -struct page *get_balloon_scratch_page(void); -void put_balloon_scratch_page(void); - struct device; #ifdef CONFIG_XEN_SELFBALLOONING extern int register_xen_selfballooning(struct device *dev); -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754862AbbG3REg (ORCPT ); Thu, 30 Jul 2015 13:04:36 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:25139 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754831AbbG3RE2 (ORCPT ); Thu, 30 Jul 2015 13:04:28 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438821" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 03/10] x86/xen: discard RAM regions above the maximum reservation Date: Thu, 30 Jul 2015 18:03:05 +0100 Message-ID: <1438275792-5726-4-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During setup, discard RAM regions that are above the maximum reservation (instead of marking them as E820_UNUSABLE). This allows hotplug memory to be placed at these addresses. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- arch/x86/xen/setup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 55f388e..32910c5 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -646,6 +646,7 @@ char * __init xen_memory_setup(void) phys_addr_t addr = map[i].addr; phys_addr_t size = map[i].size; u32 type = map[i].type; + bool discard = false; if (type == E820_RAM) { if (addr < mem_end) { @@ -656,10 +657,11 @@ char * __init xen_memory_setup(void) xen_add_extra_mem(addr, size); xen_max_p2m_pfn = PFN_DOWN(addr + size); } else - type = E820_UNUSABLE; + discard = true; } - xen_align_and_add_e820_region(addr, size, type); + if (!discard) + xen_align_and_add_e820_region(addr, size, type); map[i].addr += size; map[i].size -= size; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754819AbbG3REX (ORCPT ); Thu, 30 Jul 2015 13:04:23 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:26248 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750868AbbG3RES (ORCPT ); Thu, 30 Jul 2015 13:04:18 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438779" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 04/10] xen/balloon: find non-conflicting regions to place hotplugged memory Date: Thu, 30 Jul 2015 18:03:06 +0100 Message-ID: <1438275792-5726-5-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Daniel Kiper --- v3: - Remove stale comment. --- drivers/xen/balloon.c | 73 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index fd93369..7ecbbc5 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -208,26 +209,56 @@ static bool balloon_is_inflated(void) return false; } -/* - * reserve_additional_memory() adds memory region of size >= credit above - * max_pfn. New region is section aligned and size is modified to be multiple - * of section size. Those features allow optimal use of address space and - * establish proper alignment when this function is called first time after - * boot (last section not fully populated at boot time contains unused memory - * pages with PG_reserved bit not set; online_pages_range() does not allow page - * onlining in whole range if first onlined page does not have PG_reserved - * bit set). Real size of added memory is established at page onlining stage. - */ +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); +} 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 +273,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 +295,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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753714AbbG3RGB (ORCPT ); Thu, 30 Jul 2015 13:06:01 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:44512 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753931AbbG3RET (ORCPT ); Thu, 30 Jul 2015 13:04:19 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438784" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 05/10] xen/balloon: rationalize memory hotplug stats Date: Thu, 30 Jul 2015 18:03:07 +0100 Message-ID: <1438275792-5726-6-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The stats used for memory hotplug make no sense and are fiddled with in odd ways. Remove them and introduce total_pages to track the total number of pages (both populated and unpopulated) including those within hotplugged regions (note that this includes not yet onlined pages). This will be used in a subsequent commit (xen/balloon: only hotplug additional memory if required) when deciding whether additional memory needs to be hotplugged. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- drivers/xen/balloon.c | 75 +++++++++------------------------------------------ include/xen/balloon.h | 5 +--- 2 files changed, 13 insertions(+), 67 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 7ecbbc5..932d232 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -194,21 +194,6 @@ static enum bp_state update_schedule(enum bp_state state) } #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG -static long current_credit(void) -{ - return balloon_stats.target_pages - balloon_stats.current_pages - - balloon_stats.hotplug_pages; -} - -static bool balloon_is_inflated(void) -{ - if (balloon_stats.balloon_low || balloon_stats.balloon_high || - balloon_stats.balloon_hotplug) - return true; - else - return false; -} - static struct resource *additional_memory_resource(phys_addr_t size) { struct resource *res; @@ -289,10 +274,7 @@ static enum bp_state reserve_additional_memory(long credit) goto err; } - balloon_hotplug -= credit; - - balloon_stats.hotplug_pages += credit; - balloon_stats.balloon_hotplug = balloon_hotplug; + balloon_stats.total_pages += balloon_hotplug; return BP_DONE; err: @@ -308,11 +290,6 @@ static void xen_online_page(struct page *page) __balloon_append(page); - if (balloon_stats.hotplug_pages) - --balloon_stats.hotplug_pages; - else - --balloon_stats.balloon_hotplug; - mutex_unlock(&balloon_mutex); } @@ -329,32 +306,22 @@ static struct notifier_block xen_memory_nb = { .priority = 0 }; #else -static long current_credit(void) +static enum bp_state reserve_additional_memory(long credit) { - unsigned long target = balloon_stats.target_pages; - - target = min(target, - balloon_stats.current_pages + - balloon_stats.balloon_low + - balloon_stats.balloon_high); - - return target - balloon_stats.current_pages; + balloon_stats.target_pages = balloon_stats.current_pages; + return BP_DONE; } +#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ -static bool balloon_is_inflated(void) +static long current_credit(void) { - if (balloon_stats.balloon_low || balloon_stats.balloon_high) - return true; - else - return false; + return balloon_stats.target_pages - balloon_stats.current_pages; } -static enum bp_state reserve_additional_memory(long credit) +static bool balloon_is_inflated(void) { - balloon_stats.target_pages = balloon_stats.current_pages; - return BP_DONE; + return balloon_stats.balloon_low || balloon_stats.balloon_high; } -#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ static enum bp_state increase_reservation(unsigned long nr_pages) { @@ -367,15 +334,6 @@ static enum bp_state increase_reservation(unsigned long nr_pages) .domid = DOMID_SELF }; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - if (!balloon_stats.balloon_low && !balloon_stats.balloon_high) { - nr_pages = min(nr_pages, balloon_stats.balloon_hotplug); - balloon_stats.hotplug_pages += nr_pages; - balloon_stats.balloon_hotplug -= nr_pages; - return BP_DONE; - } -#endif - if (nr_pages > ARRAY_SIZE(frame_list)) nr_pages = ARRAY_SIZE(frame_list); @@ -438,15 +396,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) .domid = DOMID_SELF }; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - if (balloon_stats.hotplug_pages) { - nr_pages = min(nr_pages, balloon_stats.hotplug_pages); - balloon_stats.hotplug_pages -= nr_pages; - balloon_stats.balloon_hotplug += nr_pages; - return BP_DONE; - } -#endif - if (nr_pages > ARRAY_SIZE(frame_list)) nr_pages = ARRAY_SIZE(frame_list); @@ -636,6 +585,8 @@ static void __init balloon_add_region(unsigned long start_pfn, don't subtract from it. */ __balloon_append(page); } + + balloon_stats.total_pages += extra_pfn_end - start_pfn; } static int __init balloon_init(void) @@ -653,6 +604,7 @@ static int __init balloon_init(void) balloon_stats.target_pages = balloon_stats.current_pages; balloon_stats.balloon_low = 0; balloon_stats.balloon_high = 0; + balloon_stats.total_pages = balloon_stats.current_pages; balloon_stats.schedule_delay = 1; balloon_stats.max_schedule_delay = 32; @@ -660,9 +612,6 @@ static int __init balloon_init(void) balloon_stats.max_retry_count = RETRY_UNLIMITED; #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - balloon_stats.hotplug_pages = 0; - balloon_stats.balloon_hotplug = 0; - set_online_page_callback(&xen_online_page); register_memory_notifier(&xen_memory_nb); #endif diff --git a/include/xen/balloon.h b/include/xen/balloon.h index cc2e1a7..c8aee7a 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -11,14 +11,11 @@ struct balloon_stats { /* Number of pages in high- and low-memory balloons. */ unsigned long balloon_low; unsigned long balloon_high; + unsigned long total_pages; unsigned long schedule_delay; unsigned long max_schedule_delay; unsigned long retry_count; unsigned long max_retry_count; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - unsigned long hotplug_pages; - unsigned long balloon_hotplug; -#endif }; extern struct balloon_stats balloon_stats; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752558AbbG3RFn (ORCPT ); Thu, 30 Jul 2015 13:05:43 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:1057 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754249AbbG3REU (ORCPT ); Thu, 30 Jul 2015 13:04:20 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438793" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 06/10] xen/balloon: only hotplug additional memory if required Date: Thu, 30 Jul 2015 18:03:08 +0100 Message-ID: <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we track the total number of pages (included hotplugged regions), it is easy to determine if more memory needs to be hotplugged. Add a new BP_WAIT state to signal that the balloon process needs to wait until kicked by the memory add notifier (when the new section is onlined by userspace). Signed-off-by: David Vrabel --- v3: - Return BP_WAIT if enough sections are already hotplugged. v2: - New BP_WAIT status after adding new memory sections. --- drivers/xen/balloon.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 932d232..e8b45e8 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -75,12 +75,14 @@ * balloon_process() state: * * BP_DONE: done or nothing to do, + * BP_WAIT: wait to be rescheduled, * BP_EAGAIN: error, go to sleep, * BP_ECANCELED: error, balloon operation canceled. */ enum bp_state { BP_DONE, + BP_WAIT, BP_EAGAIN, BP_ECANCELED }; @@ -167,6 +169,9 @@ static struct page *balloon_next_page(struct page *page) static enum bp_state update_schedule(enum bp_state state) { + if (state == BP_WAIT) + return BP_WAIT; + if (state == BP_ECANCELED) return BP_ECANCELED; @@ -231,12 +236,22 @@ static void release_memory_resource(struct resource *resource) kfree(resource); } -static enum bp_state reserve_additional_memory(long credit) +static enum bp_state reserve_additional_memory(void) { + long credit; struct resource *resource; int nid, rc; unsigned long balloon_hotplug; + credit = balloon_stats.target_pages - balloon_stats.total_pages; + + /* + * Already hotplugged enough pages? Wait for them to be + * onlined. + */ + if (credit <= 0) + return BP_WAIT; + balloon_hotplug = round_up(credit, PAGES_PER_SECTION); resource = additional_memory_resource(balloon_hotplug * PAGE_SIZE); @@ -276,7 +291,7 @@ static enum bp_state reserve_additional_memory(long credit) balloon_stats.total_pages += balloon_hotplug; - return BP_DONE; + return BP_WAIT; err: release_memory_resource(resource); return BP_ECANCELED; @@ -306,7 +321,7 @@ static struct notifier_block xen_memory_nb = { .priority = 0 }; #else -static enum bp_state reserve_additional_memory(long credit) +static enum bp_state reserve_additional_memory(void) { balloon_stats.target_pages = balloon_stats.current_pages; return BP_DONE; @@ -473,7 +488,7 @@ static void balloon_process(struct work_struct *work) if (balloon_is_inflated()) state = increase_reservation(credit); else - state = reserve_additional_memory(credit); + state = reserve_additional_memory(); } if (credit < 0) -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754494AbbG3RFB (ORCPT ); Thu, 30 Jul 2015 13:05:01 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:25139 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751884AbbG3RE0 (ORCPT ); Thu, 30 Jul 2015 13:04:26 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438823" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 07/10] xen/balloon: make alloc_xenballoon_pages() always allocate low pages Date: Thu, 30 Jul 2015 18:03:09 +0100 Message-ID: <1438275792-5726-8-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All users of alloc_xenballoon_pages() wanted low memory pages, so remove the option for high memory. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- arch/x86/xen/grant-table.c | 2 +- drivers/xen/balloon.c | 21 ++++++++------------- drivers/xen/grant-table.c | 2 +- drivers/xen/privcmd.c | 2 +- drivers/xen/xenbus/xenbus_client.c | 3 +-- include/xen/balloon.h | 3 +-- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c index 1580e7a..e079500 100644 --- a/arch/x86/xen/grant-table.c +++ b/arch/x86/xen/grant-table.c @@ -133,7 +133,7 @@ static int __init xlated_setup_gnttab_pages(void) kfree(pages); return -ENOMEM; } - rc = alloc_xenballooned_pages(nr_grant_frames, pages, 0 /* lowmem */); + rc = alloc_xenballooned_pages(nr_grant_frames, pages); if (rc) { pr_warn("%s Couldn't balloon alloc %ld pfns rc:%d\n", __func__, nr_grant_frames, rc); diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index e8b45e8..2a01da7 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -136,17 +136,16 @@ static void balloon_append(struct page *page) } /* balloon_retrieve: rescue a page from the balloon, if it is not empty. */ -static struct page *balloon_retrieve(bool prefer_highmem) +static struct page *balloon_retrieve(bool require_lowmem) { struct page *page; if (list_empty(&ballooned_pages)) return NULL; - if (prefer_highmem) - page = list_entry(ballooned_pages.prev, struct page, lru); - else - page = list_entry(ballooned_pages.next, struct page, lru); + page = list_entry(ballooned_pages.next, struct page, lru); + if (require_lowmem && PageHighMem(page)) + return NULL; list_del(&page->lru); if (PageHighMem(page)) @@ -522,24 +521,20 @@ EXPORT_SYMBOL_GPL(balloon_set_new_target); * alloc_xenballooned_pages - get pages that have been ballooned out * @nr_pages: Number of pages to get * @pages: pages returned - * @highmem: allow highmem pages * @return 0 on success, error otherwise */ -int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem) +int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; mutex_lock(&balloon_mutex); while (pgno < nr_pages) { - page = balloon_retrieve(highmem); - if (page && (highmem || !PageHighMem(page))) { + page = balloon_retrieve(true); + if (page) { pages[pgno++] = page; } else { enum bp_state st; - if (page) - balloon_append(page); - st = decrease_reservation(nr_pages - pgno, - highmem ? GFP_HIGHUSER : GFP_USER); + st = decrease_reservation(nr_pages - pgno, GFP_USER); if (st != BP_DONE) goto out_undo; } diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 62f591f..a4b702c 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -687,7 +687,7 @@ int gnttab_alloc_pages(int nr_pages, struct page **pages) int i; int ret; - ret = alloc_xenballooned_pages(nr_pages, pages, false); + ret = alloc_xenballooned_pages(nr_pages, pages); if (ret < 0) return ret; diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 5a29616..59cfec9 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -401,7 +401,7 @@ static int alloc_empty_pages(struct vm_area_struct *vma, int numpgs) if (pages == NULL) return -ENOMEM; - rc = alloc_xenballooned_pages(numpgs, pages, 0); + rc = alloc_xenballooned_pages(numpgs, pages); if (rc != 0) { pr_warn("%s Could not alloc %d pfns rc:%d\n", __func__, numpgs, rc); diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 9ad3272..2a2da04 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -614,8 +614,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, if (!node) return -ENOMEM; - err = alloc_xenballooned_pages(nr_grefs, node->hvm.pages, - false /* lowmem */); + err = alloc_xenballooned_pages(nr_grefs, node->hvm.pages); if (err) goto out_err; diff --git a/include/xen/balloon.h b/include/xen/balloon.h index c8aee7a..83efdeb 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -22,8 +22,7 @@ extern struct balloon_stats balloon_stats; void balloon_set_new_target(unsigned long target); -int alloc_xenballooned_pages(int nr_pages, struct page **pages, - bool highmem); +int alloc_xenballooned_pages(int nr_pages, struct page **pages); void free_xenballooned_pages(int nr_pages, struct page **pages); struct device; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754381AbbG3RGD (ORCPT ); Thu, 30 Jul 2015 13:06:03 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:26248 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754111AbbG3RET (ORCPT ); Thu, 30 Jul 2015 13:04:19 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438791" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 08/10] xen/balloon: use hotplugged pages for foreign mappings etc. Date: Thu, 30 Jul 2015 18:03:10 +0100 Message-ID: <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org alloc_xenballooned_pages() is used to get ballooned pages to back foreign mappings etc. Instead of having to balloon out real pages, use (if supported) hotplugged memory. This makes more memory available to the guest and reduces fragmentation in the p2m. This is only enabled if the xen.balloon.hotplug_unpopulated sysctl is set to 1. This sysctl defaults to 0 in case the udev rules to automatically online hotplugged memory do not exist. Signed-off-by: David Vrabel --- v3: - Add xen.balloon.hotplug_unpopulated sysctl to enable use of hotplug for unpopulated pages. --- drivers/xen/balloon.c | 87 +++++++++++++++++++++++++++++++++++++++++++++------ include/xen/balloon.h | 1 + 2 files changed, 79 insertions(+), 9 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 2a01da7..3094f38f 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,46 @@ #include #include +static int xen_hotplug_unpopulated; + +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG + +static int zero; +static int one = 1; + +static struct ctl_table balloon_table[] = { + { + .procname = "hotplug_unpopulated", + .data = &xen_hotplug_unpopulated, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + { } +}; + +static struct ctl_table balloon_root[] = { + { + .procname = "balloon", + .mode = 0555, + .child = balloon_table, + }, + { } +}; + +static struct ctl_table xen_root[] = { + { + .procname = "xen", + .mode = 0555, + .child = balloon_root, + }, + { } +}; + +#endif + /* * balloon_process() state: * @@ -99,6 +140,7 @@ static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)]; /* List of ballooned pages, threaded through the mem_map array. */ static LIST_HEAD(ballooned_pages); +static DECLARE_WAIT_QUEUE_HEAD(balloon_wq); /* Main work function, always executed in process context. */ static void balloon_process(struct work_struct *work); @@ -127,6 +169,7 @@ static void __balloon_append(struct page *page) list_add(&page->lru, &ballooned_pages); balloon_stats.balloon_low++; } + wake_up(&balloon_wq); } static void balloon_append(struct page *page) @@ -242,7 +285,8 @@ static enum bp_state reserve_additional_memory(void) int nid, rc; unsigned long balloon_hotplug; - credit = balloon_stats.target_pages - balloon_stats.total_pages; + credit = balloon_stats.target_pages + balloon_stats.target_unpopulated + - balloon_stats.total_pages; /* * Already hotplugged enough pages? Wait for them to be @@ -323,7 +367,7 @@ static struct notifier_block xen_memory_nb = { static enum bp_state reserve_additional_memory(void) { balloon_stats.target_pages = balloon_stats.current_pages; - return BP_DONE; + return BP_ECANCELED; } #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ @@ -517,6 +561,28 @@ void balloon_set_new_target(unsigned long target) } EXPORT_SYMBOL_GPL(balloon_set_new_target); +static int add_ballooned_pages(int nr_pages) +{ + enum bp_state st; + + if (xen_hotplug_unpopulated) { + st = reserve_additional_memory(); + if (st != BP_ECANCELED) { + mutex_unlock(&balloon_mutex); + wait_event(balloon_wq, + !list_empty(&ballooned_pages)); + mutex_lock(&balloon_mutex); + return 0; + } + } + + st = decrease_reservation(nr_pages, GFP_USER); + if (st != BP_DONE) + return -ENOMEM; + + return 0; +} + /** * alloc_xenballooned_pages - get pages that have been ballooned out * @nr_pages: Number of pages to get @@ -527,26 +593,26 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; + mutex_lock(&balloon_mutex); + + balloon_stats.target_unpopulated += nr_pages; + while (pgno < nr_pages) { page = balloon_retrieve(true); if (page) { pages[pgno++] = page; } else { - enum bp_state st; - st = decrease_reservation(nr_pages - pgno, GFP_USER); - if (st != BP_DONE) + ret = add_ballooned_pages(nr_pages - pgno); + if (ret < 0) goto out_undo; } } mutex_unlock(&balloon_mutex); return 0; out_undo: - while (pgno) - balloon_append(pages[--pgno]); - /* Free the memory back to the kernel soon */ - schedule_delayed_work(&balloon_worker, 0); mutex_unlock(&balloon_mutex); + free_xenballooned_pages(pgno, pages); return -ENOMEM; } EXPORT_SYMBOL(alloc_xenballooned_pages); @@ -567,6 +633,8 @@ void free_xenballooned_pages(int nr_pages, struct page **pages) balloon_append(pages[i]); } + balloon_stats.target_unpopulated -= nr_pages; + /* The balloon may be too large now. Shrink it if needed. */ if (current_credit()) schedule_delayed_work(&balloon_worker, 0); @@ -624,6 +692,7 @@ static int __init balloon_init(void) #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG set_online_page_callback(&xen_online_page); register_memory_notifier(&xen_memory_nb); + register_sysctl_table(xen_root); #endif /* diff --git a/include/xen/balloon.h b/include/xen/balloon.h index 83efdeb..d1767df 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -8,6 +8,7 @@ struct balloon_stats { /* We aim for 'current allocation' == 'target allocation'. */ unsigned long current_pages; unsigned long target_pages; + unsigned long target_unpopulated; /* Number of pages in high- and low-memory balloons. */ unsigned long balloon_low; unsigned long balloon_high; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754832AbbG3RE1 (ORCPT ); Thu, 30 Jul 2015 13:04:27 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:19447 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750868AbbG3REY (ORCPT ); Thu, 30 Jul 2015 13:04:24 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="289438807" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 09/10] x86/xen: export xen_alloc_p2m_entry() Date: Thu, 30 Jul 2015 18:03:11 +0100 Message-ID: <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rename alloc_p2m() to xen_alloc_p2m_entry() and export it. This is useful for ensuring that a p2m entry is allocated (i.e., not a shared missing or identity entry) so that subsequent set_phys_to_machine() calls will require no further allocations. Signed-off-by: David Vrabel --- v3: - Make xen_alloc_p2m_entry() a nop on auto-xlate guests. --- arch/x86/include/asm/xen/page.h | 2 ++ arch/x86/xen/p2m.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h index c44a5d5..960b380 100644 --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h @@ -45,6 +45,8 @@ extern unsigned long *xen_p2m_addr; extern unsigned long xen_p2m_size; extern unsigned long xen_max_p2m_pfn; +extern int xen_alloc_p2m_entry(unsigned long pfn); + extern unsigned long get_phys_to_machine(unsigned long pfn); extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn); extern bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn); diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 8b7f18e..0215897 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -503,7 +503,7 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *pte_pg) * the new pages are installed with cmpxchg; if we lose the race then * simply free the page we allocated and use the one that's there. */ -static bool alloc_p2m(unsigned long pfn) +int xen_alloc_p2m_entry(unsigned long pfn) { unsigned topidx, mididx; unsigned long *top_mfn_p, *mid_mfn; @@ -513,6 +513,9 @@ static bool alloc_p2m(unsigned long pfn) unsigned long addr = (unsigned long)(xen_p2m_addr + pfn); unsigned long p2m_pfn; + if (xen_feature(XENFEAT_auto_translated_physmap)) + return 0; + topidx = p2m_top_index(pfn); mididx = p2m_mid_index(pfn); @@ -524,7 +527,7 @@ static bool alloc_p2m(unsigned long pfn) /* PMD level is missing, allocate a new one */ ptep = alloc_p2m_pmd(addr, pte_pg); if (!ptep) - return false; + return -ENOMEM; } if (p2m_top_mfn) { @@ -541,7 +544,7 @@ static bool alloc_p2m(unsigned long pfn) mid_mfn = alloc_p2m_page(); if (!mid_mfn) - return false; + return -ENOMEM; p2m_mid_mfn_init(mid_mfn, p2m_missing); @@ -567,7 +570,7 @@ static bool alloc_p2m(unsigned long pfn) p2m = alloc_p2m_page(); if (!p2m) - return false; + return -ENOMEM; if (p2m_pfn == PFN_DOWN(__pa(p2m_missing))) p2m_init(p2m); @@ -590,8 +593,9 @@ static bool alloc_p2m(unsigned long pfn) free_p2m_page(p2m); } - return true; + return 0; } +EXPORT_SYMBOL(xen_alloc_p2m_entry); unsigned long __init set_phys_range_identity(unsigned long pfn_s, unsigned long pfn_e) @@ -648,7 +652,10 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn) bool set_phys_to_machine(unsigned long pfn, unsigned long mfn) { if (unlikely(!__set_phys_to_machine(pfn, mfn))) { - if (!alloc_p2m(pfn)) + int ret; + + ret = xen_alloc_p2m_entry(pfn); + if (ret < 0) return false; return __set_phys_to_machine(pfn, mfn); -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754895AbbG3RPm (ORCPT ); Thu, 30 Jul 2015 13:15:42 -0400 Received: from smtp.citrix.com ([66.165.176.89]:62930 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752275AbbG3RPk (ORCPT ); Thu, 30 Jul 2015 13:15:40 -0400 X-IronPort-AV: E=Sophos;i="5.15,577,1432598400"; d="scan'208";a="286213117" From: David Vrabel To: , CC: David Vrabel , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , Daniel Kiper Subject: [PATCHv3 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages Date: Thu, 30 Jul 2015 18:03:12 +0100 Message-ID: <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pages returned by alloc_xenballooned_pages() will be used for grant mapping which will call set_phys_to_machine() (in PV guests). Ballooned pages are set as INVALID_P2M_ENTRY in the p2m and thus may be using the (shared) missing tables and a subsequent set_phys_to_machine() will need to allocate new tables. Since the grant mapping may be done from a context that cannot sleep, the p2m entries must already be allocated. Signed-off-by: David Vrabel --- drivers/xen/balloon.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 3094f38f..e040cf4 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -593,6 +593,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; + int ret = -ENOMEM; mutex_lock(&balloon_mutex); @@ -602,6 +603,11 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) page = balloon_retrieve(true); if (page) { pages[pgno++] = page; +#ifdef CONFIG_XEN_HAVE_PVMMU + ret = xen_alloc_p2m_entry(page_to_pfn(page)); + if (ret < 0) + goto out_undo; +#endif } else { ret = add_ballooned_pages(nr_pages - pgno); if (ret < 0) @@ -613,7 +619,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) out_undo: mutex_unlock(&balloon_mutex); free_xenballooned_pages(pgno, pages); - return -ENOMEM; + return ret; } EXPORT_SYMBOL(alloc_xenballooned_pages); -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754491AbbGaXPy (ORCPT ); Fri, 31 Jul 2015 19:15:54 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:16943 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752859AbbGaXPx (ORCPT ); Fri, 31 Jul 2015 19:15:53 -0400 Date: Sat, 1 Aug 2015 01:15:24 +0200 From: Daniel Kiper To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , Andrew Morton Subject: Re: [PATCHv3 01/10] mm: memory hotplug with an existing resource Message-ID: <20150731231524.GA3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2015 at 06:03:03PM +0100, David Vrabel wrote: > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. > > Signed-off-by: David Vrabel > Cc: Andrew Morton Hmmm... Why do you remove my Reviewed-by line from this patch? Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754478AbbGaXSl (ORCPT ); Fri, 31 Jul 2015 19:18:41 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:41888 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753482AbbGaXSk (ORCPT ); Fri, 31 Jul 2015 19:18:40 -0400 Date: Sat, 1 Aug 2015 01:18:26 +0200 From: Daniel Kiper To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky Subject: Re: [PATCHv3 06/10] xen/balloon: only hotplug additional memory if required Message-ID: <20150731231826.GB3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2015 at 06:03:08PM +0100, David Vrabel wrote: > Now that we track the total number of pages (included hotplugged > regions), it is easy to determine if more memory needs to be > hotplugged. > > Add a new BP_WAIT state to signal that the balloon process needs to > wait until kicked by the memory add notifier (when the new section is > onlined by userspace). > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754486AbbGaXU5 (ORCPT ); Fri, 31 Jul 2015 19:20:57 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:42439 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752501AbbGaXU4 (ORCPT ); Fri, 31 Jul 2015 19:20:56 -0400 Date: Sat, 1 Aug 2015 01:20:31 +0200 From: Daniel Kiper To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky Subject: Re: [PATCHv3 08/10] xen/balloon: use hotplugged pages for foreign mappings etc. Message-ID: <20150731232031.GC3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2015 at 06:03:10PM +0100, David Vrabel wrote: > alloc_xenballooned_pages() is used to get ballooned pages to back > foreign mappings etc. Instead of having to balloon out real pages, > use (if supported) hotplugged memory. > > This makes more memory available to the guest and reduces > fragmentation in the p2m. > > This is only enabled if the xen.balloon.hotplug_unpopulated sysctl is > set to 1. This sysctl defaults to 0 in case the udev rules to > automatically online hotplugged memory do not exist. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754677AbbGaXWX (ORCPT ); Fri, 31 Jul 2015 19:22:23 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:42679 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752715AbbGaXWW (ORCPT ); Fri, 31 Jul 2015 19:22:22 -0400 Date: Sat, 1 Aug 2015 01:22:08 +0200 From: Daniel Kiper To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky Subject: Re: [PATCHv3 09/10] x86/xen: export xen_alloc_p2m_entry() Message-ID: <20150731232208.GD3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2015 at 06:03:11PM +0100, David Vrabel wrote: > Rename alloc_p2m() to xen_alloc_p2m_entry() and export it. > > This is useful for ensuring that a p2m entry is allocated (i.e., not a > shared missing or identity entry) so that subsequent set_phys_to_machine() > calls will require no further allocations. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754480AbbGaXYE (ORCPT ); Fri, 31 Jul 2015 19:24:04 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:18735 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753098AbbGaXYB (ORCPT ); Fri, 31 Jul 2015 19:24:01 -0400 Date: Sat, 1 Aug 2015 01:23:50 +0200 From: Daniel Kiper To: David Vrabel Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, Konrad Rzeszutek Wilk , Boris Ostrovsky Subject: Re: [PATCHv3 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages Message-ID: <20150731232350.GE3488@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2015 at 06:03:12PM +0100, David Vrabel wrote: > Pages returned by alloc_xenballooned_pages() will be used for grant > mapping which will call set_phys_to_machine() (in PV guests). > > Ballooned pages are set as INVALID_P2M_ENTRY in the p2m and thus may > be using the (shared) missing tables and a subsequent > set_phys_to_machine() will need to allocate new tables. > > Since the grant mapping may be done from a context that cannot sleep, > the p2m entries must already be allocated. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel PS FYI, next week I am on vacation. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752079AbbHMKWY (ORCPT ); Thu, 13 Aug 2015 06:22:24 -0400 Received: from smtp.citrix.com ([66.165.176.89]:38269 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750872AbbHMKWX (ORCPT ); Thu, 13 Aug 2015 06:22:23 -0400 X-IronPort-AV: E=Sophos;i="5.15,669,1432598400"; d="scan'208";a="290730177" Message-ID: <55CC6FB7.4080600@citrix.com> Date: Thu, 13 Aug 2015 11:21:43 +0100 From: David Vrabel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 MIME-Version: 1.0 To: David Vrabel , , CC: Daniel Kiper , , "Boris Ostrovsky" , Andrew Morton Subject: Re: [Xen-devel] [PATCHv3 01/10] mm: memory hotplug with an existing resource References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-DLP: MIA2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/07/15 18:03, David Vrabel wrote: > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. Ping? This enables a useful feature for Xen guests. > Signed-off-by: David Vrabel > Cc: Andrew Morton > --- > include/linux/memory_hotplug.h | 2 ++ > mm/memory_hotplug.c | 28 +++++++++++++++++++++------- > 2 files changed, 23 insertions(+), 7 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 6ffa0ac..c76d371 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -11,6 +11,7 @@ struct zone; > struct pglist_data; > struct mem_section; > struct memory_block; > +struct resource; > > #ifdef CONFIG_MEMORY_HOTPLUG > > @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} > extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, > void *arg, int (*func)(struct memory_block *, void *)); > extern int add_memory(int nid, u64 start, u64 size); > +extern int add_memory_resource(int nid, struct resource *resource); > extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); > extern int arch_add_memory(int nid, u64 start, u64 size); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 003dbe4..169770a 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) > } > > /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ > -int __ref add_memory(int nid, u64 start, u64 size) > +int __ref add_memory_resource(int nid, struct resource *res) > { > + u64 start, size; > pg_data_t *pgdat = NULL; > bool new_pgdat; > bool new_node; > - struct resource *res; > int ret; > > + start = res->start; > + size = resource_size(res); > + > ret = check_hotplug_memory_range(start, size); > if (ret) > return ret; > > - res = register_memory_resource(start, size); > - ret = -EEXIST; > - if (!res) > - return ret; > - > { /* Stupid hack to suppress address-never-null warning */ > void *p = NODE_DATA(nid); > new_pgdat = !p; > @@ -1290,6 +1288,22 @@ out: > mem_hotplug_done(); > return ret; > } > +EXPORT_SYMBOL_GPL(add_memory_resource); > + > +int __ref add_memory(int nid, u64 start, u64 size) > +{ > + struct resource *res; > + int ret; > + > + res = register_memory_resource(start, size); > + if (!res) > + return -EEXIST; > + > + ret = add_memory_resource(nid, res); > + if (ret < 0) > + release_memory_resource(res); > + return ret; > +} > EXPORT_SYMBOL_GPL(add_memory); > > #ifdef CONFIG_MEMORY_HOTREMOVE > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754008AbbHMUkG (ORCPT ); Thu, 13 Aug 2015 16:40:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53860 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752183AbbHMUkE (ORCPT ); Thu, 13 Aug 2015 16:40:04 -0400 Date: Thu, 13 Aug 2015 13:40:03 -0700 From: Andrew Morton To: David Vrabel Cc: , , Daniel Kiper , , "Boris Ostrovsky" , Tang Chen , Yasuaki Ishimatsu Subject: Re: [Xen-devel] [PATCHv3 01/10] mm: memory hotplug with an existing resource Message-Id: <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> In-Reply-To: <55CC6FB7.4080600@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> <55CC6FB7.4080600@citrix.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Aug 2015 11:21:43 +0100 David Vrabel wrote: > On 30/07/15 18:03, David Vrabel wrote: > > Add add_memory_resource() to add memory using an existing "System RAM" > > resource. This is useful if the memory region is being located by > > finding a free resource slot with allocate_resource(). > > > > Xen guests will make use of this in their balloon driver to hotplug > > arbitrary amounts of memory in response to toolstack requests. > > Ping? This enables a useful feature for Xen guests. > Looks OK to me. I've cc'ed some memory_hotplug.c developers. If they're OK with it, please add the patch to the (Xen?) tree which uses it. Add add_memory_resource() to add memory using an existing "System RAM" resource. This is useful if the memory region is being located by finding a free resource slot with allocate_resource(). Xen guests will make use of this in their balloon driver to hotplug arbitrary amounts of memory in response to toolstack requests. Signed-off-by: David Vrabel Cc: Andrew Morton --- include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 6ffa0ac..c76d371 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -11,6 +11,7 @@ struct zone; struct pglist_data; struct mem_section; struct memory_block; +struct resource; #ifdef CONFIG_MEMORY_HOTPLUG @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); extern int add_memory(int nid, u64 start, u64 size); +extern int add_memory_resource(int nid, struct resource *resource); extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); extern int arch_add_memory(int nid, u64 start, u64 size); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 003dbe4..169770a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) } /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int __ref add_memory(int nid, u64 start, u64 size) +int __ref add_memory_resource(int nid, struct resource *res) { + u64 start, size; pg_data_t *pgdat = NULL; bool new_pgdat; bool new_node; - struct resource *res; int ret; + start = res->start; + size = resource_size(res); + ret = check_hotplug_memory_range(start, size); if (ret) return ret; - res = register_memory_resource(start, size); - ret = -EEXIST; - if (!res) - return ret; - { /* Stupid hack to suppress address-never-null warning */ void *p = NODE_DATA(nid); new_pgdat = !p; @@ -1290,6 +1288,22 @@ out: mem_hotplug_done(); return ret; } +EXPORT_SYMBOL_GPL(add_memory_resource); + +int __ref add_memory(int nid, u64 start, u64 size) +{ + struct resource *res; + int ret; + + res = register_memory_resource(start, size); + if (!res) + return -EEXIST; + + ret = add_memory_resource(nid, res); + if (ret < 0) + release_memory_resource(res); + return ret; +} EXPORT_SYMBOL_GPL(add_memory); #ifdef CONFIG_MEMORY_HOTREMOVE -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752076AbbHPLmq (ORCPT ); Sun, 16 Aug 2015 07:42:46 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:25522 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751307AbbHPLmn (ORCPT ); Sun, 16 Aug 2015 07:42:43 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="99686181" Message-ID: <55D076D5.8070601@cn.fujitsu.com> Date: Sun, 16 Aug 2015 19:41:09 +0800 From: Tang Chen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Andrew Morton , David Vrabel CC: , , Daniel Kiper , , Boris Ostrovsky , Yasuaki Ishimatsu , Subject: Re: [Xen-devel] [PATCHv3 01/10] mm: memory hotplug with an existing resource References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> <55CC6FB7.4080600@citrix.com> <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> In-Reply-To: <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/14/2015 04:40 AM, Andrew Morton wrote: > On Thu, 13 Aug 2015 11:21:43 +0100 David Vrabel wrote: > >> On 30/07/15 18:03, David Vrabel wrote: >>> Add add_memory_resource() to add memory using an existing "System RAM" >>> resource. This is useful if the memory region is being located by >>> finding a free resource slot with allocate_resource(). >>> >>> Xen guests will make use of this in their balloon driver to hotplug >>> arbitrary amounts of memory in response to toolstack requests. >> Ping? This enables a useful feature for Xen guests. >> > Looks OK to me. I've cc'ed some memory_hotplug.c developers. If > they're OK with it, please add the patch to the (Xen?) tree which uses > it. > > > > > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. > > Signed-off-by: David Vrabel > Cc: Andrew Morton > --- > include/linux/memory_hotplug.h | 2 ++ > mm/memory_hotplug.c | 28 +++++++++++++++++++++------- > 2 files changed, 23 insertions(+), 7 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 6ffa0ac..c76d371 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -11,6 +11,7 @@ struct zone; > struct pglist_data; > struct mem_section; > struct memory_block; > +struct resource; > > #ifdef CONFIG_MEMORY_HOTPLUG > > @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} > extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, > void *arg, int (*func)(struct memory_block *, void *)); > extern int add_memory(int nid, u64 start, u64 size); > +extern int add_memory_resource(int nid, struct resource *resource); > extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); > extern int arch_add_memory(int nid, u64 start, u64 size); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 003dbe4..169770a 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) > } > > /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ > -int __ref add_memory(int nid, u64 start, u64 size) > +int __ref add_memory_resource(int nid, struct resource *res) > { > + u64 start, size; > pg_data_t *pgdat = NULL; > bool new_pgdat; > bool new_node; > - struct resource *res; > int ret; > > + start = res->start; > + size = resource_size(res); > + > ret = check_hotplug_memory_range(start, size); > if (ret) > return ret; > > - res = register_memory_resource(start, size); > - ret = -EEXIST; > - if (!res) > - return ret; > - > { /* Stupid hack to suppress address-never-null warning */ > void *p = NODE_DATA(nid); > new_pgdat = !p; > @@ -1290,6 +1288,22 @@ out: > mem_hotplug_done(); > return ret; > } > +EXPORT_SYMBOL_GPL(add_memory_resource); > + > +int __ref add_memory(int nid, u64 start, u64 size) > +{ > + struct resource *res; > + int ret; > + > + res = register_memory_resource(start, size); > + if (!res) > + return -EEXIST; > + > + ret = add_memory_resource(nid, res); > + if (ret < 0) Not a big deal, but I think "if (ret)" is enough. The code looks good. Reviewed-by: Tang Chen Thanks. > + release_memory_resource(res); > + return ret; > +} > EXPORT_SYMBOL_GPL(add_memory); > > #ifdef CONFIG_MEMORY_HOTREMOVE From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755402AbbI2QZE (ORCPT ); Tue, 29 Sep 2015 12:25:04 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:21620 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751196AbbI2QY7 (ORCPT ); Tue, 29 Sep 2015 12:24:59 -0400 X-IronPort-AV: E=Sophos;i="5.17,608,1437436800"; d="scan'208";a="306873035" Message-ID: <560ABB57.6080607@citrix.com> Date: Tue, 29 Sep 2015 17:24:55 +0100 From: David Vrabel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 MIME-Version: 1.0 To: David Vrabel , , CC: , Boris Ostrovsky , "Daniel Kiper" Subject: Re: [Xen-devel] [PATCHv3 00/10] mm, xen/balloon: memory hotplug improvements References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/07/15 18:03, David Vrabel wrote: > The series improves the use of hotplug memory in the Xen balloon > driver. > > - Reliably find a non-conflicting location for the hotplugged memory > (this fixes memory hotplug in a number of cases, particularly in > dom0). > > - Use hotplugged memory for alloc_xenballooned_pages() (keeping more > memory available for the domain and reducing fragmentation of the > p2m). Applied to for-linus-4.4. David From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 05/10] xen/balloon: rationalize memory hotplug stats Date: Thu, 30 Jul 2015 18:03:07 +0100 Message-ID: <1438275792-5726-6-git-send-email-david.vrabel__17055.4146673114$1438275936$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFl-0002xf-IJ for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:21 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org The stats used for memory hotplug make no sense and are fiddled with in odd ways. Remove them and introduce total_pages to track the total number of pages (both populated and unpopulated) including those within hotplugged regions (note that this includes not yet onlined pages). This will be used in a subsequent commit (xen/balloon: only hotplug additional memory if required) when deciding whether additional memory needs to be hotplugged. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- drivers/xen/balloon.c | 75 +++++++++------------------------------------------ include/xen/balloon.h | 5 +--- 2 files changed, 13 insertions(+), 67 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 7ecbbc5..932d232 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -194,21 +194,6 @@ static enum bp_state update_schedule(enum bp_state state) } #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG -static long current_credit(void) -{ - return balloon_stats.target_pages - balloon_stats.current_pages - - balloon_stats.hotplug_pages; -} - -static bool balloon_is_inflated(void) -{ - if (balloon_stats.balloon_low || balloon_stats.balloon_high || - balloon_stats.balloon_hotplug) - return true; - else - return false; -} - static struct resource *additional_memory_resource(phys_addr_t size) { struct resource *res; @@ -289,10 +274,7 @@ static enum bp_state reserve_additional_memory(long credit) goto err; } - balloon_hotplug -= credit; - - balloon_stats.hotplug_pages += credit; - balloon_stats.balloon_hotplug = balloon_hotplug; + balloon_stats.total_pages += balloon_hotplug; return BP_DONE; err: @@ -308,11 +290,6 @@ static void xen_online_page(struct page *page) __balloon_append(page); - if (balloon_stats.hotplug_pages) - --balloon_stats.hotplug_pages; - else - --balloon_stats.balloon_hotplug; - mutex_unlock(&balloon_mutex); } @@ -329,32 +306,22 @@ static struct notifier_block xen_memory_nb = { .priority = 0 }; #else -static long current_credit(void) +static enum bp_state reserve_additional_memory(long credit) { - unsigned long target = balloon_stats.target_pages; - - target = min(target, - balloon_stats.current_pages + - balloon_stats.balloon_low + - balloon_stats.balloon_high); - - return target - balloon_stats.current_pages; + balloon_stats.target_pages = balloon_stats.current_pages; + return BP_DONE; } +#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ -static bool balloon_is_inflated(void) +static long current_credit(void) { - if (balloon_stats.balloon_low || balloon_stats.balloon_high) - return true; - else - return false; + return balloon_stats.target_pages - balloon_stats.current_pages; } -static enum bp_state reserve_additional_memory(long credit) +static bool balloon_is_inflated(void) { - balloon_stats.target_pages = balloon_stats.current_pages; - return BP_DONE; + return balloon_stats.balloon_low || balloon_stats.balloon_high; } -#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ static enum bp_state increase_reservation(unsigned long nr_pages) { @@ -367,15 +334,6 @@ static enum bp_state increase_reservation(unsigned long nr_pages) .domid = DOMID_SELF }; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - if (!balloon_stats.balloon_low && !balloon_stats.balloon_high) { - nr_pages = min(nr_pages, balloon_stats.balloon_hotplug); - balloon_stats.hotplug_pages += nr_pages; - balloon_stats.balloon_hotplug -= nr_pages; - return BP_DONE; - } -#endif - if (nr_pages > ARRAY_SIZE(frame_list)) nr_pages = ARRAY_SIZE(frame_list); @@ -438,15 +396,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) .domid = DOMID_SELF }; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - if (balloon_stats.hotplug_pages) { - nr_pages = min(nr_pages, balloon_stats.hotplug_pages); - balloon_stats.hotplug_pages -= nr_pages; - balloon_stats.balloon_hotplug += nr_pages; - return BP_DONE; - } -#endif - if (nr_pages > ARRAY_SIZE(frame_list)) nr_pages = ARRAY_SIZE(frame_list); @@ -636,6 +585,8 @@ static void __init balloon_add_region(unsigned long start_pfn, don't subtract from it. */ __balloon_append(page); } + + balloon_stats.total_pages += extra_pfn_end - start_pfn; } static int __init balloon_init(void) @@ -653,6 +604,7 @@ static int __init balloon_init(void) balloon_stats.target_pages = balloon_stats.current_pages; balloon_stats.balloon_low = 0; balloon_stats.balloon_high = 0; + balloon_stats.total_pages = balloon_stats.current_pages; balloon_stats.schedule_delay = 1; balloon_stats.max_schedule_delay = 32; @@ -660,9 +612,6 @@ static int __init balloon_init(void) balloon_stats.max_retry_count = RETRY_UNLIMITED; #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - balloon_stats.hotplug_pages = 0; - balloon_stats.balloon_hotplug = 0; - set_online_page_callback(&xen_online_page); register_memory_notifier(&xen_memory_nb); #endif diff --git a/include/xen/balloon.h b/include/xen/balloon.h index cc2e1a7..c8aee7a 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -11,14 +11,11 @@ struct balloon_stats { /* Number of pages in high- and low-memory balloons. */ unsigned long balloon_low; unsigned long balloon_high; + unsigned long total_pages; unsigned long schedule_delay; unsigned long max_schedule_delay; unsigned long retry_count; unsigned long max_retry_count; -#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG - unsigned long hotplug_pages; - unsigned long balloon_hotplug; -#endif }; extern struct balloon_stats balloon_stats; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 04/10] xen/balloon: find non-conflicting regions to place hotplugged memory Date: Thu, 30 Jul 2015 18:03:06 +0100 Message-ID: <1438275792-5726-5-git-send-email-david.vrabel__37259.5159723007$1438275936$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFk-0002xY-Nk for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:20 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org 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 Reviewed-by: Daniel Kiper --- v3: - Remove stale comment. --- drivers/xen/balloon.c | 73 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index fd93369..7ecbbc5 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -208,26 +209,56 @@ static bool balloon_is_inflated(void) return false; } -/* - * reserve_additional_memory() adds memory region of size >= credit above - * max_pfn. New region is section aligned and size is modified to be multiple - * of section size. Those features allow optimal use of address space and - * establish proper alignment when this function is called first time after - * boot (last section not fully populated at boot time contains unused memory - * pages with PG_reserved bit not set; online_pages_range() does not allow page - * onlining in whole range if first onlined page does not have PG_reserved - * bit set). Real size of added memory is established at page onlining stage. - */ +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); +} 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 +273,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 +295,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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 03/10] x86/xen: discard RAM regions above the maximum reservation Date: Thu, 30 Jul 2015 18:03:05 +0100 Message-ID: <1438275792-5726-4-git-send-email-david.vrabel__48458.3597899929$1438275937$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFs-00032q-4G for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:28 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org During setup, discard RAM regions that are above the maximum reservation (instead of marking them as E820_UNUSABLE). This allows hotplug memory to be placed at these addresses. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- arch/x86/xen/setup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 55f388e..32910c5 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -646,6 +646,7 @@ char * __init xen_memory_setup(void) phys_addr_t addr = map[i].addr; phys_addr_t size = map[i].size; u32 type = map[i].type; + bool discard = false; if (type == E820_RAM) { if (addr < mem_end) { @@ -656,10 +657,11 @@ char * __init xen_memory_setup(void) xen_add_extra_mem(addr, size); xen_max_p2m_pfn = PFN_DOWN(addr + size); } else - type = E820_UNUSABLE; + discard = true; } - xen_align_and_add_e820_region(addr, size, type); + if (!discard) + xen_align_and_add_e820_region(addr, size, type); map[i].addr += size; map[i].size -= size; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 06/10] xen/balloon: only hotplug additional memory if required Date: Thu, 30 Jul 2015 18:03:08 +0100 Message-ID: <1438275792-5726-7-git-send-email-david.vrabel__7687.69802894003$1438275939$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFo-0002yl-5s for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:24 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org Now that we track the total number of pages (included hotplugged regions), it is easy to determine if more memory needs to be hotplugged. Add a new BP_WAIT state to signal that the balloon process needs to wait until kicked by the memory add notifier (when the new section is onlined by userspace). Signed-off-by: David Vrabel --- v3: - Return BP_WAIT if enough sections are already hotplugged. v2: - New BP_WAIT status after adding new memory sections. --- drivers/xen/balloon.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 932d232..e8b45e8 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -75,12 +75,14 @@ * balloon_process() state: * * BP_DONE: done or nothing to do, + * BP_WAIT: wait to be rescheduled, * BP_EAGAIN: error, go to sleep, * BP_ECANCELED: error, balloon operation canceled. */ enum bp_state { BP_DONE, + BP_WAIT, BP_EAGAIN, BP_ECANCELED }; @@ -167,6 +169,9 @@ static struct page *balloon_next_page(struct page *page) static enum bp_state update_schedule(enum bp_state state) { + if (state == BP_WAIT) + return BP_WAIT; + if (state == BP_ECANCELED) return BP_ECANCELED; @@ -231,12 +236,22 @@ static void release_memory_resource(struct resource *resource) kfree(resource); } -static enum bp_state reserve_additional_memory(long credit) +static enum bp_state reserve_additional_memory(void) { + long credit; struct resource *resource; int nid, rc; unsigned long balloon_hotplug; + credit = balloon_stats.target_pages - balloon_stats.total_pages; + + /* + * Already hotplugged enough pages? Wait for them to be + * onlined. + */ + if (credit <= 0) + return BP_WAIT; + balloon_hotplug = round_up(credit, PAGES_PER_SECTION); resource = additional_memory_resource(balloon_hotplug * PAGE_SIZE); @@ -276,7 +291,7 @@ static enum bp_state reserve_additional_memory(long credit) balloon_stats.total_pages += balloon_hotplug; - return BP_DONE; + return BP_WAIT; err: release_memory_resource(resource); return BP_ECANCELED; @@ -306,7 +321,7 @@ static struct notifier_block xen_memory_nb = { .priority = 0 }; #else -static enum bp_state reserve_additional_memory(long credit) +static enum bp_state reserve_additional_memory(void) { balloon_stats.target_pages = balloon_stats.current_pages; return BP_DONE; @@ -473,7 +488,7 @@ static void balloon_process(struct work_struct *work) if (balloon_is_inflated()) state = increase_reservation(credit); else - state = reserve_additional_memory(credit); + state = reserve_additional_memory(); } if (credit < 0) -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 01/10] mm: memory hotplug with an existing resource Date: Thu, 30 Jul 2015 18:03:03 +0100 Message-ID: <1438275792-5726-2-git-send-email-david.vrabel__27452.6128232994$1438275942$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFl-0002xe-Hr for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:21 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Daniel Kiper , linux-mm@kvack.org, David Vrabel , Boris Ostrovsky , Andrew Morton List-Id: xen-devel@lists.xenproject.org Add add_memory_resource() to add memory using an existing "System RAM" resource. This is useful if the memory region is being located by finding a free resource slot with allocate_resource(). Xen guests will make use of this in their balloon driver to hotplug arbitrary amounts of memory in response to toolstack requests. Signed-off-by: David Vrabel Cc: Andrew Morton --- include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 6ffa0ac..c76d371 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -11,6 +11,7 @@ struct zone; struct pglist_data; struct mem_section; struct memory_block; +struct resource; #ifdef CONFIG_MEMORY_HOTPLUG @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); extern int add_memory(int nid, u64 start, u64 size); +extern int add_memory_resource(int nid, struct resource *resource); extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); extern int arch_add_memory(int nid, u64 start, u64 size); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 003dbe4..169770a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) } /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int __ref add_memory(int nid, u64 start, u64 size) +int __ref add_memory_resource(int nid, struct resource *res) { + u64 start, size; pg_data_t *pgdat = NULL; bool new_pgdat; bool new_node; - struct resource *res; int ret; + start = res->start; + size = resource_size(res); + ret = check_hotplug_memory_range(start, size); if (ret) return ret; - res = register_memory_resource(start, size); - ret = -EEXIST; - if (!res) - return ret; - { /* Stupid hack to suppress address-never-null warning */ void *p = NODE_DATA(nid); new_pgdat = !p; @@ -1290,6 +1288,22 @@ out: mem_hotplug_done(); return ret; } +EXPORT_SYMBOL_GPL(add_memory_resource); + +int __ref add_memory(int nid, u64 start, u64 size) +{ + struct resource *res; + int ret; + + res = register_memory_resource(start, size); + if (!res) + return -EEXIST; + + ret = add_memory_resource(nid, res); + if (ret < 0) + release_memory_resource(res); + return ret; +} EXPORT_SYMBOL_GPL(add_memory); #ifdef CONFIG_MEMORY_HOTREMOVE -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 02/10] xen/balloon: remove scratch page left overs Date: Thu, 30 Jul 2015 18:03:04 +0100 Message-ID: <1438275792-5726-3-git-send-email-david.vrabel__1006.1732413762$1438275942$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFo-0002z1-Q9 for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:24 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org Commit 0bb599fd30108883b00c7d4a226eeb49111e6932 (xen: remove scratch frames for ballooned pages and m2p override) removed the use of the scratch page for ballooned out pages. Remove some left over function definitions. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- include/xen/balloon.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/xen/balloon.h b/include/xen/balloon.h index a4c1c6a..cc2e1a7 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -29,9 +29,6 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem); void free_xenballooned_pages(int nr_pages, struct page **pages); -struct page *get_balloon_scratch_page(void); -void put_balloon_scratch_page(void); - struct device; #ifdef CONFIG_XEN_SELFBALLOONING extern int register_xen_selfballooning(struct device *dev); -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 08/10] xen/balloon: use hotplugged pages for foreign mappings etc. Date: Thu, 30 Jul 2015 18:03:10 +0100 Message-ID: <1438275792-5726-9-git-send-email-david.vrabel__31399.8329140761$1438275949$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFm-0002xv-5a for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:22 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org alloc_xenballooned_pages() is used to get ballooned pages to back foreign mappings etc. Instead of having to balloon out real pages, use (if supported) hotplugged memory. This makes more memory available to the guest and reduces fragmentation in the p2m. This is only enabled if the xen.balloon.hotplug_unpopulated sysctl is set to 1. This sysctl defaults to 0 in case the udev rules to automatically online hotplugged memory do not exist. Signed-off-by: David Vrabel --- v3: - Add xen.balloon.hotplug_unpopulated sysctl to enable use of hotplug for unpopulated pages. --- drivers/xen/balloon.c | 87 +++++++++++++++++++++++++++++++++++++++++++++------ include/xen/balloon.h | 1 + 2 files changed, 79 insertions(+), 9 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 2a01da7..3094f38f 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,46 @@ #include #include +static int xen_hotplug_unpopulated; + +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG + +static int zero; +static int one = 1; + +static struct ctl_table balloon_table[] = { + { + .procname = "hotplug_unpopulated", + .data = &xen_hotplug_unpopulated, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + { } +}; + +static struct ctl_table balloon_root[] = { + { + .procname = "balloon", + .mode = 0555, + .child = balloon_table, + }, + { } +}; + +static struct ctl_table xen_root[] = { + { + .procname = "xen", + .mode = 0555, + .child = balloon_root, + }, + { } +}; + +#endif + /* * balloon_process() state: * @@ -99,6 +140,7 @@ static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)]; /* List of ballooned pages, threaded through the mem_map array. */ static LIST_HEAD(ballooned_pages); +static DECLARE_WAIT_QUEUE_HEAD(balloon_wq); /* Main work function, always executed in process context. */ static void balloon_process(struct work_struct *work); @@ -127,6 +169,7 @@ static void __balloon_append(struct page *page) list_add(&page->lru, &ballooned_pages); balloon_stats.balloon_low++; } + wake_up(&balloon_wq); } static void balloon_append(struct page *page) @@ -242,7 +285,8 @@ static enum bp_state reserve_additional_memory(void) int nid, rc; unsigned long balloon_hotplug; - credit = balloon_stats.target_pages - balloon_stats.total_pages; + credit = balloon_stats.target_pages + balloon_stats.target_unpopulated + - balloon_stats.total_pages; /* * Already hotplugged enough pages? Wait for them to be @@ -323,7 +367,7 @@ static struct notifier_block xen_memory_nb = { static enum bp_state reserve_additional_memory(void) { balloon_stats.target_pages = balloon_stats.current_pages; - return BP_DONE; + return BP_ECANCELED; } #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ @@ -517,6 +561,28 @@ void balloon_set_new_target(unsigned long target) } EXPORT_SYMBOL_GPL(balloon_set_new_target); +static int add_ballooned_pages(int nr_pages) +{ + enum bp_state st; + + if (xen_hotplug_unpopulated) { + st = reserve_additional_memory(); + if (st != BP_ECANCELED) { + mutex_unlock(&balloon_mutex); + wait_event(balloon_wq, + !list_empty(&ballooned_pages)); + mutex_lock(&balloon_mutex); + return 0; + } + } + + st = decrease_reservation(nr_pages, GFP_USER); + if (st != BP_DONE) + return -ENOMEM; + + return 0; +} + /** * alloc_xenballooned_pages - get pages that have been ballooned out * @nr_pages: Number of pages to get @@ -527,26 +593,26 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; + mutex_lock(&balloon_mutex); + + balloon_stats.target_unpopulated += nr_pages; + while (pgno < nr_pages) { page = balloon_retrieve(true); if (page) { pages[pgno++] = page; } else { - enum bp_state st; - st = decrease_reservation(nr_pages - pgno, GFP_USER); - if (st != BP_DONE) + ret = add_ballooned_pages(nr_pages - pgno); + if (ret < 0) goto out_undo; } } mutex_unlock(&balloon_mutex); return 0; out_undo: - while (pgno) - balloon_append(pages[--pgno]); - /* Free the memory back to the kernel soon */ - schedule_delayed_work(&balloon_worker, 0); mutex_unlock(&balloon_mutex); + free_xenballooned_pages(pgno, pages); return -ENOMEM; } EXPORT_SYMBOL(alloc_xenballooned_pages); @@ -567,6 +633,8 @@ void free_xenballooned_pages(int nr_pages, struct page **pages) balloon_append(pages[i]); } + balloon_stats.target_unpopulated -= nr_pages; + /* The balloon may be too large now. Shrink it if needed. */ if (current_credit()) schedule_delayed_work(&balloon_worker, 0); @@ -624,6 +692,7 @@ static int __init balloon_init(void) #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG set_online_page_callback(&xen_online_page); register_memory_notifier(&xen_memory_nb); + register_sysctl_table(xen_root); #endif /* diff --git a/include/xen/balloon.h b/include/xen/balloon.h index 83efdeb..d1767df 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -8,6 +8,7 @@ struct balloon_stats { /* We aim for 'current allocation' == 'target allocation'. */ unsigned long current_pages; unsigned long target_pages; + unsigned long target_unpopulated; /* Number of pages in high- and low-memory balloons. */ unsigned long balloon_low; unsigned long balloon_high; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 07/10] xen/balloon: make alloc_xenballoon_pages() always allocate low pages Date: Thu, 30 Jul 2015 18:03:09 +0100 Message-ID: <1438275792-5726-8-git-send-email-david.vrabel__40584.4423607506$1438275950$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFu-000352-21 for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:30 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org All users of alloc_xenballoon_pages() wanted low memory pages, so remove the option for high memory. Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper --- arch/x86/xen/grant-table.c | 2 +- drivers/xen/balloon.c | 21 ++++++++------------- drivers/xen/grant-table.c | 2 +- drivers/xen/privcmd.c | 2 +- drivers/xen/xenbus/xenbus_client.c | 3 +-- include/xen/balloon.h | 3 +-- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c index 1580e7a..e079500 100644 --- a/arch/x86/xen/grant-table.c +++ b/arch/x86/xen/grant-table.c @@ -133,7 +133,7 @@ static int __init xlated_setup_gnttab_pages(void) kfree(pages); return -ENOMEM; } - rc = alloc_xenballooned_pages(nr_grant_frames, pages, 0 /* lowmem */); + rc = alloc_xenballooned_pages(nr_grant_frames, pages); if (rc) { pr_warn("%s Couldn't balloon alloc %ld pfns rc:%d\n", __func__, nr_grant_frames, rc); diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index e8b45e8..2a01da7 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -136,17 +136,16 @@ static void balloon_append(struct page *page) } /* balloon_retrieve: rescue a page from the balloon, if it is not empty. */ -static struct page *balloon_retrieve(bool prefer_highmem) +static struct page *balloon_retrieve(bool require_lowmem) { struct page *page; if (list_empty(&ballooned_pages)) return NULL; - if (prefer_highmem) - page = list_entry(ballooned_pages.prev, struct page, lru); - else - page = list_entry(ballooned_pages.next, struct page, lru); + page = list_entry(ballooned_pages.next, struct page, lru); + if (require_lowmem && PageHighMem(page)) + return NULL; list_del(&page->lru); if (PageHighMem(page)) @@ -522,24 +521,20 @@ EXPORT_SYMBOL_GPL(balloon_set_new_target); * alloc_xenballooned_pages - get pages that have been ballooned out * @nr_pages: Number of pages to get * @pages: pages returned - * @highmem: allow highmem pages * @return 0 on success, error otherwise */ -int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem) +int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; mutex_lock(&balloon_mutex); while (pgno < nr_pages) { - page = balloon_retrieve(highmem); - if (page && (highmem || !PageHighMem(page))) { + page = balloon_retrieve(true); + if (page) { pages[pgno++] = page; } else { enum bp_state st; - if (page) - balloon_append(page); - st = decrease_reservation(nr_pages - pgno, - highmem ? GFP_HIGHUSER : GFP_USER); + st = decrease_reservation(nr_pages - pgno, GFP_USER); if (st != BP_DONE) goto out_undo; } diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 62f591f..a4b702c 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -687,7 +687,7 @@ int gnttab_alloc_pages(int nr_pages, struct page **pages) int i; int ret; - ret = alloc_xenballooned_pages(nr_pages, pages, false); + ret = alloc_xenballooned_pages(nr_pages, pages); if (ret < 0) return ret; diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 5a29616..59cfec9 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -401,7 +401,7 @@ static int alloc_empty_pages(struct vm_area_struct *vma, int numpgs) if (pages == NULL) return -ENOMEM; - rc = alloc_xenballooned_pages(numpgs, pages, 0); + rc = alloc_xenballooned_pages(numpgs, pages); if (rc != 0) { pr_warn("%s Could not alloc %d pfns rc:%d\n", __func__, numpgs, rc); diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 9ad3272..2a2da04 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -614,8 +614,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, if (!node) return -ENOMEM; - err = alloc_xenballooned_pages(nr_grefs, node->hvm.pages, - false /* lowmem */); + err = alloc_xenballooned_pages(nr_grefs, node->hvm.pages); if (err) goto out_err; diff --git a/include/xen/balloon.h b/include/xen/balloon.h index c8aee7a..83efdeb 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -22,8 +22,7 @@ extern struct balloon_stats balloon_stats; void balloon_set_new_target(unsigned long target); -int alloc_xenballooned_pages(int nr_pages, struct page **pages, - bool highmem); +int alloc_xenballooned_pages(int nr_pages, struct page **pages); void free_xenballooned_pages(int nr_pages, struct page **pages); struct device; -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 09/10] x86/xen: export xen_alloc_p2m_entry() Date: Thu, 30 Jul 2015 18:03:11 +0100 Message-ID: <1438275792-5726-10-git-send-email-david.vrabel__41885.5350385003$1438275954$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrFq-0002xe-UI for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:04:27 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org Rename alloc_p2m() to xen_alloc_p2m_entry() and export it. This is useful for ensuring that a p2m entry is allocated (i.e., not a shared missing or identity entry) so that subsequent set_phys_to_machine() calls will require no further allocations. Signed-off-by: David Vrabel --- v3: - Make xen_alloc_p2m_entry() a nop on auto-xlate guests. --- arch/x86/include/asm/xen/page.h | 2 ++ arch/x86/xen/p2m.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h index c44a5d5..960b380 100644 --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h @@ -45,6 +45,8 @@ extern unsigned long *xen_p2m_addr; extern unsigned long xen_p2m_size; extern unsigned long xen_max_p2m_pfn; +extern int xen_alloc_p2m_entry(unsigned long pfn); + extern unsigned long get_phys_to_machine(unsigned long pfn); extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn); extern bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn); diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 8b7f18e..0215897 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -503,7 +503,7 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *pte_pg) * the new pages are installed with cmpxchg; if we lose the race then * simply free the page we allocated and use the one that's there. */ -static bool alloc_p2m(unsigned long pfn) +int xen_alloc_p2m_entry(unsigned long pfn) { unsigned topidx, mididx; unsigned long *top_mfn_p, *mid_mfn; @@ -513,6 +513,9 @@ static bool alloc_p2m(unsigned long pfn) unsigned long addr = (unsigned long)(xen_p2m_addr + pfn); unsigned long p2m_pfn; + if (xen_feature(XENFEAT_auto_translated_physmap)) + return 0; + topidx = p2m_top_index(pfn); mididx = p2m_mid_index(pfn); @@ -524,7 +527,7 @@ static bool alloc_p2m(unsigned long pfn) /* PMD level is missing, allocate a new one */ ptep = alloc_p2m_pmd(addr, pte_pg); if (!ptep) - return false; + return -ENOMEM; } if (p2m_top_mfn) { @@ -541,7 +544,7 @@ static bool alloc_p2m(unsigned long pfn) mid_mfn = alloc_p2m_page(); if (!mid_mfn) - return false; + return -ENOMEM; p2m_mid_mfn_init(mid_mfn, p2m_missing); @@ -567,7 +570,7 @@ static bool alloc_p2m(unsigned long pfn) p2m = alloc_p2m_page(); if (!p2m) - return false; + return -ENOMEM; if (p2m_pfn == PFN_DOWN(__pa(p2m_missing))) p2m_init(p2m); @@ -590,8 +593,9 @@ static bool alloc_p2m(unsigned long pfn) free_p2m_page(p2m); } - return true; + return 0; } +EXPORT_SYMBOL(xen_alloc_p2m_entry); unsigned long __init set_phys_range_identity(unsigned long pfn_s, unsigned long pfn_e) @@ -648,7 +652,10 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn) bool set_phys_to_machine(unsigned long pfn, unsigned long mfn) { if (unlikely(!__set_phys_to_machine(pfn, mfn))) { - if (!alloc_p2m(pfn)) + int ret; + + ret = xen_alloc_p2m_entry(pfn); + if (ret < 0) return false; return __set_phys_to_machine(pfn, mfn); -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: [PATCHv3 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages Date: Thu, 30 Jul 2015 18:03:12 +0100 Message-ID: <1438275792-5726-11-git-send-email-david.vrabel__31447.182436432$1438276628$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZKrQl-00051m-QQ for xen-devel@lists.xenproject.org; Thu, 30 Jul 2015 17:15:43 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper , David Vrabel List-Id: xen-devel@lists.xenproject.org Pages returned by alloc_xenballooned_pages() will be used for grant mapping which will call set_phys_to_machine() (in PV guests). Ballooned pages are set as INVALID_P2M_ENTRY in the p2m and thus may be using the (shared) missing tables and a subsequent set_phys_to_machine() will need to allocate new tables. Since the grant mapping may be done from a context that cannot sleep, the p2m entries must already be allocated. Signed-off-by: David Vrabel --- drivers/xen/balloon.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 3094f38f..e040cf4 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -593,6 +593,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) { int pgno = 0; struct page *page; + int ret = -ENOMEM; mutex_lock(&balloon_mutex); @@ -602,6 +603,11 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) page = balloon_retrieve(true); if (page) { pages[pgno++] = page; +#ifdef CONFIG_XEN_HAVE_PVMMU + ret = xen_alloc_p2m_entry(page_to_pfn(page)); + if (ret < 0) + goto out_undo; +#endif } else { ret = add_ballooned_pages(nr_pages - pgno); if (ret < 0) @@ -613,7 +619,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) out_undo: mutex_unlock(&balloon_mutex); free_xenballooned_pages(pgno, pages); - return -ENOMEM; + return ret; } EXPORT_SYMBOL(alloc_xenballooned_pages); -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Kiper Subject: Re: [PATCHv3 01/10] mm: memory hotplug with an existing resource Date: Sat, 1 Aug 2015 01:15:24 +0200 Message-ID: <20150731231524.GA3488__32526.3137267486$1438384648$gmane$org@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZLJWr-0003eT-KH for xen-devel@lists.xenproject.org; Fri, 31 Jul 2015 23:15:53 +0000 Content-Disposition: inline In-Reply-To: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, xen-devel@lists.xenproject.org, Boris Ostrovsky , Andrew Morton List-Id: xen-devel@lists.xenproject.org On Thu, Jul 30, 2015 at 06:03:03PM +0100, David Vrabel wrote: > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. > > Signed-off-by: David Vrabel > Cc: Andrew Morton Hmmm... Why do you remove my Reviewed-by line from this patch? Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Kiper Subject: Re: [PATCHv3 06/10] xen/balloon: only hotplug additional memory if required Date: Sat, 1 Aug 2015 01:18:26 +0200 Message-ID: <20150731231826.GB3488__10471.8159804635$1438384797$gmane$org@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZLJZY-0004F4-Hu for xen-devel@lists.xenproject.org; Fri, 31 Jul 2015 23:18:40 +0000 Content-Disposition: inline In-Reply-To: <1438275792-5726-7-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: xen-devel@lists.xenproject.org, Boris Ostrovsky , linux-kernel@vger.kernel.org, linux-mm@kvack.org List-Id: xen-devel@lists.xenproject.org On Thu, Jul 30, 2015 at 06:03:08PM +0100, David Vrabel wrote: > Now that we track the total number of pages (included hotplugged > regions), it is easy to determine if more memory needs to be > hotplugged. > > Add a new BP_WAIT state to signal that the balloon process needs to > wait until kicked by the memory add notifier (when the new section is > onlined by userspace). > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Kiper Subject: Re: [PATCHv3 08/10] xen/balloon: use hotplugged pages for foreign mappings etc. Date: Sat, 1 Aug 2015 01:20:31 +0200 Message-ID: <20150731232031.GC3488__38311.2027113841$1438384943$gmane$org@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZLJbk-0004Mg-R6 for xen-devel@lists.xenproject.org; Fri, 31 Jul 2015 23:20:56 +0000 Content-Disposition: inline In-Reply-To: <1438275792-5726-9-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: xen-devel@lists.xenproject.org, Boris Ostrovsky , linux-kernel@vger.kernel.org, linux-mm@kvack.org List-Id: xen-devel@lists.xenproject.org On Thu, Jul 30, 2015 at 06:03:10PM +0100, David Vrabel wrote: > alloc_xenballooned_pages() is used to get ballooned pages to back > foreign mappings etc. Instead of having to balloon out real pages, > use (if supported) hotplugged memory. > > This makes more memory available to the guest and reduces > fragmentation in the p2m. > > This is only enabled if the xen.balloon.hotplug_unpopulated sysctl is > set to 1. This sysctl defaults to 0 in case the udev rules to > automatically online hotplugged memory do not exist. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Kiper Subject: Re: [PATCHv3 09/10] x86/xen: export xen_alloc_p2m_entry() Date: Sat, 1 Aug 2015 01:22:08 +0200 Message-ID: <20150731232208.GD3488__38175.3243892037$1438385023$gmane$org@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZLJd8-0004TH-9G for xen-devel@lists.xenproject.org; Fri, 31 Jul 2015 23:22:22 +0000 Content-Disposition: inline In-Reply-To: <1438275792-5726-10-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: xen-devel@lists.xenproject.org, Boris Ostrovsky , linux-kernel@vger.kernel.org, linux-mm@kvack.org List-Id: xen-devel@lists.xenproject.org On Thu, Jul 30, 2015 at 06:03:11PM +0100, David Vrabel wrote: > Rename alloc_p2m() to xen_alloc_p2m_entry() and export it. > > This is useful for ensuring that a p2m entry is allocated (i.e., not a > shared missing or identity entry) so that subsequent set_phys_to_machine() > calls will require no further allocations. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Kiper Subject: Re: [PATCHv3 10/10] xen/balloon: pre-allocate p2m entries for ballooned pages Date: Sat, 1 Aug 2015 01:23:50 +0200 Message-ID: <20150731232350.GE3488__10746.7869682752$1438385117$gmane$org@olila.local.net-space.pl> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZLJek-0004dS-G5 for xen-devel@lists.xenproject.org; Fri, 31 Jul 2015 23:24:02 +0000 Content-Disposition: inline In-Reply-To: <1438275792-5726-11-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: xen-devel@lists.xenproject.org, Boris Ostrovsky , linux-kernel@vger.kernel.org, linux-mm@kvack.org List-Id: xen-devel@lists.xenproject.org On Thu, Jul 30, 2015 at 06:03:12PM +0100, David Vrabel wrote: > Pages returned by alloc_xenballooned_pages() will be used for grant > mapping which will call set_phys_to_machine() (in PV guests). > > Ballooned pages are set as INVALID_P2M_ENTRY in the p2m and thus may > be using the (shared) missing tables and a subsequent > set_phys_to_machine() will need to allocate new tables. > > Since the grant mapping may be done from a context that cannot sleep, > the p2m entries must already be allocated. > > Signed-off-by: David Vrabel Reviewed-by: Daniel Kiper Daniel PS FYI, next week I am on vacation. From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCHv3 01/10] mm: memory hotplug with an existing resource Date: Thu, 13 Aug 2015 11:21:43 +0100 Message-ID: <55CC6FB7.4080600__47139.7466761575$1439461421$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZPpeT-0003Tu-9O for xen-devel@lists.xenproject.org; Thu, 13 Aug 2015 10:22:25 +0000 In-Reply-To: <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Daniel Kiper , Boris Ostrovsky , Andrew Morton List-Id: xen-devel@lists.xenproject.org On 30/07/15 18:03, David Vrabel wrote: > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. Ping? This enables a useful feature for Xen guests. > Signed-off-by: David Vrabel > Cc: Andrew Morton > --- > include/linux/memory_hotplug.h | 2 ++ > mm/memory_hotplug.c | 28 +++++++++++++++++++++------- > 2 files changed, 23 insertions(+), 7 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 6ffa0ac..c76d371 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -11,6 +11,7 @@ struct zone; > struct pglist_data; > struct mem_section; > struct memory_block; > +struct resource; > > #ifdef CONFIG_MEMORY_HOTPLUG > > @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} > extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, > void *arg, int (*func)(struct memory_block *, void *)); > extern int add_memory(int nid, u64 start, u64 size); > +extern int add_memory_resource(int nid, struct resource *resource); > extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); > extern int arch_add_memory(int nid, u64 start, u64 size); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 003dbe4..169770a 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) > } > > /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ > -int __ref add_memory(int nid, u64 start, u64 size) > +int __ref add_memory_resource(int nid, struct resource *res) > { > + u64 start, size; > pg_data_t *pgdat = NULL; > bool new_pgdat; > bool new_node; > - struct resource *res; > int ret; > > + start = res->start; > + size = resource_size(res); > + > ret = check_hotplug_memory_range(start, size); > if (ret) > return ret; > > - res = register_memory_resource(start, size); > - ret = -EEXIST; > - if (!res) > - return ret; > - > { /* Stupid hack to suppress address-never-null warning */ > void *p = NODE_DATA(nid); > new_pgdat = !p; > @@ -1290,6 +1288,22 @@ out: > mem_hotplug_done(); > return ret; > } > +EXPORT_SYMBOL_GPL(add_memory_resource); > + > +int __ref add_memory(int nid, u64 start, u64 size) > +{ > + struct resource *res; > + int ret; > + > + res = register_memory_resource(start, size); > + if (!res) > + return -EEXIST; > + > + ret = add_memory_resource(nid, res); > + if (ret < 0) > + release_memory_resource(res); > + return ret; > +} > EXPORT_SYMBOL_GPL(add_memory); > > #ifdef CONFIG_MEMORY_HOTREMOVE > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: Re: [PATCHv3 01/10] mm: memory hotplug with an existing resource Date: Thu, 13 Aug 2015 13:40:03 -0700 Message-ID: <20150813134003.895cd1ce421631fb55db21fb__45544.6300482892$1439498510$gmane$org@linux-foundation.org> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> <55CC6FB7.4080600@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZPzIG-00026V-6R for xen-devel@lists.xenproject.org; Thu, 13 Aug 2015 20:40:08 +0000 In-Reply-To: <55CC6FB7.4080600@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: Daniel Kiper , linux-kernel@vger.kernel.org, Tang Chen , linux-mm@kvack.org, Yasuaki Ishimatsu , xen-devel@lists.xenproject.org, Boris Ostrovsky List-Id: xen-devel@lists.xenproject.org On Thu, 13 Aug 2015 11:21:43 +0100 David Vrabel wrote: > On 30/07/15 18:03, David Vrabel wrote: > > Add add_memory_resource() to add memory using an existing "System RAM" > > resource. This is useful if the memory region is being located by > > finding a free resource slot with allocate_resource(). > > > > Xen guests will make use of this in their balloon driver to hotplug > > arbitrary amounts of memory in response to toolstack requests. > > Ping? This enables a useful feature for Xen guests. > Looks OK to me. I've cc'ed some memory_hotplug.c developers. If they're OK with it, please add the patch to the (Xen?) tree which uses it. Add add_memory_resource() to add memory using an existing "System RAM" resource. This is useful if the memory region is being located by finding a free resource slot with allocate_resource(). Xen guests will make use of this in their balloon driver to hotplug arbitrary amounts of memory in response to toolstack requests. Signed-off-by: David Vrabel Cc: Andrew Morton --- include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 6ffa0ac..c76d371 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -11,6 +11,7 @@ struct zone; struct pglist_data; struct mem_section; struct memory_block; +struct resource; #ifdef CONFIG_MEMORY_HOTPLUG @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); extern int add_memory(int nid, u64 start, u64 size); +extern int add_memory_resource(int nid, struct resource *resource); extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); extern int arch_add_memory(int nid, u64 start, u64 size); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 003dbe4..169770a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) } /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int __ref add_memory(int nid, u64 start, u64 size) +int __ref add_memory_resource(int nid, struct resource *res) { + u64 start, size; pg_data_t *pgdat = NULL; bool new_pgdat; bool new_node; - struct resource *res; int ret; + start = res->start; + size = resource_size(res); + ret = check_hotplug_memory_range(start, size); if (ret) return ret; - res = register_memory_resource(start, size); - ret = -EEXIST; - if (!res) - return ret; - { /* Stupid hack to suppress address-never-null warning */ void *p = NODE_DATA(nid); new_pgdat = !p; @@ -1290,6 +1288,22 @@ out: mem_hotplug_done(); return ret; } +EXPORT_SYMBOL_GPL(add_memory_resource); + +int __ref add_memory(int nid, u64 start, u64 size) +{ + struct resource *res; + int ret; + + res = register_memory_resource(start, size); + if (!res) + return -EEXIST; + + ret = add_memory_resource(nid, res); + if (ret < 0) + release_memory_resource(res); + return ret; +} EXPORT_SYMBOL_GPL(add_memory); #ifdef CONFIG_MEMORY_HOTREMOVE -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tang Chen Subject: Re: [PATCHv3 01/10] mm: memory hotplug with an existing resource Date: Sun, 16 Aug 2015 19:41:09 +0800 Message-ID: <55D076D5.8070601__24099.5877808475$1439791444$gmane$org@cn.fujitsu.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> <1438275792-5726-2-git-send-email-david.vrabel@citrix.com> <55CC6FB7.4080600@citrix.com> <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZQwKs-0002je-JB for xen-devel@lists.xenproject.org; Sun, 16 Aug 2015 11:42:46 +0000 In-Reply-To: <20150813134003.895cd1ce421631fb55db21fb@linux-foundation.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Morton , David Vrabel Cc: Daniel Kiper , linux-kernel@vger.kernel.org, tangchen@cn.fujitsu.com, linux-mm@kvack.org, Yasuaki Ishimatsu , xen-devel@lists.xenproject.org, Boris Ostrovsky List-Id: xen-devel@lists.xenproject.org On 08/14/2015 04:40 AM, Andrew Morton wrote: > On Thu, 13 Aug 2015 11:21:43 +0100 David Vrabel wrote: > >> On 30/07/15 18:03, David Vrabel wrote: >>> Add add_memory_resource() to add memory using an existing "System RAM" >>> resource. This is useful if the memory region is being located by >>> finding a free resource slot with allocate_resource(). >>> >>> Xen guests will make use of this in their balloon driver to hotplug >>> arbitrary amounts of memory in response to toolstack requests. >> Ping? This enables a useful feature for Xen guests. >> > Looks OK to me. I've cc'ed some memory_hotplug.c developers. If > they're OK with it, please add the patch to the (Xen?) tree which uses > it. > > > > > Add add_memory_resource() to add memory using an existing "System RAM" > resource. This is useful if the memory region is being located by > finding a free resource slot with allocate_resource(). > > Xen guests will make use of this in their balloon driver to hotplug > arbitrary amounts of memory in response to toolstack requests. > > Signed-off-by: David Vrabel > Cc: Andrew Morton > --- > include/linux/memory_hotplug.h | 2 ++ > mm/memory_hotplug.c | 28 +++++++++++++++++++++------- > 2 files changed, 23 insertions(+), 7 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 6ffa0ac..c76d371 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -11,6 +11,7 @@ struct zone; > struct pglist_data; > struct mem_section; > struct memory_block; > +struct resource; > > #ifdef CONFIG_MEMORY_HOTPLUG > > @@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} > extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, > void *arg, int (*func)(struct memory_block *, void *)); > extern int add_memory(int nid, u64 start, u64 size); > +extern int add_memory_resource(int nid, struct resource *resource); > extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); > extern int arch_add_memory(int nid, u64 start, u64 size); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 003dbe4..169770a 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1224,23 +1224,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default) > } > > /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ > -int __ref add_memory(int nid, u64 start, u64 size) > +int __ref add_memory_resource(int nid, struct resource *res) > { > + u64 start, size; > pg_data_t *pgdat = NULL; > bool new_pgdat; > bool new_node; > - struct resource *res; > int ret; > > + start = res->start; > + size = resource_size(res); > + > ret = check_hotplug_memory_range(start, size); > if (ret) > return ret; > > - res = register_memory_resource(start, size); > - ret = -EEXIST; > - if (!res) > - return ret; > - > { /* Stupid hack to suppress address-never-null warning */ > void *p = NODE_DATA(nid); > new_pgdat = !p; > @@ -1290,6 +1288,22 @@ out: > mem_hotplug_done(); > return ret; > } > +EXPORT_SYMBOL_GPL(add_memory_resource); > + > +int __ref add_memory(int nid, u64 start, u64 size) > +{ > + struct resource *res; > + int ret; > + > + res = register_memory_resource(start, size); > + if (!res) > + return -EEXIST; > + > + ret = add_memory_resource(nid, res); > + if (ret < 0) Not a big deal, but I think "if (ret)" is enough. The code looks good. Reviewed-by: Tang Chen Thanks. > + release_memory_resource(res); > + return ret; > +} > EXPORT_SYMBOL_GPL(add_memory); > > #ifdef CONFIG_MEMORY_HOTREMOVE From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCHv3 00/10] mm, xen/balloon: memory hotplug improvements Date: Tue, 29 Sep 2015 17:24:55 +0100 Message-ID: <560ABB57.6080607__17210.3662895553$1443543982$gmane$org@citrix.com> References: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Zgxi8-0004t6-UU for xen-devel@lists.xenproject.org; Tue, 29 Sep 2015 16:25:01 +0000 In-Reply-To: <1438275792-5726-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: linux-mm@kvack.org, Boris Ostrovsky , Daniel Kiper List-Id: xen-devel@lists.xenproject.org On 30/07/15 18:03, David Vrabel wrote: > The series improves the use of hotplug memory in the Xen balloon > driver. > > - Reliably find a non-conflicting location for the hotplugged memory > (this fixes memory hotplug in a number of cases, particularly in > dom0). > > - Use hotplugged memory for alloc_xenballooned_pages() (keeping more > memory available for the domain and reducing fragmentation of the > p2m). Applied to for-linus-4.4. David