]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: memory hotplug with an existing resource
authorDavid Vrabel <david.vrabel@citrix.com>
Thu, 25 Jun 2015 15:35:49 +0000 (16:35 +0100)
committerJoao Martins <joao.m.martins@oracle.com>
Sun, 27 Mar 2016 01:00:56 +0000 (02:00 +0100)
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 <david.vrabel@citrix.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Tang Chen <tangchen@cn.fujitsu.com>
Conflicts:
include/linux/memory_hotplug.h
mm/memory_hotplug.c

(cherry picked from commit 62cedb9f135794ec26a93ae29e5f0231ab263c84)
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
include/linux/memory_hotplug.h
mm/memory_hotplug.c

index 6ffa0ac7f7d62a2521ba40d154f4f5248f882afd..4caa65ca3177c99868a77165fd73d212b34fb1f9 100644 (file)
@@ -11,6 +11,7 @@ struct zone;
 struct pglist_data;
 struct mem_section;
 struct memory_block;
+struct resource;
 
 #ifdef CONFIG_MEMORY_HOTPLUG
 
@@ -267,6 +268,7 @@ 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 zone_for_memory(int nid, u64 start, u64 size, int zone_default);
+extern int add_memory_resource(int nid, struct resource *resource);
 extern int arch_add_memory(int nid, u64 start, u64 size);
 extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
 extern bool is_memblock_offlined(struct memory_block *mem);
index 9e88f749aa512395daea45f2727545fa0f281533..74bfdcaeebab45c37ff0c2f454d5a8e3dcdfee90 100644 (file)
@@ -1215,23 +1215,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;
@@ -1275,12 +1273,27 @@ error:
        /* rollback pgdat allocation and others */
        if (new_pgdat)
                rollback_node_hotadd(nid, pgdat);
-       release_memory_resource(res);
 
 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