memory_hotplug.c (245f0db0de926601353776085e6f6a4c974c5615) memory_hotplug.c (31bc3858ea3ebcc3157b3f5f0e624c5962f5a7a6)
1/*
2 * linux/mm/memory_hotplug.c
3 *
4 * Copyright (C)
5 */
6
7#include <linux/stddef.h>
8#include <linux/mm.h>

--- 63 unchanged lines hidden (view full) ---

72#endif
73};
74
75/* Lockdep annotations for get/put_online_mems() and mem_hotplug_begin/end() */
76#define memhp_lock_acquire_read() lock_map_acquire_read(&mem_hotplug.dep_map)
77#define memhp_lock_acquire() lock_map_acquire(&mem_hotplug.dep_map)
78#define memhp_lock_release() lock_map_release(&mem_hotplug.dep_map)
79
1/*
2 * linux/mm/memory_hotplug.c
3 *
4 * Copyright (C)
5 */
6
7#include <linux/stddef.h>
8#include <linux/mm.h>

--- 63 unchanged lines hidden (view full) ---

72#endif
73};
74
75/* Lockdep annotations for get/put_online_mems() and mem_hotplug_begin/end() */
76#define memhp_lock_acquire_read() lock_map_acquire_read(&mem_hotplug.dep_map)
77#define memhp_lock_acquire() lock_map_acquire(&mem_hotplug.dep_map)
78#define memhp_lock_release() lock_map_release(&mem_hotplug.dep_map)
79
80bool memhp_auto_online;
81EXPORT_SYMBOL_GPL(memhp_auto_online);
82
80void get_online_mems(void)
81{
82 might_sleep();
83 if (mem_hotplug.active_writer == current)
84 return;
85 memhp_lock_acquire_read();
86 mutex_lock(&mem_hotplug.lock);
87 mem_hotplug.refcount++;

--- 45 unchanged lines hidden (view full) ---

133 struct resource *res;
134 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
135 if (!res)
136 return ERR_PTR(-ENOMEM);
137
138 res->name = "System RAM";
139 res->start = start;
140 res->end = start + size - 1;
83void get_online_mems(void)
84{
85 might_sleep();
86 if (mem_hotplug.active_writer == current)
87 return;
88 memhp_lock_acquire_read();
89 mutex_lock(&mem_hotplug.lock);
90 mem_hotplug.refcount++;

--- 45 unchanged lines hidden (view full) ---

136 struct resource *res;
137 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
138 if (!res)
139 return ERR_PTR(-ENOMEM);
140
141 res->name = "System RAM";
142 res->start = start;
143 res->end = start + size - 1;
141 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
144 res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
142 if (request_resource(&iomem_resource, res) < 0) {
143 pr_debug("System RAM resource %pR cannot be added\n", res);
144 kfree(res);
145 return ERR_PTR(-EEXIST);
146 }
147 return res;
148}
149

--- 1106 unchanged lines hidden (view full) ---

1256 return ZONE_DEVICE;
1257#endif
1258 if (should_add_memory_movable(nid, start, size))
1259 return ZONE_MOVABLE;
1260
1261 return zone_default;
1262}
1263
145 if (request_resource(&iomem_resource, res) < 0) {
146 pr_debug("System RAM resource %pR cannot be added\n", res);
147 kfree(res);
148 return ERR_PTR(-EEXIST);
149 }
150 return res;
151}
152

--- 1106 unchanged lines hidden (view full) ---

1259 return ZONE_DEVICE;
1260#endif
1261 if (should_add_memory_movable(nid, start, size))
1262 return ZONE_MOVABLE;
1263
1264 return zone_default;
1265}
1266
1267static int online_memory_block(struct memory_block *mem, void *arg)
1268{
1269 return memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
1270}
1271
1264/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
1272/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
1265int __ref add_memory_resource(int nid, struct resource *res)
1273int __ref add_memory_resource(int nid, struct resource *res, bool online)
1266{
1267 u64 start, size;
1268 pg_data_t *pgdat = NULL;
1269 bool new_pgdat;
1270 bool new_node;
1271 int ret;
1272
1273 start = res->start;

--- 43 unchanged lines hidden (view full) ---

1317 * So, check by BUG_ON() to catch it reluctantly..
1318 */
1319 BUG_ON(ret);
1320 }
1321
1322 /* create new memmap entry */
1323 firmware_map_add_hotplug(start, start + size, "System RAM");
1324
1274{
1275 u64 start, size;
1276 pg_data_t *pgdat = NULL;
1277 bool new_pgdat;
1278 bool new_node;
1279 int ret;
1280
1281 start = res->start;

--- 43 unchanged lines hidden (view full) ---

1325 * So, check by BUG_ON() to catch it reluctantly..
1326 */
1327 BUG_ON(ret);
1328 }
1329
1330 /* create new memmap entry */
1331 firmware_map_add_hotplug(start, start + size, "System RAM");
1332
1333 /* online pages if requested */
1334 if (online)
1335 walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1),
1336 NULL, online_memory_block);
1337
1325 goto out;
1326
1327error:
1328 /* rollback pgdat allocation and others */
1329 if (new_pgdat)
1330 rollback_node_hotadd(nid, pgdat);
1331 memblock_remove(start, size);
1332

--- 7 unchanged lines hidden (view full) ---

1340{
1341 struct resource *res;
1342 int ret;
1343
1344 res = register_memory_resource(start, size);
1345 if (IS_ERR(res))
1346 return PTR_ERR(res);
1347
1338 goto out;
1339
1340error:
1341 /* rollback pgdat allocation and others */
1342 if (new_pgdat)
1343 rollback_node_hotadd(nid, pgdat);
1344 memblock_remove(start, size);
1345

--- 7 unchanged lines hidden (view full) ---

1353{
1354 struct resource *res;
1355 int ret;
1356
1357 res = register_memory_resource(start, size);
1358 if (IS_ERR(res))
1359 return PTR_ERR(res);
1360
1348 ret = add_memory_resource(nid, res);
1361 ret = add_memory_resource(nid, res, memhp_auto_online);
1349 if (ret < 0)
1350 release_memory_resource(res);
1351 return ret;
1352}
1353EXPORT_SYMBOL_GPL(add_memory);
1354
1355#ifdef CONFIG_MEMORY_HOTREMOVE
1356/*

--- 737 unchanged lines hidden ---
1362 if (ret < 0)
1363 release_memory_resource(res);
1364 return ret;
1365}
1366EXPORT_SYMBOL_GPL(add_memory);
1367
1368#ifdef CONFIG_MEMORY_HOTREMOVE
1369/*

--- 737 unchanged lines hidden ---