Skip to content

Commit 62cedb9

Browse files
author
David Vrabel
committed
mm: memory hotplug with an existing resource
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 <[email protected]> Reviewed-by: Daniel Kiper <[email protected]> Reviewed-by: Tang Chen <[email protected]>
1 parent 7379047 commit 62cedb9

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

include/linux/memory_hotplug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct zone;
1111
struct pglist_data;
1212
struct mem_section;
1313
struct memory_block;
14+
struct resource;
1415

1516
#ifdef CONFIG_MEMORY_HOTPLUG
1617

@@ -266,6 +267,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {}
266267
extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
267268
void *arg, int (*func)(struct memory_block *, void *));
268269
extern int add_memory(int nid, u64 start, u64 size);
270+
extern int add_memory_resource(int nid, struct resource *resource);
269271
extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default,
270272
bool for_device);
271273
extern int arch_add_memory(int nid, u64 start, u64 size, bool for_device);

mm/memory_hotplug.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,23 +1232,21 @@ int zone_for_memory(int nid, u64 start, u64 size, int zone_default,
12321232
}
12331233

12341234
/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
1235-
int __ref add_memory(int nid, u64 start, u64 size)
1235+
int __ref add_memory_resource(int nid, struct resource *res)
12361236
{
1237+
u64 start, size;
12371238
pg_data_t *pgdat = NULL;
12381239
bool new_pgdat;
12391240
bool new_node;
1240-
struct resource *res;
12411241
int ret;
12421242

1243+
start = res->start;
1244+
size = resource_size(res);
1245+
12431246
ret = check_hotplug_memory_range(start, size);
12441247
if (ret)
12451248
return ret;
12461249

1247-
res = register_memory_resource(start, size);
1248-
ret = -EEXIST;
1249-
if (!res)
1250-
return ret;
1251-
12521250
{ /* Stupid hack to suppress address-never-null warning */
12531251
void *p = NODE_DATA(nid);
12541252
new_pgdat = !p;
@@ -1300,13 +1298,28 @@ int __ref add_memory(int nid, u64 start, u64 size)
13001298
/* rollback pgdat allocation and others */
13011299
if (new_pgdat)
13021300
rollback_node_hotadd(nid, pgdat);
1303-
release_memory_resource(res);
13041301
memblock_remove(start, size);
13051302

13061303
out:
13071304
mem_hotplug_done();
13081305
return ret;
13091306
}
1307+
EXPORT_SYMBOL_GPL(add_memory_resource);
1308+
1309+
int __ref add_memory(int nid, u64 start, u64 size)
1310+
{
1311+
struct resource *res;
1312+
int ret;
1313+
1314+
res = register_memory_resource(start, size);
1315+
if (!res)
1316+
return -EEXIST;
1317+
1318+
ret = add_memory_resource(nid, res);
1319+
if (ret < 0)
1320+
release_memory_resource(res);
1321+
return ret;
1322+
}
13101323
EXPORT_SYMBOL_GPL(add_memory);
13111324

13121325
#ifdef CONFIG_MEMORY_HOTREMOVE

0 commit comments

Comments
 (0)