memory_hotplug.c (009f773836513960d3982e80c86e266d25528563) memory_hotplug.c (6f754ba4cfcc044078d4836056ac45404e1b6e85)
1/*
2 * linux/mm/memory_hotplug.c
3 *
4 * Copyright (C)
5 */
6
7#include <linux/stddef.h>
8#include <linux/mm.h>

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

126 memhp_lock_release();
127}
128
129/* add this memory to iomem resource */
130static struct resource *register_memory_resource(u64 start, u64 size)
131{
132 struct resource *res;
133 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
1/*
2 * linux/mm/memory_hotplug.c
3 *
4 * Copyright (C)
5 */
6
7#include <linux/stddef.h>
8#include <linux/mm.h>

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

126 memhp_lock_release();
127}
128
129/* add this memory to iomem resource */
130static struct resource *register_memory_resource(u64 start, u64 size)
131{
132 struct resource *res;
133 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
134 BUG_ON(!res);
134 if (!res)
135 return ERR_PTR(-ENOMEM);
135
136 res->name = "System RAM";
137 res->start = start;
138 res->end = start + size - 1;
139 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
140 if (request_resource(&iomem_resource, res) < 0) {
141 pr_debug("System RAM resource %pR cannot be added\n", res);
142 kfree(res);
136
137 res->name = "System RAM";
138 res->start = start;
139 res->end = start + size - 1;
140 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
141 if (request_resource(&iomem_resource, res) < 0) {
142 pr_debug("System RAM resource %pR cannot be added\n", res);
143 kfree(res);
143 res = NULL;
144 return ERR_PTR(-EEXIST);
144 }
145 return res;
146}
147
148static void release_memory_resource(struct resource *res)
149{
150 if (!res)
151 return;

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

1307EXPORT_SYMBOL_GPL(add_memory_resource);
1308
1309int __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);
145 }
146 return res;
147}
148
149static void release_memory_resource(struct resource *res)
150{
151 if (!res)
152 return;

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

1308EXPORT_SYMBOL_GPL(add_memory_resource);
1309
1310int __ref add_memory(int nid, u64 start, u64 size)
1311{
1312 struct resource *res;
1313 int ret;
1314
1315 res = register_memory_resource(start, size);
1315 if (!res)
1316 return -EEXIST;
1316 if (IS_ERR(res))
1317 return PTR_ERR(res);
1317
1318 ret = add_memory_resource(nid, res);
1319 if (ret < 0)
1320 release_memory_resource(res);
1321 return ret;
1322}
1323EXPORT_SYMBOL_GPL(add_memory);
1324

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

1370 return 1;
1371}
1372
1373/*
1374 * Confirm all pages in a range [start, end) is belongs to the same zone.
1375 */
1376int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn)
1377{
1318
1319 ret = add_memory_resource(nid, res);
1320 if (ret < 0)
1321 release_memory_resource(res);
1322 return ret;
1323}
1324EXPORT_SYMBOL_GPL(add_memory);
1325

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

1371 return 1;
1372}
1373
1374/*
1375 * Confirm all pages in a range [start, end) is belongs to the same zone.
1376 */
1377int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn)
1378{
1378 unsigned long pfn;
1379 unsigned long pfn, sec_end_pfn;
1379 struct zone *zone = NULL;
1380 struct page *page;
1381 int i;
1380 struct zone *zone = NULL;
1381 struct page *page;
1382 int i;
1382 for (pfn = start_pfn;
1383 for (pfn = start_pfn, sec_end_pfn = SECTION_ALIGN_UP(start_pfn);
1383 pfn < end_pfn;
1384 pfn < end_pfn;
1384 pfn += MAX_ORDER_NR_PAGES) {
1385 i = 0;
1386 /* This is just a CONFIG_HOLES_IN_ZONE check.*/
1387 while ((i < MAX_ORDER_NR_PAGES) && !pfn_valid_within(pfn + i))
1388 i++;
1389 if (i == MAX_ORDER_NR_PAGES)
1385 pfn = sec_end_pfn + 1, sec_end_pfn += PAGES_PER_SECTION) {
1386 /* Make sure the memory section is present first */
1387 if (!present_section_nr(pfn_to_section_nr(pfn)))
1390 continue;
1388 continue;
1391 page = pfn_to_page(pfn + i);
1392 if (zone && page_zone(page) != zone)
1393 return 0;
1394 zone = page_zone(page);
1389 for (; pfn < sec_end_pfn && pfn < end_pfn;
1390 pfn += MAX_ORDER_NR_PAGES) {
1391 i = 0;
1392 /* This is just a CONFIG_HOLES_IN_ZONE check.*/
1393 while ((i < MAX_ORDER_NR_PAGES) &&
1394 !pfn_valid_within(pfn + i))
1395 i++;
1396 if (i == MAX_ORDER_NR_PAGES)
1397 continue;
1398 page = pfn_to_page(pfn + i);
1399 if (zone && page_zone(page) != zone)
1400 return 0;
1401 zone = page_zone(page);
1402 }
1395 }
1396 return 1;
1397}
1398
1399/*
1400 * Scan pfn range [start,end) to find movable/migratable pages (LRU pages
1401 * and hugepages). We scan pfn because it's much easier than scanning over
1402 * linked list. This function returns the pfn of the first found movable

--- 654 unchanged lines hidden ---
1403 }
1404 return 1;
1405}
1406
1407/*
1408 * Scan pfn range [start,end) to find movable/migratable pages (LRU pages
1409 * and hugepages). We scan pfn because it's much easier than scanning over
1410 * linked list. This function returns the pfn of the first found movable

--- 654 unchanged lines hidden ---