Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/mm/memory_hotplug.c |
| 3 | * |
| 4 | * Copyright (C) |
| 5 | */ |
| 6 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 7 | #include <linux/stddef.h> |
| 8 | #include <linux/mm.h> |
| 9 | #include <linux/swap.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/pagemap.h> |
| 12 | #include <linux/bootmem.h> |
| 13 | #include <linux/compiler.h> |
Paul Gortmaker | b95f1b31 | 2011-10-16 02:01:52 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 15 | #include <linux/pagevec.h> |
Chandra Seetharaman | 2d1d43f | 2006-09-29 02:01:25 -0700 | [diff] [blame] | 16 | #include <linux/writeback.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 17 | #include <linux/slab.h> |
| 18 | #include <linux/sysctl.h> |
| 19 | #include <linux/cpu.h> |
| 20 | #include <linux/memory.h> |
| 21 | #include <linux/memory_hotplug.h> |
| 22 | #include <linux/highmem.h> |
| 23 | #include <linux/vmalloc.h> |
KAMEZAWA Hiroyuki | 0a54703 | 2006-06-27 02:53:35 -0700 | [diff] [blame] | 24 | #include <linux/ioport.h> |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
| 26 | #include <linux/migrate.h> |
| 27 | #include <linux/page-isolation.h> |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 28 | #include <linux/pfn.h> |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 29 | #include <linux/suspend.h> |
KOSAKI Motohiro | 6d9c285 | 2009-12-14 17:58:11 -0800 | [diff] [blame] | 30 | #include <linux/mm_inline.h> |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 31 | #include <linux/firmware-map.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 32 | |
| 33 | #include <asm/tlbflush.h> |
| 34 | |
Adrian Bunk | 1e5ad9a | 2008-04-28 20:40:08 +0300 | [diff] [blame] | 35 | #include "internal.h" |
| 36 | |
Daniel Kiper | 9d0ad8c | 2011-07-25 17:12:05 -0700 | [diff] [blame] | 37 | /* |
| 38 | * online_page_callback contains pointer to current page onlining function. |
| 39 | * Initially it is generic_online_page(). If it is required it could be |
| 40 | * changed by calling set_online_page_callback() for callback registration |
| 41 | * and restore_online_page_callback() for generic callback restore. |
| 42 | */ |
| 43 | |
| 44 | static void generic_online_page(struct page *page); |
| 45 | |
| 46 | static online_page_callback_t online_page_callback = generic_online_page; |
| 47 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 48 | DEFINE_MUTEX(mem_hotplug_mutex); |
| 49 | |
| 50 | void lock_memory_hotplug(void) |
| 51 | { |
| 52 | mutex_lock(&mem_hotplug_mutex); |
| 53 | |
| 54 | /* for exclusive hibernation if CONFIG_HIBERNATION=y */ |
| 55 | lock_system_sleep(); |
| 56 | } |
| 57 | |
| 58 | void unlock_memory_hotplug(void) |
| 59 | { |
| 60 | unlock_system_sleep(); |
| 61 | mutex_unlock(&mem_hotplug_mutex); |
| 62 | } |
| 63 | |
| 64 | |
Keith Mannthey | 45e0b78 | 2006-09-30 23:27:09 -0700 | [diff] [blame] | 65 | /* add this memory to iomem resource */ |
| 66 | static struct resource *register_memory_resource(u64 start, u64 size) |
| 67 | { |
| 68 | struct resource *res; |
| 69 | res = kzalloc(sizeof(struct resource), GFP_KERNEL); |
| 70 | BUG_ON(!res); |
| 71 | |
| 72 | res->name = "System RAM"; |
| 73 | res->start = start; |
| 74 | res->end = start + size - 1; |
Yasunori Goto | 887c3cb | 2007-11-14 16:59:20 -0800 | [diff] [blame] | 75 | res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
Keith Mannthey | 45e0b78 | 2006-09-30 23:27:09 -0700 | [diff] [blame] | 76 | if (request_resource(&iomem_resource, res) < 0) { |
Bjorn Helgaas | a62e2f4 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 77 | printk("System RAM resource %pR cannot be added\n", res); |
Keith Mannthey | 45e0b78 | 2006-09-30 23:27:09 -0700 | [diff] [blame] | 78 | kfree(res); |
| 79 | res = NULL; |
| 80 | } |
| 81 | return res; |
| 82 | } |
| 83 | |
| 84 | static void release_memory_resource(struct resource *res) |
| 85 | { |
| 86 | if (!res) |
| 87 | return; |
| 88 | release_resource(res); |
| 89 | kfree(res); |
| 90 | return; |
| 91 | } |
| 92 | |
Keith Mannthey | 5394702 | 2006-09-30 23:27:08 -0700 | [diff] [blame] | 93 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 94 | void get_page_bootmem(unsigned long info, struct page *page, |
| 95 | unsigned long type) |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 96 | { |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 97 | page->lru.next = (struct list_head *) type; |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 98 | SetPagePrivate(page); |
| 99 | set_page_private(page, info); |
| 100 | atomic_inc(&page->_count); |
| 101 | } |
| 102 | |
Rakib Mullick | 23ce932 | 2009-12-14 17:59:44 -0800 | [diff] [blame] | 103 | /* reference to __meminit __free_pages_bootmem is valid |
| 104 | * so use __ref to tell modpost not to generate a warning */ |
| 105 | void __ref put_page_bootmem(struct page *page) |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 106 | { |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 107 | unsigned long type; |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 108 | static DEFINE_MUTEX(ppb_lock); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 109 | |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 110 | type = (unsigned long) page->lru.next; |
| 111 | BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE || |
| 112 | type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 113 | |
| 114 | if (atomic_dec_return(&page->_count) == 1) { |
| 115 | ClearPagePrivate(page); |
| 116 | set_page_private(page, 0); |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 117 | INIT_LIST_HEAD(&page->lru); |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * Please refer to comment for __free_pages_bootmem() |
| 121 | * for why we serialize here. |
| 122 | */ |
| 123 | mutex_lock(&ppb_lock); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 124 | __free_pages_bootmem(page, 0); |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 125 | mutex_unlock(&ppb_lock); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | } |
| 129 | |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 130 | #ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE |
| 131 | #ifndef CONFIG_SPARSEMEM_VMEMMAP |
Adrian Bunk | d92bc31 | 2008-07-23 21:28:12 -0700 | [diff] [blame] | 132 | static void register_page_bootmem_info_section(unsigned long start_pfn) |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 133 | { |
| 134 | unsigned long *usemap, mapsize, section_nr, i; |
| 135 | struct mem_section *ms; |
| 136 | struct page *page, *memmap; |
| 137 | |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 138 | section_nr = pfn_to_section_nr(start_pfn); |
| 139 | ms = __nr_to_section(section_nr); |
| 140 | |
| 141 | /* Get section's memmap address */ |
| 142 | memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); |
| 143 | |
| 144 | /* |
| 145 | * Get page for the memmap's phys address |
| 146 | * XXX: need more consideration for sparse_vmemmap... |
| 147 | */ |
| 148 | page = virt_to_page(memmap); |
| 149 | mapsize = sizeof(struct page) * PAGES_PER_SECTION; |
| 150 | mapsize = PAGE_ALIGN(mapsize) >> PAGE_SHIFT; |
| 151 | |
| 152 | /* remember memmap's page */ |
| 153 | for (i = 0; i < mapsize; i++, page++) |
| 154 | get_page_bootmem(section_nr, page, SECTION_INFO); |
| 155 | |
| 156 | usemap = __nr_to_section(section_nr)->pageblock_flags; |
| 157 | page = virt_to_page(usemap); |
| 158 | |
| 159 | mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT; |
| 160 | |
| 161 | for (i = 0; i < mapsize; i++, page++) |
Yasunori Goto | af370fb | 2008-07-23 21:28:17 -0700 | [diff] [blame] | 162 | get_page_bootmem(section_nr, page, MIX_SECTION_INFO); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 163 | |
| 164 | } |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 165 | #else /* CONFIG_SPARSEMEM_VMEMMAP */ |
| 166 | static void register_page_bootmem_info_section(unsigned long start_pfn) |
| 167 | { |
| 168 | unsigned long *usemap, mapsize, section_nr, i; |
| 169 | struct mem_section *ms; |
| 170 | struct page *page, *memmap; |
| 171 | |
| 172 | if (!pfn_valid(start_pfn)) |
| 173 | return; |
| 174 | |
| 175 | section_nr = pfn_to_section_nr(start_pfn); |
| 176 | ms = __nr_to_section(section_nr); |
| 177 | |
| 178 | memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); |
| 179 | |
| 180 | register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION); |
| 181 | |
| 182 | usemap = __nr_to_section(section_nr)->pageblock_flags; |
| 183 | page = virt_to_page(usemap); |
| 184 | |
| 185 | mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT; |
| 186 | |
| 187 | for (i = 0; i < mapsize; i++, page++) |
| 188 | get_page_bootmem(section_nr, page, MIX_SECTION_INFO); |
| 189 | } |
| 190 | #endif /* !CONFIG_SPARSEMEM_VMEMMAP */ |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 191 | |
| 192 | void register_page_bootmem_info_node(struct pglist_data *pgdat) |
| 193 | { |
| 194 | unsigned long i, pfn, end_pfn, nr_pages; |
| 195 | int node = pgdat->node_id; |
| 196 | struct page *page; |
| 197 | struct zone *zone; |
| 198 | |
| 199 | nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT; |
| 200 | page = virt_to_page(pgdat); |
| 201 | |
| 202 | for (i = 0; i < nr_pages; i++, page++) |
| 203 | get_page_bootmem(node, page, NODE_INFO); |
| 204 | |
| 205 | zone = &pgdat->node_zones[0]; |
| 206 | for (; zone < pgdat->node_zones + MAX_NR_ZONES - 1; zone++) { |
| 207 | if (zone->wait_table) { |
| 208 | nr_pages = zone->wait_table_hash_nr_entries |
| 209 | * sizeof(wait_queue_head_t); |
| 210 | nr_pages = PAGE_ALIGN(nr_pages) >> PAGE_SHIFT; |
| 211 | page = virt_to_page(zone->wait_table); |
| 212 | |
| 213 | for (i = 0; i < nr_pages; i++, page++) |
| 214 | get_page_bootmem(node, page, NODE_INFO); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | pfn = pgdat->node_start_pfn; |
| 219 | end_pfn = pfn + pgdat->node_spanned_pages; |
| 220 | |
| 221 | /* register_section info */ |
qiuxishi | f14851a | 2012-09-17 14:09:24 -0700 | [diff] [blame] | 222 | for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { |
| 223 | /* |
| 224 | * Some platforms can assign the same pfn to multiple nodes - on |
| 225 | * node0 as well as nodeN. To avoid registering a pfn against |
| 226 | * multiple nodes we check that this pfn does not already |
| 227 | * reside in some other node. |
| 228 | */ |
| 229 | if (pfn_valid(pfn) && (pfn_to_nid(pfn) == node)) |
| 230 | register_page_bootmem_info_section(pfn); |
| 231 | } |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 232 | } |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 233 | #endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */ |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 234 | |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 235 | static void grow_zone_span(struct zone *zone, unsigned long start_pfn, |
| 236 | unsigned long end_pfn) |
| 237 | { |
| 238 | unsigned long old_zone_end_pfn; |
| 239 | |
| 240 | zone_span_writelock(zone); |
| 241 | |
| 242 | old_zone_end_pfn = zone->zone_start_pfn + zone->spanned_pages; |
Tang Chen | 712cd38 | 2012-12-11 16:01:07 -0800 | [diff] [blame] | 243 | if (!zone->spanned_pages || start_pfn < zone->zone_start_pfn) |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 244 | zone->zone_start_pfn = start_pfn; |
| 245 | |
| 246 | zone->spanned_pages = max(old_zone_end_pfn, end_pfn) - |
| 247 | zone->zone_start_pfn; |
| 248 | |
| 249 | zone_span_writeunlock(zone); |
| 250 | } |
| 251 | |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 252 | static void resize_zone(struct zone *zone, unsigned long start_pfn, |
| 253 | unsigned long end_pfn) |
| 254 | { |
| 255 | zone_span_writelock(zone); |
| 256 | |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 257 | if (end_pfn - start_pfn) { |
| 258 | zone->zone_start_pfn = start_pfn; |
| 259 | zone->spanned_pages = end_pfn - start_pfn; |
| 260 | } else { |
| 261 | /* |
| 262 | * make it consist as free_area_init_core(), |
| 263 | * if spanned_pages = 0, then keep start_pfn = 0 |
| 264 | */ |
| 265 | zone->zone_start_pfn = 0; |
| 266 | zone->spanned_pages = 0; |
| 267 | } |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 268 | |
| 269 | zone_span_writeunlock(zone); |
| 270 | } |
| 271 | |
| 272 | static void fix_zone_id(struct zone *zone, unsigned long start_pfn, |
| 273 | unsigned long end_pfn) |
| 274 | { |
| 275 | enum zone_type zid = zone_idx(zone); |
| 276 | int nid = zone->zone_pgdat->node_id; |
| 277 | unsigned long pfn; |
| 278 | |
| 279 | for (pfn = start_pfn; pfn < end_pfn; pfn++) |
| 280 | set_page_links(pfn_to_page(pfn), zid, nid, pfn); |
| 281 | } |
| 282 | |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 283 | static int __meminit move_pfn_range_left(struct zone *z1, struct zone *z2, |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 284 | unsigned long start_pfn, unsigned long end_pfn) |
| 285 | { |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 286 | int ret; |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 287 | unsigned long flags; |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 288 | unsigned long z1_start_pfn; |
| 289 | |
| 290 | if (!z1->wait_table) { |
| 291 | ret = init_currently_empty_zone(z1, start_pfn, |
| 292 | end_pfn - start_pfn, MEMMAP_HOTPLUG); |
| 293 | if (ret) |
| 294 | return ret; |
| 295 | } |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 296 | |
| 297 | pgdat_resize_lock(z1->zone_pgdat, &flags); |
| 298 | |
| 299 | /* can't move pfns which are higher than @z2 */ |
| 300 | if (end_pfn > z2->zone_start_pfn + z2->spanned_pages) |
| 301 | goto out_fail; |
| 302 | /* the move out part mast at the left most of @z2 */ |
| 303 | if (start_pfn > z2->zone_start_pfn) |
| 304 | goto out_fail; |
| 305 | /* must included/overlap */ |
| 306 | if (end_pfn <= z2->zone_start_pfn) |
| 307 | goto out_fail; |
| 308 | |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 309 | /* use start_pfn for z1's start_pfn if z1 is empty */ |
| 310 | if (z1->spanned_pages) |
| 311 | z1_start_pfn = z1->zone_start_pfn; |
| 312 | else |
| 313 | z1_start_pfn = start_pfn; |
| 314 | |
| 315 | resize_zone(z1, z1_start_pfn, end_pfn); |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 316 | resize_zone(z2, end_pfn, z2->zone_start_pfn + z2->spanned_pages); |
| 317 | |
| 318 | pgdat_resize_unlock(z1->zone_pgdat, &flags); |
| 319 | |
| 320 | fix_zone_id(z1, start_pfn, end_pfn); |
| 321 | |
| 322 | return 0; |
| 323 | out_fail: |
| 324 | pgdat_resize_unlock(z1->zone_pgdat, &flags); |
| 325 | return -1; |
| 326 | } |
| 327 | |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 328 | static int __meminit move_pfn_range_right(struct zone *z1, struct zone *z2, |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 329 | unsigned long start_pfn, unsigned long end_pfn) |
| 330 | { |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 331 | int ret; |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 332 | unsigned long flags; |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 333 | unsigned long z2_end_pfn; |
| 334 | |
| 335 | if (!z2->wait_table) { |
| 336 | ret = init_currently_empty_zone(z2, start_pfn, |
| 337 | end_pfn - start_pfn, MEMMAP_HOTPLUG); |
| 338 | if (ret) |
| 339 | return ret; |
| 340 | } |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 341 | |
| 342 | pgdat_resize_lock(z1->zone_pgdat, &flags); |
| 343 | |
| 344 | /* can't move pfns which are lower than @z1 */ |
| 345 | if (z1->zone_start_pfn > start_pfn) |
| 346 | goto out_fail; |
| 347 | /* the move out part mast at the right most of @z1 */ |
| 348 | if (z1->zone_start_pfn + z1->spanned_pages > end_pfn) |
| 349 | goto out_fail; |
| 350 | /* must included/overlap */ |
| 351 | if (start_pfn >= z1->zone_start_pfn + z1->spanned_pages) |
| 352 | goto out_fail; |
| 353 | |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 354 | /* use end_pfn for z2's end_pfn if z2 is empty */ |
| 355 | if (z2->spanned_pages) |
| 356 | z2_end_pfn = z2->zone_start_pfn + z2->spanned_pages; |
| 357 | else |
| 358 | z2_end_pfn = end_pfn; |
| 359 | |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 360 | resize_zone(z1, z1->zone_start_pfn, start_pfn); |
Lai Jiangshan | e455a9b | 2012-12-11 16:03:20 -0800 | [diff] [blame] | 361 | resize_zone(z2, start_pfn, z2_end_pfn); |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 362 | |
| 363 | pgdat_resize_unlock(z1->zone_pgdat, &flags); |
| 364 | |
| 365 | fix_zone_id(z2, start_pfn, end_pfn); |
| 366 | |
| 367 | return 0; |
| 368 | out_fail: |
| 369 | pgdat_resize_unlock(z1->zone_pgdat, &flags); |
| 370 | return -1; |
| 371 | } |
| 372 | |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 373 | static void grow_pgdat_span(struct pglist_data *pgdat, unsigned long start_pfn, |
| 374 | unsigned long end_pfn) |
| 375 | { |
| 376 | unsigned long old_pgdat_end_pfn = |
| 377 | pgdat->node_start_pfn + pgdat->node_spanned_pages; |
| 378 | |
Tang Chen | 712cd38 | 2012-12-11 16:01:07 -0800 | [diff] [blame] | 379 | if (!pgdat->node_spanned_pages || start_pfn < pgdat->node_start_pfn) |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 380 | pgdat->node_start_pfn = start_pfn; |
| 381 | |
| 382 | pgdat->node_spanned_pages = max(old_pgdat_end_pfn, end_pfn) - |
| 383 | pgdat->node_start_pfn; |
| 384 | } |
| 385 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 386 | static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 387 | { |
| 388 | struct pglist_data *pgdat = zone->zone_pgdat; |
| 389 | int nr_pages = PAGES_PER_SECTION; |
| 390 | int nid = pgdat->node_id; |
| 391 | int zone_type; |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 392 | unsigned long flags; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 393 | |
| 394 | zone_type = zone - pgdat->node_zones; |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 395 | if (!zone->wait_table) { |
| 396 | int ret; |
| 397 | |
| 398 | ret = init_currently_empty_zone(zone, phys_start_pfn, |
| 399 | nr_pages, MEMMAP_HOTPLUG); |
| 400 | if (ret) |
| 401 | return ret; |
| 402 | } |
| 403 | pgdat_resize_lock(zone->zone_pgdat, &flags); |
| 404 | grow_zone_span(zone, phys_start_pfn, phys_start_pfn + nr_pages); |
| 405 | grow_pgdat_span(zone->zone_pgdat, phys_start_pfn, |
| 406 | phys_start_pfn + nr_pages); |
| 407 | pgdat_resize_unlock(zone->zone_pgdat, &flags); |
Dave Hansen | a2f3aa02 | 2007-01-10 23:15:30 -0800 | [diff] [blame] | 408 | memmap_init_zone(nr_pages, nid, zone_type, |
| 409 | phys_start_pfn, MEMMAP_HOTPLUG); |
Yasunori Goto | 718127c | 2006-06-23 02:03:10 -0700 | [diff] [blame] | 410 | return 0; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 413 | static int __meminit __add_section(int nid, struct zone *zone, |
| 414 | unsigned long phys_start_pfn) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 415 | { |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 416 | int nr_pages = PAGES_PER_SECTION; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 417 | int ret; |
| 418 | |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 419 | if (pfn_valid(phys_start_pfn)) |
| 420 | return -EEXIST; |
| 421 | |
Dave Hansen | 0b0acbe | 2005-10-29 18:16:55 -0700 | [diff] [blame] | 422 | ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 423 | |
| 424 | if (ret < 0) |
| 425 | return ret; |
| 426 | |
Yasunori Goto | 718127c | 2006-06-23 02:03:10 -0700 | [diff] [blame] | 427 | ret = __add_zone(zone, phys_start_pfn); |
| 428 | |
| 429 | if (ret < 0) |
| 430 | return ret; |
| 431 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 432 | return register_new_memory(nid, __pfn_to_section(phys_start_pfn)); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Yasuaki Ishimatsu | 815121d | 2013-02-22 16:33:12 -0800 | [diff] [blame^] | 435 | /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ |
| 436 | static int find_smallest_section_pfn(int nid, struct zone *zone, |
| 437 | unsigned long start_pfn, |
| 438 | unsigned long end_pfn) |
| 439 | { |
| 440 | struct mem_section *ms; |
| 441 | |
| 442 | for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) { |
| 443 | ms = __pfn_to_section(start_pfn); |
| 444 | |
| 445 | if (unlikely(!valid_section(ms))) |
| 446 | continue; |
| 447 | |
| 448 | if (unlikely(pfn_to_nid(start_pfn) != nid)) |
| 449 | continue; |
| 450 | |
| 451 | if (zone && zone != page_zone(pfn_to_page(start_pfn))) |
| 452 | continue; |
| 453 | |
| 454 | return start_pfn; |
| 455 | } |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | /* find the biggest valid pfn in the range [start_pfn, end_pfn). */ |
| 461 | static int find_biggest_section_pfn(int nid, struct zone *zone, |
| 462 | unsigned long start_pfn, |
| 463 | unsigned long end_pfn) |
| 464 | { |
| 465 | struct mem_section *ms; |
| 466 | unsigned long pfn; |
| 467 | |
| 468 | /* pfn is the end pfn of a memory section. */ |
| 469 | pfn = end_pfn - 1; |
| 470 | for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) { |
| 471 | ms = __pfn_to_section(pfn); |
| 472 | |
| 473 | if (unlikely(!valid_section(ms))) |
| 474 | continue; |
| 475 | |
| 476 | if (unlikely(pfn_to_nid(pfn) != nid)) |
| 477 | continue; |
| 478 | |
| 479 | if (zone && zone != page_zone(pfn_to_page(pfn))) |
| 480 | continue; |
| 481 | |
| 482 | return pfn; |
| 483 | } |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, |
| 489 | unsigned long end_pfn) |
| 490 | { |
| 491 | unsigned long zone_start_pfn = zone->zone_start_pfn; |
| 492 | unsigned long zone_end_pfn = zone->zone_start_pfn + zone->spanned_pages; |
| 493 | unsigned long pfn; |
| 494 | struct mem_section *ms; |
| 495 | int nid = zone_to_nid(zone); |
| 496 | |
| 497 | zone_span_writelock(zone); |
| 498 | if (zone_start_pfn == start_pfn) { |
| 499 | /* |
| 500 | * If the section is smallest section in the zone, it need |
| 501 | * shrink zone->zone_start_pfn and zone->zone_spanned_pages. |
| 502 | * In this case, we find second smallest valid mem_section |
| 503 | * for shrinking zone. |
| 504 | */ |
| 505 | pfn = find_smallest_section_pfn(nid, zone, end_pfn, |
| 506 | zone_end_pfn); |
| 507 | if (pfn) { |
| 508 | zone->zone_start_pfn = pfn; |
| 509 | zone->spanned_pages = zone_end_pfn - pfn; |
| 510 | } |
| 511 | } else if (zone_end_pfn == end_pfn) { |
| 512 | /* |
| 513 | * If the section is biggest section in the zone, it need |
| 514 | * shrink zone->spanned_pages. |
| 515 | * In this case, we find second biggest valid mem_section for |
| 516 | * shrinking zone. |
| 517 | */ |
| 518 | pfn = find_biggest_section_pfn(nid, zone, zone_start_pfn, |
| 519 | start_pfn); |
| 520 | if (pfn) |
| 521 | zone->spanned_pages = pfn - zone_start_pfn + 1; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * The section is not biggest or smallest mem_section in the zone, it |
| 526 | * only creates a hole in the zone. So in this case, we need not |
| 527 | * change the zone. But perhaps, the zone has only hole data. Thus |
| 528 | * it check the zone has only hole or not. |
| 529 | */ |
| 530 | pfn = zone_start_pfn; |
| 531 | for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) { |
| 532 | ms = __pfn_to_section(pfn); |
| 533 | |
| 534 | if (unlikely(!valid_section(ms))) |
| 535 | continue; |
| 536 | |
| 537 | if (page_zone(pfn_to_page(pfn)) != zone) |
| 538 | continue; |
| 539 | |
| 540 | /* If the section is current section, it continues the loop */ |
| 541 | if (start_pfn == pfn) |
| 542 | continue; |
| 543 | |
| 544 | /* If we find valid section, we have nothing to do */ |
| 545 | zone_span_writeunlock(zone); |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | /* The zone has no valid section */ |
| 550 | zone->zone_start_pfn = 0; |
| 551 | zone->spanned_pages = 0; |
| 552 | zone_span_writeunlock(zone); |
| 553 | } |
| 554 | |
| 555 | static void shrink_pgdat_span(struct pglist_data *pgdat, |
| 556 | unsigned long start_pfn, unsigned long end_pfn) |
| 557 | { |
| 558 | unsigned long pgdat_start_pfn = pgdat->node_start_pfn; |
| 559 | unsigned long pgdat_end_pfn = |
| 560 | pgdat->node_start_pfn + pgdat->node_spanned_pages; |
| 561 | unsigned long pfn; |
| 562 | struct mem_section *ms; |
| 563 | int nid = pgdat->node_id; |
| 564 | |
| 565 | if (pgdat_start_pfn == start_pfn) { |
| 566 | /* |
| 567 | * If the section is smallest section in the pgdat, it need |
| 568 | * shrink pgdat->node_start_pfn and pgdat->node_spanned_pages. |
| 569 | * In this case, we find second smallest valid mem_section |
| 570 | * for shrinking zone. |
| 571 | */ |
| 572 | pfn = find_smallest_section_pfn(nid, NULL, end_pfn, |
| 573 | pgdat_end_pfn); |
| 574 | if (pfn) { |
| 575 | pgdat->node_start_pfn = pfn; |
| 576 | pgdat->node_spanned_pages = pgdat_end_pfn - pfn; |
| 577 | } |
| 578 | } else if (pgdat_end_pfn == end_pfn) { |
| 579 | /* |
| 580 | * If the section is biggest section in the pgdat, it need |
| 581 | * shrink pgdat->node_spanned_pages. |
| 582 | * In this case, we find second biggest valid mem_section for |
| 583 | * shrinking zone. |
| 584 | */ |
| 585 | pfn = find_biggest_section_pfn(nid, NULL, pgdat_start_pfn, |
| 586 | start_pfn); |
| 587 | if (pfn) |
| 588 | pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1; |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * If the section is not biggest or smallest mem_section in the pgdat, |
| 593 | * it only creates a hole in the pgdat. So in this case, we need not |
| 594 | * change the pgdat. |
| 595 | * But perhaps, the pgdat has only hole data. Thus it check the pgdat |
| 596 | * has only hole or not. |
| 597 | */ |
| 598 | pfn = pgdat_start_pfn; |
| 599 | for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SECTION) { |
| 600 | ms = __pfn_to_section(pfn); |
| 601 | |
| 602 | if (unlikely(!valid_section(ms))) |
| 603 | continue; |
| 604 | |
| 605 | if (pfn_to_nid(pfn) != nid) |
| 606 | continue; |
| 607 | |
| 608 | /* If the section is current section, it continues the loop */ |
| 609 | if (start_pfn == pfn) |
| 610 | continue; |
| 611 | |
| 612 | /* If we find valid section, we have nothing to do */ |
| 613 | return; |
| 614 | } |
| 615 | |
| 616 | /* The pgdat has no valid section */ |
| 617 | pgdat->node_start_pfn = 0; |
| 618 | pgdat->node_spanned_pages = 0; |
| 619 | } |
| 620 | |
| 621 | static void __remove_zone(struct zone *zone, unsigned long start_pfn) |
| 622 | { |
| 623 | struct pglist_data *pgdat = zone->zone_pgdat; |
| 624 | int nr_pages = PAGES_PER_SECTION; |
| 625 | int zone_type; |
| 626 | unsigned long flags; |
| 627 | |
| 628 | zone_type = zone - pgdat->node_zones; |
| 629 | |
| 630 | pgdat_resize_lock(zone->zone_pgdat, &flags); |
| 631 | shrink_zone_span(zone, start_pfn, start_pfn + nr_pages); |
| 632 | shrink_pgdat_span(pgdat, start_pfn, start_pfn + nr_pages); |
| 633 | pgdat_resize_unlock(zone->zone_pgdat, &flags); |
| 634 | } |
| 635 | |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 636 | static int __remove_section(struct zone *zone, struct mem_section *ms) |
| 637 | { |
Yasuaki Ishimatsu | 815121d | 2013-02-22 16:33:12 -0800 | [diff] [blame^] | 638 | unsigned long start_pfn; |
| 639 | int scn_nr; |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 640 | int ret = -EINVAL; |
| 641 | |
| 642 | if (!valid_section(ms)) |
| 643 | return ret; |
| 644 | |
| 645 | ret = unregister_memory_section(ms); |
| 646 | if (ret) |
| 647 | return ret; |
| 648 | |
Yasuaki Ishimatsu | 815121d | 2013-02-22 16:33:12 -0800 | [diff] [blame^] | 649 | scn_nr = __section_nr(ms); |
| 650 | start_pfn = section_nr_to_pfn(scn_nr); |
| 651 | __remove_zone(zone, start_pfn); |
| 652 | |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 653 | sparse_remove_one_section(zone, ms); |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 657 | /* |
| 658 | * Reasonably generic function for adding memory. It is |
| 659 | * expected that archs that support memory hotplug will |
| 660 | * call this function after deciding the zone to which to |
| 661 | * add the new pages. |
| 662 | */ |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 663 | int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn, |
| 664 | unsigned long nr_pages) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 665 | { |
| 666 | unsigned long i; |
| 667 | int err = 0; |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 668 | int start_sec, end_sec; |
| 669 | /* during initialize mem_map, align hot-added range to section */ |
| 670 | start_sec = pfn_to_section_nr(phys_start_pfn); |
| 671 | end_sec = pfn_to_section_nr(phys_start_pfn + nr_pages - 1); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 672 | |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 673 | for (i = start_sec; i <= end_sec; i++) { |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 674 | err = __add_section(nid, zone, i << PFN_SECTION_SHIFT); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 675 | |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 676 | /* |
Simon Arlott | 183ff22 | 2007-10-20 01:27:18 +0200 | [diff] [blame] | 677 | * EEXIST is finally dealt with by ioresource collision |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 678 | * check. see add_memory() => register_memory_resource() |
| 679 | * Warning will be printed if there is collision. |
Joel H Schopp | bed120c | 2006-05-01 12:16:11 -0700 | [diff] [blame] | 680 | */ |
| 681 | if (err && (err != -EEXIST)) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 682 | break; |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 683 | err = 0; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | return err; |
| 687 | } |
Joel H Schopp | bed120c | 2006-05-01 12:16:11 -0700 | [diff] [blame] | 688 | EXPORT_SYMBOL_GPL(__add_pages); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 689 | |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 690 | /** |
| 691 | * __remove_pages() - remove sections of pages from a zone |
| 692 | * @zone: zone from which pages need to be removed |
| 693 | * @phys_start_pfn: starting pageframe (must be aligned to start of a section) |
| 694 | * @nr_pages: number of pages to remove (must be multiple of section size) |
| 695 | * |
| 696 | * Generic helper function to remove section mappings and sysfs entries |
| 697 | * for the section of the memory we are removing. Caller needs to make |
| 698 | * sure that pages are marked reserved and zones are adjust properly by |
| 699 | * calling offline_pages(). |
| 700 | */ |
| 701 | int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, |
| 702 | unsigned long nr_pages) |
| 703 | { |
| 704 | unsigned long i, ret = 0; |
| 705 | int sections_to_remove; |
| 706 | |
| 707 | /* |
| 708 | * We can only remove entire sections |
| 709 | */ |
| 710 | BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK); |
| 711 | BUG_ON(nr_pages % PAGES_PER_SECTION); |
| 712 | |
Yasuaki Ishimatsu | d760afd | 2012-10-08 16:34:14 -0700 | [diff] [blame] | 713 | release_mem_region(phys_start_pfn << PAGE_SHIFT, nr_pages * PAGE_SIZE); |
| 714 | |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 715 | sections_to_remove = nr_pages / PAGES_PER_SECTION; |
| 716 | for (i = 0; i < sections_to_remove; i++) { |
| 717 | unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; |
| 718 | ret = __remove_section(zone, __pfn_to_section(pfn)); |
| 719 | if (ret) |
| 720 | break; |
| 721 | } |
| 722 | return ret; |
| 723 | } |
| 724 | EXPORT_SYMBOL_GPL(__remove_pages); |
| 725 | |
Daniel Kiper | 9d0ad8c | 2011-07-25 17:12:05 -0700 | [diff] [blame] | 726 | int set_online_page_callback(online_page_callback_t callback) |
| 727 | { |
| 728 | int rc = -EINVAL; |
| 729 | |
| 730 | lock_memory_hotplug(); |
| 731 | |
| 732 | if (online_page_callback == generic_online_page) { |
| 733 | online_page_callback = callback; |
| 734 | rc = 0; |
| 735 | } |
| 736 | |
| 737 | unlock_memory_hotplug(); |
| 738 | |
| 739 | return rc; |
| 740 | } |
| 741 | EXPORT_SYMBOL_GPL(set_online_page_callback); |
| 742 | |
| 743 | int restore_online_page_callback(online_page_callback_t callback) |
| 744 | { |
| 745 | int rc = -EINVAL; |
| 746 | |
| 747 | lock_memory_hotplug(); |
| 748 | |
| 749 | if (online_page_callback == callback) { |
| 750 | online_page_callback = generic_online_page; |
| 751 | rc = 0; |
| 752 | } |
| 753 | |
| 754 | unlock_memory_hotplug(); |
| 755 | |
| 756 | return rc; |
| 757 | } |
| 758 | EXPORT_SYMBOL_GPL(restore_online_page_callback); |
| 759 | |
| 760 | void __online_page_set_limits(struct page *page) |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 761 | { |
Jan Beulich | 4738e1b | 2009-09-21 17:03:03 -0700 | [diff] [blame] | 762 | unsigned long pfn = page_to_pfn(page); |
| 763 | |
Jan Beulich | 4738e1b | 2009-09-21 17:03:03 -0700 | [diff] [blame] | 764 | if (pfn >= num_physpages) |
| 765 | num_physpages = pfn + 1; |
Daniel Kiper | 9d0ad8c | 2011-07-25 17:12:05 -0700 | [diff] [blame] | 766 | } |
| 767 | EXPORT_SYMBOL_GPL(__online_page_set_limits); |
| 768 | |
| 769 | void __online_page_increment_counters(struct page *page) |
| 770 | { |
| 771 | totalram_pages++; |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 772 | |
| 773 | #ifdef CONFIG_HIGHMEM |
| 774 | if (PageHighMem(page)) |
| 775 | totalhigh_pages++; |
| 776 | #endif |
Daniel Kiper | 9d0ad8c | 2011-07-25 17:12:05 -0700 | [diff] [blame] | 777 | } |
| 778 | EXPORT_SYMBOL_GPL(__online_page_increment_counters); |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 779 | |
Daniel Kiper | 9d0ad8c | 2011-07-25 17:12:05 -0700 | [diff] [blame] | 780 | void __online_page_free(struct page *page) |
| 781 | { |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 782 | ClearPageReserved(page); |
| 783 | init_page_count(page); |
| 784 | __free_page(page); |
| 785 | } |
Daniel Kiper | 9d0ad8c | 2011-07-25 17:12:05 -0700 | [diff] [blame] | 786 | EXPORT_SYMBOL_GPL(__online_page_free); |
| 787 | |
| 788 | static void generic_online_page(struct page *page) |
| 789 | { |
| 790 | __online_page_set_limits(page); |
| 791 | __online_page_increment_counters(page); |
| 792 | __online_page_free(page); |
| 793 | } |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 794 | |
KAMEZAWA Hiroyuki | 75884fb1 | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 795 | static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages, |
| 796 | void *arg) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 797 | { |
| 798 | unsigned long i; |
KAMEZAWA Hiroyuki | 75884fb1 | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 799 | unsigned long onlined_pages = *(unsigned long *)arg; |
| 800 | struct page *page; |
| 801 | if (PageReserved(pfn_to_page(start_pfn))) |
| 802 | for (i = 0; i < nr_pages; i++) { |
| 803 | page = pfn_to_page(start_pfn + i); |
Daniel Kiper | 9d0ad8c | 2011-07-25 17:12:05 -0700 | [diff] [blame] | 804 | (*online_page_callback)(page); |
KAMEZAWA Hiroyuki | 75884fb1 | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 805 | onlined_pages++; |
| 806 | } |
| 807 | *(unsigned long *)arg = onlined_pages; |
| 808 | return 0; |
| 809 | } |
| 810 | |
Lai Jiangshan | 09285af | 2012-12-12 13:52:04 -0800 | [diff] [blame] | 811 | #ifdef CONFIG_MOVABLE_NODE |
Tang Chen | 79a4dce | 2012-12-18 14:23:24 -0800 | [diff] [blame] | 812 | /* |
| 813 | * When CONFIG_MOVABLE_NODE, we permit onlining of a node which doesn't have |
| 814 | * normal memory. |
| 815 | */ |
Lai Jiangshan | 09285af | 2012-12-12 13:52:04 -0800 | [diff] [blame] | 816 | static bool can_online_high_movable(struct zone *zone) |
| 817 | { |
| 818 | return true; |
| 819 | } |
Tang Chen | 79a4dce | 2012-12-18 14:23:24 -0800 | [diff] [blame] | 820 | #else /* CONFIG_MOVABLE_NODE */ |
Lai Jiangshan | 74d42d8 | 2012-12-11 16:03:23 -0800 | [diff] [blame] | 821 | /* ensure every online node has NORMAL memory */ |
| 822 | static bool can_online_high_movable(struct zone *zone) |
| 823 | { |
| 824 | return node_state(zone_to_nid(zone), N_NORMAL_MEMORY); |
| 825 | } |
Tang Chen | 79a4dce | 2012-12-18 14:23:24 -0800 | [diff] [blame] | 826 | #endif /* CONFIG_MOVABLE_NODE */ |
Lai Jiangshan | 74d42d8 | 2012-12-11 16:03:23 -0800 | [diff] [blame] | 827 | |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 828 | /* check which state of node_states will be changed when online memory */ |
| 829 | static void node_states_check_changes_online(unsigned long nr_pages, |
| 830 | struct zone *zone, struct memory_notify *arg) |
| 831 | { |
| 832 | int nid = zone_to_nid(zone); |
| 833 | enum zone_type zone_last = ZONE_NORMAL; |
| 834 | |
| 835 | /* |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 836 | * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY] |
| 837 | * contains nodes which have zones of 0...ZONE_NORMAL, |
| 838 | * set zone_last to ZONE_NORMAL. |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 839 | * |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 840 | * If we don't have HIGHMEM nor movable node, |
| 841 | * node_states[N_NORMAL_MEMORY] contains nodes which have zones of |
| 842 | * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE. |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 843 | */ |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 844 | if (N_MEMORY == N_NORMAL_MEMORY) |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 845 | zone_last = ZONE_MOVABLE; |
| 846 | |
| 847 | /* |
| 848 | * if the memory to be online is in a zone of 0...zone_last, and |
| 849 | * the zones of 0...zone_last don't have memory before online, we will |
| 850 | * need to set the node to node_states[N_NORMAL_MEMORY] after |
| 851 | * the memory is online. |
| 852 | */ |
| 853 | if (zone_idx(zone) <= zone_last && !node_state(nid, N_NORMAL_MEMORY)) |
| 854 | arg->status_change_nid_normal = nid; |
| 855 | else |
| 856 | arg->status_change_nid_normal = -1; |
| 857 | |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 858 | #ifdef CONFIG_HIGHMEM |
| 859 | /* |
| 860 | * If we have movable node, node_states[N_HIGH_MEMORY] |
| 861 | * contains nodes which have zones of 0...ZONE_HIGHMEM, |
| 862 | * set zone_last to ZONE_HIGHMEM. |
| 863 | * |
| 864 | * If we don't have movable node, node_states[N_NORMAL_MEMORY] |
| 865 | * contains nodes which have zones of 0...ZONE_MOVABLE, |
| 866 | * set zone_last to ZONE_MOVABLE. |
| 867 | */ |
| 868 | zone_last = ZONE_HIGHMEM; |
| 869 | if (N_MEMORY == N_HIGH_MEMORY) |
| 870 | zone_last = ZONE_MOVABLE; |
| 871 | |
| 872 | if (zone_idx(zone) <= zone_last && !node_state(nid, N_HIGH_MEMORY)) |
| 873 | arg->status_change_nid_high = nid; |
| 874 | else |
| 875 | arg->status_change_nid_high = -1; |
| 876 | #else |
| 877 | arg->status_change_nid_high = arg->status_change_nid_normal; |
| 878 | #endif |
| 879 | |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 880 | /* |
| 881 | * if the node don't have memory befor online, we will need to |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 882 | * set the node to node_states[N_MEMORY] after the memory |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 883 | * is online. |
| 884 | */ |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 885 | if (!node_state(nid, N_MEMORY)) |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 886 | arg->status_change_nid = nid; |
| 887 | else |
| 888 | arg->status_change_nid = -1; |
| 889 | } |
| 890 | |
| 891 | static void node_states_set_node(int node, struct memory_notify *arg) |
| 892 | { |
| 893 | if (arg->status_change_nid_normal >= 0) |
| 894 | node_set_state(node, N_NORMAL_MEMORY); |
| 895 | |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 896 | if (arg->status_change_nid_high >= 0) |
| 897 | node_set_state(node, N_HIGH_MEMORY); |
| 898 | |
| 899 | node_set_state(node, N_MEMORY); |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 900 | } |
| 901 | |
KAMEZAWA Hiroyuki | 75884fb1 | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 902 | |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 903 | int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_type) |
KAMEZAWA Hiroyuki | 75884fb1 | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 904 | { |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 905 | unsigned long onlined_pages = 0; |
| 906 | struct zone *zone; |
Yasunori Goto | 6811378 | 2006-06-23 02:03:11 -0700 | [diff] [blame] | 907 | int need_zonelists_rebuild = 0; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 908 | int nid; |
| 909 | int ret; |
| 910 | struct memory_notify arg; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 911 | |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 912 | lock_memory_hotplug(); |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 913 | /* |
| 914 | * This doesn't need a lock to do pfn_to_page(). |
| 915 | * The section can't be removed here because of the |
| 916 | * memory_block->state_mutex. |
| 917 | */ |
| 918 | zone = page_zone(pfn_to_page(pfn)); |
| 919 | |
Lai Jiangshan | 74d42d8 | 2012-12-11 16:03:23 -0800 | [diff] [blame] | 920 | if ((zone_idx(zone) > ZONE_NORMAL || online_type == ONLINE_MOVABLE) && |
| 921 | !can_online_high_movable(zone)) { |
| 922 | unlock_memory_hotplug(); |
| 923 | return -1; |
| 924 | } |
| 925 | |
Lai Jiangshan | 511c2ab | 2012-12-11 16:03:16 -0800 | [diff] [blame] | 926 | if (online_type == ONLINE_KERNEL && zone_idx(zone) == ZONE_MOVABLE) { |
| 927 | if (move_pfn_range_left(zone - 1, zone, pfn, pfn + nr_pages)) { |
| 928 | unlock_memory_hotplug(); |
| 929 | return -1; |
| 930 | } |
| 931 | } |
| 932 | if (online_type == ONLINE_MOVABLE && zone_idx(zone) == ZONE_MOVABLE - 1) { |
| 933 | if (move_pfn_range_right(zone, zone + 1, pfn, pfn + nr_pages)) { |
| 934 | unlock_memory_hotplug(); |
| 935 | return -1; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | /* Previous code may changed the zone of the pfn range */ |
| 940 | zone = page_zone(pfn_to_page(pfn)); |
| 941 | |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 942 | arg.start_pfn = pfn; |
| 943 | arg.nr_pages = nr_pages; |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 944 | node_states_check_changes_online(nr_pages, zone, &arg); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 945 | |
| 946 | nid = page_to_nid(pfn_to_page(pfn)); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 947 | |
| 948 | ret = memory_notify(MEM_GOING_ONLINE, &arg); |
| 949 | ret = notifier_to_errno(ret); |
| 950 | if (ret) { |
| 951 | memory_notify(MEM_CANCEL_ONLINE, &arg); |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 952 | unlock_memory_hotplug(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 953 | return ret; |
| 954 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 955 | /* |
Yasunori Goto | 6811378 | 2006-06-23 02:03:11 -0700 | [diff] [blame] | 956 | * If this zone is not populated, then it is not in zonelist. |
| 957 | * This means the page allocator ignores this zone. |
| 958 | * So, zonelist must be updated after online. |
| 959 | */ |
Haicheng Li | 4eaf3f6 | 2010-05-24 14:32:52 -0700 | [diff] [blame] | 960 | mutex_lock(&zonelists_mutex); |
Wen Congyang | 6dcd73d | 2012-12-11 16:01:01 -0800 | [diff] [blame] | 961 | if (!populated_zone(zone)) { |
Yasunori Goto | 6811378 | 2006-06-23 02:03:11 -0700 | [diff] [blame] | 962 | need_zonelists_rebuild = 1; |
Wen Congyang | 6dcd73d | 2012-12-11 16:01:01 -0800 | [diff] [blame] | 963 | build_all_zonelists(NULL, zone); |
| 964 | } |
Yasunori Goto | 6811378 | 2006-06-23 02:03:11 -0700 | [diff] [blame] | 965 | |
KAMEZAWA Hiroyuki | 908eedc | 2009-09-22 16:45:46 -0700 | [diff] [blame] | 966 | ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages, |
KAMEZAWA Hiroyuki | 75884fb1 | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 967 | online_pages_range); |
Geoff Levand | fd8a422 | 2008-05-14 16:05:50 -0700 | [diff] [blame] | 968 | if (ret) { |
Wen Congyang | 6dcd73d | 2012-12-11 16:01:01 -0800 | [diff] [blame] | 969 | if (need_zonelists_rebuild) |
| 970 | zone_pcp_reset(zone); |
Haicheng Li | 4eaf3f6 | 2010-05-24 14:32:52 -0700 | [diff] [blame] | 971 | mutex_unlock(&zonelists_mutex); |
Bjorn Helgaas | a62e2f4 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 972 | printk(KERN_DEBUG "online_pages [mem %#010llx-%#010llx] failed\n", |
| 973 | (unsigned long long) pfn << PAGE_SHIFT, |
| 974 | (((unsigned long long) pfn + nr_pages) |
| 975 | << PAGE_SHIFT) - 1); |
Geoff Levand | fd8a422 | 2008-05-14 16:05:50 -0700 | [diff] [blame] | 976 | memory_notify(MEM_CANCEL_ONLINE, &arg); |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 977 | unlock_memory_hotplug(); |
Geoff Levand | fd8a422 | 2008-05-14 16:05:50 -0700 | [diff] [blame] | 978 | return ret; |
| 979 | } |
| 980 | |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 981 | zone->managed_pages += onlined_pages; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 982 | zone->present_pages += onlined_pages; |
Yasunori Goto | f2937be | 2006-03-09 17:33:51 -0800 | [diff] [blame] | 983 | zone->zone_pgdat->node_present_pages += onlined_pages; |
Jiang Liu | 08dff7b | 2012-07-31 16:43:30 -0700 | [diff] [blame] | 984 | if (onlined_pages) { |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 985 | node_states_set_node(zone_to_nid(zone), &arg); |
Jiang Liu | 08dff7b | 2012-07-31 16:43:30 -0700 | [diff] [blame] | 986 | if (need_zonelists_rebuild) |
Wen Congyang | 6dcd73d | 2012-12-11 16:01:01 -0800 | [diff] [blame] | 987 | build_all_zonelists(NULL, NULL); |
Jiang Liu | 08dff7b | 2012-07-31 16:43:30 -0700 | [diff] [blame] | 988 | else |
| 989 | zone_pcp_update(zone); |
| 990 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 991 | |
Haicheng Li | 4eaf3f6 | 2010-05-24 14:32:52 -0700 | [diff] [blame] | 992 | mutex_unlock(&zonelists_mutex); |
KOSAKI Motohiro | 1b79acc | 2011-05-24 17:11:32 -0700 | [diff] [blame] | 993 | |
| 994 | init_per_zone_wmark_min(); |
| 995 | |
Jiang Liu | 08dff7b | 2012-07-31 16:43:30 -0700 | [diff] [blame] | 996 | if (onlined_pages) |
Christoph Lameter | 7ea1530 | 2007-10-16 01:25:29 -0700 | [diff] [blame] | 997 | kswapd_run(zone_to_nid(zone)); |
Dave Hansen | 61b1399 | 2005-10-29 18:16:56 -0700 | [diff] [blame] | 998 | |
Haicheng Li | 1f52250 | 2010-05-24 14:32:51 -0700 | [diff] [blame] | 999 | vm_total_pages = nr_free_pagecache_pages(); |
Kent Liu | 2f7f24e | 2008-07-23 21:28:18 -0700 | [diff] [blame] | 1000 | |
Chandra Seetharaman | 2d1d43f | 2006-09-29 02:01:25 -0700 | [diff] [blame] | 1001 | writeback_set_ratelimit(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | if (onlined_pages) |
| 1004 | memory_notify(MEM_ONLINE, &arg); |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 1005 | unlock_memory_hotplug(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1006 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 1007 | return 0; |
| 1008 | } |
Keith Mannthey | 5394702 | 2006-09-30 23:27:08 -0700 | [diff] [blame] | 1009 | #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 1010 | |
Hidetoshi Seto | e131933 | 2009-11-17 14:06:18 -0800 | [diff] [blame] | 1011 | /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ |
| 1012 | static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start) |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1013 | { |
| 1014 | struct pglist_data *pgdat; |
| 1015 | unsigned long zones_size[MAX_NR_ZONES] = {0}; |
| 1016 | unsigned long zholes_size[MAX_NR_ZONES] = {0}; |
| 1017 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 1018 | |
| 1019 | pgdat = arch_alloc_nodedata(nid); |
| 1020 | if (!pgdat) |
| 1021 | return NULL; |
| 1022 | |
| 1023 | arch_refresh_nodedata(nid, pgdat); |
| 1024 | |
| 1025 | /* we can use NODE_DATA(nid) from here */ |
| 1026 | |
| 1027 | /* init node's zones as empty zones, we don't have any present pages.*/ |
Johannes Weiner | 9109fb7 | 2008-07-23 21:27:20 -0700 | [diff] [blame] | 1028 | free_area_init_node(nid, zones_size, start_pfn, zholes_size); |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1029 | |
KAMEZAWA Hiroyuki | 959ecc4 | 2011-06-15 15:08:38 -0700 | [diff] [blame] | 1030 | /* |
| 1031 | * The node we allocated has no zone fallback lists. For avoiding |
| 1032 | * to access not-initialized zonelist, build here. |
| 1033 | */ |
David Rientjes | f957db4 | 2011-06-22 18:13:04 -0700 | [diff] [blame] | 1034 | mutex_lock(&zonelists_mutex); |
Jiang Liu | 9adb62a | 2012-07-31 16:43:28 -0700 | [diff] [blame] | 1035 | build_all_zonelists(pgdat, NULL); |
David Rientjes | f957db4 | 2011-06-22 18:13:04 -0700 | [diff] [blame] | 1036 | mutex_unlock(&zonelists_mutex); |
KAMEZAWA Hiroyuki | 959ecc4 | 2011-06-15 15:08:38 -0700 | [diff] [blame] | 1037 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1038 | return pgdat; |
| 1039 | } |
| 1040 | |
| 1041 | static void rollback_node_hotadd(int nid, pg_data_t *pgdat) |
| 1042 | { |
| 1043 | arch_refresh_nodedata(nid, NULL); |
| 1044 | arch_free_nodedata(pgdat); |
| 1045 | return; |
| 1046 | } |
| 1047 | |
KAMEZAWA Hiroyuki | 0a54703 | 2006-06-27 02:53:35 -0700 | [diff] [blame] | 1048 | |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 1049 | /* |
| 1050 | * called by cpu_up() to online a node without onlined memory. |
| 1051 | */ |
| 1052 | int mem_online_node(int nid) |
| 1053 | { |
| 1054 | pg_data_t *pgdat; |
| 1055 | int ret; |
| 1056 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 1057 | lock_memory_hotplug(); |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 1058 | pgdat = hotadd_new_pgdat(nid, 0); |
David Rientjes | 7553e8f | 2011-06-22 18:13:01 -0700 | [diff] [blame] | 1059 | if (!pgdat) { |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 1060 | ret = -ENOMEM; |
| 1061 | goto out; |
| 1062 | } |
| 1063 | node_set_online(nid); |
| 1064 | ret = register_one_node(nid); |
| 1065 | BUG_ON(ret); |
| 1066 | |
| 1067 | out: |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 1068 | unlock_memory_hotplug(); |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 1069 | return ret; |
| 1070 | } |
| 1071 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 1072 | /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ |
| 1073 | int __ref add_memory(int nid, u64 start, u64 size) |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 1074 | { |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1075 | pg_data_t *pgdat = NULL; |
| 1076 | int new_pgdat = 0; |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 1077 | struct resource *res; |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 1078 | int ret; |
| 1079 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 1080 | lock_memory_hotplug(); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1081 | |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 1082 | res = register_memory_resource(start, size); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1083 | ret = -EEXIST; |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 1084 | if (!res) |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1085 | goto out; |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 1086 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1087 | if (!node_online(nid)) { |
| 1088 | pgdat = hotadd_new_pgdat(nid, start); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1089 | ret = -ENOMEM; |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1090 | if (!pgdat) |
Wen Congyang | 41b9e2d | 2012-07-11 14:02:31 -0700 | [diff] [blame] | 1091 | goto error; |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1092 | new_pgdat = 1; |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 1095 | /* call arch's memory hotadd */ |
| 1096 | ret = arch_add_memory(nid, start, size); |
| 1097 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1098 | if (ret < 0) |
| 1099 | goto error; |
| 1100 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 1101 | /* we online node here. we can't roll back from here. */ |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1102 | node_set_online(nid); |
| 1103 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 1104 | if (new_pgdat) { |
| 1105 | ret = register_one_node(nid); |
| 1106 | /* |
| 1107 | * If sysfs file of new node can't create, cpu on the node |
| 1108 | * can't be hot-added. There is no rollback way now. |
| 1109 | * So, check by BUG_ON() to catch it reluctantly.. |
| 1110 | */ |
| 1111 | BUG_ON(ret); |
| 1112 | } |
| 1113 | |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 1114 | /* create new memmap entry */ |
| 1115 | firmware_map_add_hotplug(start, start + size, "System RAM"); |
| 1116 | |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1117 | goto out; |
| 1118 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1119 | error: |
| 1120 | /* rollback pgdat allocation and others */ |
| 1121 | if (new_pgdat) |
| 1122 | rollback_node_hotadd(nid, pgdat); |
Sasha Levin | a864b9d | 2013-02-22 16:32:48 -0800 | [diff] [blame] | 1123 | release_memory_resource(res); |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 1124 | |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1125 | out: |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 1126 | unlock_memory_hotplug(); |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 1127 | return ret; |
| 1128 | } |
| 1129 | EXPORT_SYMBOL_GPL(add_memory); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1130 | |
| 1131 | #ifdef CONFIG_MEMORY_HOTREMOVE |
| 1132 | /* |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1133 | * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy |
| 1134 | * set and the size of the free page is given by page_order(). Using this, |
| 1135 | * the function determines if the pageblock contains only free pages. |
| 1136 | * Due to buddy contraints, a free page at least the size of a pageblock will |
| 1137 | * be located at the start of the pageblock |
| 1138 | */ |
| 1139 | static inline int pageblock_free(struct page *page) |
| 1140 | { |
| 1141 | return PageBuddy(page) && page_order(page) >= pageblock_order; |
| 1142 | } |
| 1143 | |
| 1144 | /* Return the start of the next active pageblock after a given page */ |
| 1145 | static struct page *next_active_pageblock(struct page *page) |
| 1146 | { |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1147 | /* Ensure the starting page is pageblock-aligned */ |
| 1148 | BUG_ON(page_to_pfn(page) & (pageblock_nr_pages - 1)); |
| 1149 | |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1150 | /* If the entire pageblock is free, move to the end of free page */ |
KAMEZAWA Hiroyuki | 0dcc48c | 2010-09-09 16:38:01 -0700 | [diff] [blame] | 1151 | if (pageblock_free(page)) { |
| 1152 | int order; |
| 1153 | /* be careful. we don't have locks, page_order can be changed.*/ |
| 1154 | order = page_order(page); |
| 1155 | if ((order < MAX_ORDER) && (order >= pageblock_order)) |
| 1156 | return page + (1 << order); |
| 1157 | } |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1158 | |
KAMEZAWA Hiroyuki | 0dcc48c | 2010-09-09 16:38:01 -0700 | [diff] [blame] | 1159 | return page + pageblock_nr_pages; |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* Checks if this range of memory is likely to be hot-removable. */ |
| 1163 | int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages) |
| 1164 | { |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1165 | struct page *page = pfn_to_page(start_pfn); |
| 1166 | struct page *end_page = page + nr_pages; |
| 1167 | |
| 1168 | /* Check the starting page of each pageblock within the range */ |
| 1169 | for (; page < end_page; page = next_active_pageblock(page)) { |
KAMEZAWA Hiroyuki | 49ac825 | 2010-10-26 14:21:30 -0700 | [diff] [blame] | 1170 | if (!is_pageblock_removable_nolock(page)) |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1171 | return 0; |
KAMEZAWA Hiroyuki | 49ac825 | 2010-10-26 14:21:30 -0700 | [diff] [blame] | 1172 | cond_resched(); |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /* All pageblocks in the memory block are likely to be hot-removable */ |
| 1176 | return 1; |
| 1177 | } |
| 1178 | |
| 1179 | /* |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1180 | * Confirm all pages in a range [start, end) is belongs to the same zone. |
| 1181 | */ |
| 1182 | static int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn) |
| 1183 | { |
| 1184 | unsigned long pfn; |
| 1185 | struct zone *zone = NULL; |
| 1186 | struct page *page; |
| 1187 | int i; |
| 1188 | for (pfn = start_pfn; |
| 1189 | pfn < end_pfn; |
| 1190 | pfn += MAX_ORDER_NR_PAGES) { |
| 1191 | i = 0; |
| 1192 | /* This is just a CONFIG_HOLES_IN_ZONE check.*/ |
| 1193 | while ((i < MAX_ORDER_NR_PAGES) && !pfn_valid_within(pfn + i)) |
| 1194 | i++; |
| 1195 | if (i == MAX_ORDER_NR_PAGES) |
| 1196 | continue; |
| 1197 | page = pfn_to_page(pfn + i); |
| 1198 | if (zone && page_zone(page) != zone) |
| 1199 | return 0; |
| 1200 | zone = page_zone(page); |
| 1201 | } |
| 1202 | return 1; |
| 1203 | } |
| 1204 | |
| 1205 | /* |
| 1206 | * Scanning pfn is much easier than scanning lru list. |
| 1207 | * Scan pfn from start to end and Find LRU page. |
| 1208 | */ |
Andrew Morton | 7bbc090 | 2010-10-26 14:22:05 -0700 | [diff] [blame] | 1209 | static unsigned long scan_lru_pages(unsigned long start, unsigned long end) |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1210 | { |
| 1211 | unsigned long pfn; |
| 1212 | struct page *page; |
| 1213 | for (pfn = start; pfn < end; pfn++) { |
| 1214 | if (pfn_valid(pfn)) { |
| 1215 | page = pfn_to_page(pfn); |
| 1216 | if (PageLRU(page)) |
| 1217 | return pfn; |
| 1218 | } |
| 1219 | } |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1223 | #define NR_OFFLINE_AT_ONCE_PAGES (256) |
| 1224 | static int |
| 1225 | do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) |
| 1226 | { |
| 1227 | unsigned long pfn; |
| 1228 | struct page *page; |
| 1229 | int move_pages = NR_OFFLINE_AT_ONCE_PAGES; |
| 1230 | int not_managed = 0; |
| 1231 | int ret = 0; |
| 1232 | LIST_HEAD(source); |
| 1233 | |
| 1234 | for (pfn = start_pfn; pfn < end_pfn && move_pages > 0; pfn++) { |
| 1235 | if (!pfn_valid(pfn)) |
| 1236 | continue; |
| 1237 | page = pfn_to_page(pfn); |
Konstantin Khlebnikov | 700c2a4 | 2011-05-24 17:12:19 -0700 | [diff] [blame] | 1238 | if (!get_page_unless_zero(page)) |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1239 | continue; |
| 1240 | /* |
| 1241 | * We can skip free pages. And we can only deal with pages on |
| 1242 | * LRU. |
| 1243 | */ |
Nick Piggin | 62695a8 | 2008-10-18 20:26:09 -0700 | [diff] [blame] | 1244 | ret = isolate_lru_page(page); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1245 | if (!ret) { /* Success */ |
Konstantin Khlebnikov | 700c2a4 | 2011-05-24 17:12:19 -0700 | [diff] [blame] | 1246 | put_page(page); |
Nick Piggin | 62695a8 | 2008-10-18 20:26:09 -0700 | [diff] [blame] | 1247 | list_add_tail(&page->lru, &source); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1248 | move_pages--; |
KOSAKI Motohiro | 6d9c285 | 2009-12-14 17:58:11 -0800 | [diff] [blame] | 1249 | inc_zone_page_state(page, NR_ISOLATED_ANON + |
| 1250 | page_is_file_cache(page)); |
| 1251 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1252 | } else { |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1253 | #ifdef CONFIG_DEBUG_VM |
Wu Fengguang | 718a382 | 2010-03-10 15:20:43 -0800 | [diff] [blame] | 1254 | printk(KERN_ALERT "removing pfn %lx from LRU failed\n", |
| 1255 | pfn); |
| 1256 | dump_page(page); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1257 | #endif |
Konstantin Khlebnikov | 700c2a4 | 2011-05-24 17:12:19 -0700 | [diff] [blame] | 1258 | put_page(page); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1259 | /* Because we don't have big zone->lock. we should |
Bob Liu | 809c444 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 1260 | check this again here. */ |
| 1261 | if (page_count(page)) { |
| 1262 | not_managed++; |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 1263 | ret = -EBUSY; |
Bob Liu | 809c444 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 1264 | break; |
| 1265 | } |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 1268 | if (!list_empty(&source)) { |
| 1269 | if (not_managed) { |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1270 | putback_lru_pages(&source); |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 1271 | goto out; |
| 1272 | } |
Minchan Kim | 74c08f9 | 2012-10-08 16:32:54 -0700 | [diff] [blame] | 1273 | |
| 1274 | /* |
| 1275 | * alloc_migrate_target should be improooooved!! |
| 1276 | * migrate_pages returns # of failed pages. |
| 1277 | */ |
| 1278 | ret = migrate_pages(&source, alloc_migrate_target, 0, |
Mel Gorman | 7b2a2d4 | 2012-10-19 14:07:31 +0100 | [diff] [blame] | 1279 | true, MIGRATE_SYNC, |
| 1280 | MR_MEMORY_HOTPLUG); |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 1281 | if (ret) |
| 1282 | putback_lru_pages(&source); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1283 | } |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1284 | out: |
| 1285 | return ret; |
| 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * remove from free_area[] and mark all as Reserved. |
| 1290 | */ |
| 1291 | static int |
| 1292 | offline_isolated_pages_cb(unsigned long start, unsigned long nr_pages, |
| 1293 | void *data) |
| 1294 | { |
| 1295 | __offline_isolated_pages(start, start + nr_pages); |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | static void |
| 1300 | offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) |
| 1301 | { |
KAMEZAWA Hiroyuki | 908eedc | 2009-09-22 16:45:46 -0700 | [diff] [blame] | 1302 | walk_system_ram_range(start_pfn, end_pfn - start_pfn, NULL, |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1303 | offline_isolated_pages_cb); |
| 1304 | } |
| 1305 | |
| 1306 | /* |
| 1307 | * Check all pages in range, recoreded as memory resource, are isolated. |
| 1308 | */ |
| 1309 | static int |
| 1310 | check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages, |
| 1311 | void *data) |
| 1312 | { |
| 1313 | int ret; |
| 1314 | long offlined = *(long *)data; |
Wen Congyang | b023f46 | 2012-12-11 16:00:45 -0800 | [diff] [blame] | 1315 | ret = test_pages_isolated(start_pfn, start_pfn + nr_pages, true); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1316 | offlined = nr_pages; |
| 1317 | if (!ret) |
| 1318 | *(long *)data += offlined; |
| 1319 | return ret; |
| 1320 | } |
| 1321 | |
| 1322 | static long |
| 1323 | check_pages_isolated(unsigned long start_pfn, unsigned long end_pfn) |
| 1324 | { |
| 1325 | long offlined = 0; |
| 1326 | int ret; |
| 1327 | |
KAMEZAWA Hiroyuki | 908eedc | 2009-09-22 16:45:46 -0700 | [diff] [blame] | 1328 | ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn, &offlined, |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1329 | check_pages_isolated_cb); |
| 1330 | if (ret < 0) |
| 1331 | offlined = (long)ret; |
| 1332 | return offlined; |
| 1333 | } |
| 1334 | |
Lai Jiangshan | 09285af | 2012-12-12 13:52:04 -0800 | [diff] [blame] | 1335 | #ifdef CONFIG_MOVABLE_NODE |
Tang Chen | 79a4dce | 2012-12-18 14:23:24 -0800 | [diff] [blame] | 1336 | /* |
| 1337 | * When CONFIG_MOVABLE_NODE, we permit offlining of a node which doesn't have |
| 1338 | * normal memory. |
| 1339 | */ |
Lai Jiangshan | 09285af | 2012-12-12 13:52:04 -0800 | [diff] [blame] | 1340 | static bool can_offline_normal(struct zone *zone, unsigned long nr_pages) |
| 1341 | { |
| 1342 | return true; |
| 1343 | } |
Tang Chen | 79a4dce | 2012-12-18 14:23:24 -0800 | [diff] [blame] | 1344 | #else /* CONFIG_MOVABLE_NODE */ |
Lai Jiangshan | 74d42d8 | 2012-12-11 16:03:23 -0800 | [diff] [blame] | 1345 | /* ensure the node has NORMAL memory if it is still online */ |
| 1346 | static bool can_offline_normal(struct zone *zone, unsigned long nr_pages) |
| 1347 | { |
| 1348 | struct pglist_data *pgdat = zone->zone_pgdat; |
| 1349 | unsigned long present_pages = 0; |
| 1350 | enum zone_type zt; |
| 1351 | |
| 1352 | for (zt = 0; zt <= ZONE_NORMAL; zt++) |
| 1353 | present_pages += pgdat->node_zones[zt].present_pages; |
| 1354 | |
| 1355 | if (present_pages > nr_pages) |
| 1356 | return true; |
| 1357 | |
| 1358 | present_pages = 0; |
| 1359 | for (; zt <= ZONE_MOVABLE; zt++) |
| 1360 | present_pages += pgdat->node_zones[zt].present_pages; |
| 1361 | |
| 1362 | /* |
| 1363 | * we can't offline the last normal memory until all |
| 1364 | * higher memory is offlined. |
| 1365 | */ |
| 1366 | return present_pages == 0; |
| 1367 | } |
Tang Chen | 79a4dce | 2012-12-18 14:23:24 -0800 | [diff] [blame] | 1368 | #endif /* CONFIG_MOVABLE_NODE */ |
Lai Jiangshan | 74d42d8 | 2012-12-11 16:03:23 -0800 | [diff] [blame] | 1369 | |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1370 | /* check which state of node_states will be changed when offline memory */ |
| 1371 | static void node_states_check_changes_offline(unsigned long nr_pages, |
| 1372 | struct zone *zone, struct memory_notify *arg) |
| 1373 | { |
| 1374 | struct pglist_data *pgdat = zone->zone_pgdat; |
| 1375 | unsigned long present_pages = 0; |
| 1376 | enum zone_type zt, zone_last = ZONE_NORMAL; |
| 1377 | |
| 1378 | /* |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 1379 | * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY] |
| 1380 | * contains nodes which have zones of 0...ZONE_NORMAL, |
| 1381 | * set zone_last to ZONE_NORMAL. |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1382 | * |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 1383 | * If we don't have HIGHMEM nor movable node, |
| 1384 | * node_states[N_NORMAL_MEMORY] contains nodes which have zones of |
| 1385 | * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE. |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1386 | */ |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 1387 | if (N_MEMORY == N_NORMAL_MEMORY) |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1388 | zone_last = ZONE_MOVABLE; |
| 1389 | |
| 1390 | /* |
| 1391 | * check whether node_states[N_NORMAL_MEMORY] will be changed. |
| 1392 | * If the memory to be offline is in a zone of 0...zone_last, |
| 1393 | * and it is the last present memory, 0...zone_last will |
| 1394 | * become empty after offline , thus we can determind we will |
| 1395 | * need to clear the node from node_states[N_NORMAL_MEMORY]. |
| 1396 | */ |
| 1397 | for (zt = 0; zt <= zone_last; zt++) |
| 1398 | present_pages += pgdat->node_zones[zt].present_pages; |
| 1399 | if (zone_idx(zone) <= zone_last && nr_pages >= present_pages) |
| 1400 | arg->status_change_nid_normal = zone_to_nid(zone); |
| 1401 | else |
| 1402 | arg->status_change_nid_normal = -1; |
| 1403 | |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 1404 | #ifdef CONFIG_HIGHMEM |
| 1405 | /* |
| 1406 | * If we have movable node, node_states[N_HIGH_MEMORY] |
| 1407 | * contains nodes which have zones of 0...ZONE_HIGHMEM, |
| 1408 | * set zone_last to ZONE_HIGHMEM. |
| 1409 | * |
| 1410 | * If we don't have movable node, node_states[N_NORMAL_MEMORY] |
| 1411 | * contains nodes which have zones of 0...ZONE_MOVABLE, |
| 1412 | * set zone_last to ZONE_MOVABLE. |
| 1413 | */ |
| 1414 | zone_last = ZONE_HIGHMEM; |
| 1415 | if (N_MEMORY == N_HIGH_MEMORY) |
| 1416 | zone_last = ZONE_MOVABLE; |
| 1417 | |
| 1418 | for (; zt <= zone_last; zt++) |
| 1419 | present_pages += pgdat->node_zones[zt].present_pages; |
| 1420 | if (zone_idx(zone) <= zone_last && nr_pages >= present_pages) |
| 1421 | arg->status_change_nid_high = zone_to_nid(zone); |
| 1422 | else |
| 1423 | arg->status_change_nid_high = -1; |
| 1424 | #else |
| 1425 | arg->status_change_nid_high = arg->status_change_nid_normal; |
| 1426 | #endif |
| 1427 | |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1428 | /* |
| 1429 | * node_states[N_HIGH_MEMORY] contains nodes which have 0...ZONE_MOVABLE |
| 1430 | */ |
| 1431 | zone_last = ZONE_MOVABLE; |
| 1432 | |
| 1433 | /* |
| 1434 | * check whether node_states[N_HIGH_MEMORY] will be changed |
| 1435 | * If we try to offline the last present @nr_pages from the node, |
| 1436 | * we can determind we will need to clear the node from |
| 1437 | * node_states[N_HIGH_MEMORY]. |
| 1438 | */ |
| 1439 | for (; zt <= zone_last; zt++) |
| 1440 | present_pages += pgdat->node_zones[zt].present_pages; |
| 1441 | if (nr_pages >= present_pages) |
| 1442 | arg->status_change_nid = zone_to_nid(zone); |
| 1443 | else |
| 1444 | arg->status_change_nid = -1; |
| 1445 | } |
| 1446 | |
| 1447 | static void node_states_clear_node(int node, struct memory_notify *arg) |
| 1448 | { |
| 1449 | if (arg->status_change_nid_normal >= 0) |
| 1450 | node_clear_state(node, N_NORMAL_MEMORY); |
| 1451 | |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 1452 | if ((N_MEMORY != N_NORMAL_MEMORY) && |
| 1453 | (arg->status_change_nid_high >= 0)) |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1454 | node_clear_state(node, N_HIGH_MEMORY); |
Lai Jiangshan | 6715ddf | 2012-12-12 13:51:49 -0800 | [diff] [blame] | 1455 | |
| 1456 | if ((N_MEMORY != N_HIGH_MEMORY) && |
| 1457 | (arg->status_change_nid >= 0)) |
| 1458 | node_clear_state(node, N_MEMORY); |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
Wen Congyang | a16cee1 | 2012-10-08 16:33:58 -0700 | [diff] [blame] | 1461 | static int __ref __offline_pages(unsigned long start_pfn, |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1462 | unsigned long end_pfn, unsigned long timeout) |
| 1463 | { |
| 1464 | unsigned long pfn, nr_pages, expire; |
| 1465 | long offlined_pages; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1466 | int ret, drain, retry_max, node; |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1467 | struct zone *zone; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1468 | struct memory_notify arg; |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1469 | |
| 1470 | BUG_ON(start_pfn >= end_pfn); |
| 1471 | /* at least, alignment against pageblock is necessary */ |
| 1472 | if (!IS_ALIGNED(start_pfn, pageblock_nr_pages)) |
| 1473 | return -EINVAL; |
| 1474 | if (!IS_ALIGNED(end_pfn, pageblock_nr_pages)) |
| 1475 | return -EINVAL; |
| 1476 | /* This makes hotplug much easier...and readable. |
| 1477 | we assume this for now. .*/ |
| 1478 | if (!test_pages_in_a_zone(start_pfn, end_pfn)) |
| 1479 | return -EINVAL; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1480 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 1481 | lock_memory_hotplug(); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1482 | |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1483 | zone = page_zone(pfn_to_page(start_pfn)); |
| 1484 | node = zone_to_nid(zone); |
| 1485 | nr_pages = end_pfn - start_pfn; |
| 1486 | |
Lai Jiangshan | 74d42d8 | 2012-12-11 16:03:23 -0800 | [diff] [blame] | 1487 | ret = -EINVAL; |
| 1488 | if (zone_idx(zone) <= ZONE_NORMAL && !can_offline_normal(zone, nr_pages)) |
| 1489 | goto out; |
| 1490 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1491 | /* set above range as isolated */ |
Wen Congyang | b023f46 | 2012-12-11 16:00:45 -0800 | [diff] [blame] | 1492 | ret = start_isolate_page_range(start_pfn, end_pfn, |
| 1493 | MIGRATE_MOVABLE, true); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1494 | if (ret) |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1495 | goto out; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1496 | |
| 1497 | arg.start_pfn = start_pfn; |
| 1498 | arg.nr_pages = nr_pages; |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1499 | node_states_check_changes_offline(nr_pages, zone, &arg); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1500 | |
| 1501 | ret = memory_notify(MEM_GOING_OFFLINE, &arg); |
| 1502 | ret = notifier_to_errno(ret); |
| 1503 | if (ret) |
| 1504 | goto failed_removal; |
| 1505 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1506 | pfn = start_pfn; |
| 1507 | expire = jiffies + timeout; |
| 1508 | drain = 0; |
| 1509 | retry_max = 5; |
| 1510 | repeat: |
| 1511 | /* start memory hot removal */ |
| 1512 | ret = -EAGAIN; |
| 1513 | if (time_after(jiffies, expire)) |
| 1514 | goto failed_removal; |
| 1515 | ret = -EINTR; |
| 1516 | if (signal_pending(current)) |
| 1517 | goto failed_removal; |
| 1518 | ret = 0; |
| 1519 | if (drain) { |
| 1520 | lru_add_drain_all(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1521 | cond_resched(); |
Christoph Lameter | 9f8f217 | 2008-02-04 22:29:11 -0800 | [diff] [blame] | 1522 | drain_all_pages(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | pfn = scan_lru_pages(start_pfn, end_pfn); |
| 1526 | if (pfn) { /* We have page on LRU */ |
| 1527 | ret = do_migrate_range(pfn, end_pfn); |
| 1528 | if (!ret) { |
| 1529 | drain = 1; |
| 1530 | goto repeat; |
| 1531 | } else { |
| 1532 | if (ret < 0) |
| 1533 | if (--retry_max == 0) |
| 1534 | goto failed_removal; |
| 1535 | yield(); |
| 1536 | drain = 1; |
| 1537 | goto repeat; |
| 1538 | } |
| 1539 | } |
Adam Buchbinder | b3834be | 2012-09-19 21:48:02 -0400 | [diff] [blame] | 1540 | /* drain all zone's lru pagevec, this is asynchronous... */ |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1541 | lru_add_drain_all(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1542 | yield(); |
Adam Buchbinder | b3834be | 2012-09-19 21:48:02 -0400 | [diff] [blame] | 1543 | /* drain pcp pages, this is synchronous. */ |
Christoph Lameter | 9f8f217 | 2008-02-04 22:29:11 -0800 | [diff] [blame] | 1544 | drain_all_pages(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1545 | /* check again */ |
| 1546 | offlined_pages = check_pages_isolated(start_pfn, end_pfn); |
| 1547 | if (offlined_pages < 0) { |
| 1548 | ret = -EBUSY; |
| 1549 | goto failed_removal; |
| 1550 | } |
| 1551 | printk(KERN_INFO "Offlined Pages %ld\n", offlined_pages); |
Adam Buchbinder | b3834be | 2012-09-19 21:48:02 -0400 | [diff] [blame] | 1552 | /* Ok, all of our target is isolated. |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1553 | We cannot do rollback at this point. */ |
| 1554 | offline_isolated_pages(start_pfn, end_pfn); |
KAMEZAWA Hiroyuki | dbc0e4c | 2007-11-14 16:59:12 -0800 | [diff] [blame] | 1555 | /* reset pagetype flags and makes migrate type to be MOVABLE */ |
Michal Nazarewicz | 0815f3d | 2012-04-03 15:06:15 +0200 | [diff] [blame] | 1556 | undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1557 | /* removal success */ |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 1558 | zone->managed_pages -= offlined_pages; |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1559 | zone->present_pages -= offlined_pages; |
| 1560 | zone->zone_pgdat->node_present_pages -= offlined_pages; |
| 1561 | totalram_pages -= offlined_pages; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1562 | |
KOSAKI Motohiro | 1b79acc | 2011-05-24 17:11:32 -0700 | [diff] [blame] | 1563 | init_per_zone_wmark_min(); |
| 1564 | |
Xishi Qiu | 1e8537b | 2012-10-08 16:31:51 -0700 | [diff] [blame] | 1565 | if (!populated_zone(zone)) { |
Jiang Liu | 340175b | 2012-07-31 16:43:32 -0700 | [diff] [blame] | 1566 | zone_pcp_reset(zone); |
Xishi Qiu | 1e8537b | 2012-10-08 16:31:51 -0700 | [diff] [blame] | 1567 | mutex_lock(&zonelists_mutex); |
| 1568 | build_all_zonelists(NULL, NULL); |
| 1569 | mutex_unlock(&zonelists_mutex); |
| 1570 | } else |
| 1571 | zone_pcp_update(zone); |
Jiang Liu | 340175b | 2012-07-31 16:43:32 -0700 | [diff] [blame] | 1572 | |
Lai Jiangshan | d971367 | 2012-12-11 16:01:03 -0800 | [diff] [blame] | 1573 | node_states_clear_node(node, &arg); |
| 1574 | if (arg.status_change_nid >= 0) |
David Rientjes | 8fe23e0 | 2009-12-14 17:58:33 -0800 | [diff] [blame] | 1575 | kswapd_stop(node); |
Minchan Kim | bce7394 | 2009-06-16 15:32:50 -0700 | [diff] [blame] | 1576 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1577 | vm_total_pages = nr_free_pagecache_pages(); |
| 1578 | writeback_set_ratelimit(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1579 | |
| 1580 | memory_notify(MEM_OFFLINE, &arg); |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 1581 | unlock_memory_hotplug(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1582 | return 0; |
| 1583 | |
| 1584 | failed_removal: |
Bjorn Helgaas | a62e2f4 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 1585 | printk(KERN_INFO "memory offlining [mem %#010llx-%#010llx] failed\n", |
| 1586 | (unsigned long long) start_pfn << PAGE_SHIFT, |
| 1587 | ((unsigned long long) end_pfn << PAGE_SHIFT) - 1); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1588 | memory_notify(MEM_CANCEL_OFFLINE, &arg); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1589 | /* pushback to free area */ |
Michal Nazarewicz | 0815f3d | 2012-04-03 15:06:15 +0200 | [diff] [blame] | 1590 | undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 1591 | |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 1592 | out: |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 1593 | unlock_memory_hotplug(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1594 | return ret; |
| 1595 | } |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 1596 | |
Wen Congyang | a16cee1 | 2012-10-08 16:33:58 -0700 | [diff] [blame] | 1597 | int offline_pages(unsigned long start_pfn, unsigned long nr_pages) |
| 1598 | { |
| 1599 | return __offline_pages(start_pfn, start_pfn + nr_pages, 120 * HZ); |
| 1600 | } |
| 1601 | |
Wen Congyang | bbc76be | 2013-02-22 16:32:54 -0800 | [diff] [blame] | 1602 | /** |
| 1603 | * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn) |
| 1604 | * @start_pfn: start pfn of the memory range |
| 1605 | * @end_pfn: end pft of the memory range |
| 1606 | * @arg: argument passed to func |
| 1607 | * @func: callback for each memory section walked |
| 1608 | * |
| 1609 | * This function walks through all present mem sections in range |
| 1610 | * [start_pfn, end_pfn) and call func on each mem section. |
| 1611 | * |
| 1612 | * Returns the return value of func. |
| 1613 | */ |
| 1614 | static int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, |
| 1615 | void *arg, int (*func)(struct memory_block *, void *)) |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 1616 | { |
Wen Congyang | e90bdb7 | 2012-10-08 16:34:01 -0700 | [diff] [blame] | 1617 | struct memory_block *mem = NULL; |
| 1618 | struct mem_section *section; |
Wen Congyang | e90bdb7 | 2012-10-08 16:34:01 -0700 | [diff] [blame] | 1619 | unsigned long pfn, section_nr; |
| 1620 | int ret; |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 1621 | |
Wen Congyang | e90bdb7 | 2012-10-08 16:34:01 -0700 | [diff] [blame] | 1622 | for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { |
| 1623 | section_nr = pfn_to_section_nr(pfn); |
| 1624 | if (!present_section_nr(section_nr)) |
| 1625 | continue; |
| 1626 | |
| 1627 | section = __nr_to_section(section_nr); |
| 1628 | /* same memblock? */ |
| 1629 | if (mem) |
| 1630 | if ((section_nr >= mem->start_section_nr) && |
| 1631 | (section_nr <= mem->end_section_nr)) |
| 1632 | continue; |
| 1633 | |
| 1634 | mem = find_memory_block_hinted(section, mem); |
| 1635 | if (!mem) |
| 1636 | continue; |
| 1637 | |
Wen Congyang | bbc76be | 2013-02-22 16:32:54 -0800 | [diff] [blame] | 1638 | ret = func(mem, arg); |
Wen Congyang | e90bdb7 | 2012-10-08 16:34:01 -0700 | [diff] [blame] | 1639 | if (ret) { |
Wen Congyang | bbc76be | 2013-02-22 16:32:54 -0800 | [diff] [blame] | 1640 | kobject_put(&mem->dev.kobj); |
| 1641 | return ret; |
Wen Congyang | e90bdb7 | 2012-10-08 16:34:01 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | if (mem) |
| 1646 | kobject_put(&mem->dev.kobj); |
| 1647 | |
Wen Congyang | bbc76be | 2013-02-22 16:32:54 -0800 | [diff] [blame] | 1648 | return 0; |
| 1649 | } |
| 1650 | |
| 1651 | /** |
| 1652 | * offline_memory_block_cb - callback function for offlining memory block |
| 1653 | * @mem: the memory block to be offlined |
| 1654 | * @arg: buffer to hold error msg |
| 1655 | * |
| 1656 | * Always return 0, and put the error msg in arg if any. |
| 1657 | */ |
| 1658 | static int offline_memory_block_cb(struct memory_block *mem, void *arg) |
| 1659 | { |
| 1660 | int *ret = arg; |
| 1661 | int error = offline_memory_block(mem); |
| 1662 | |
| 1663 | if (error != 0 && *ret == 0) |
| 1664 | *ret = error; |
| 1665 | |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
| 1669 | static int is_memblock_offlined_cb(struct memory_block *mem, void *arg) |
| 1670 | { |
| 1671 | int ret = !is_memblock_offlined(mem); |
| 1672 | |
| 1673 | if (unlikely(ret)) |
| 1674 | pr_warn("removing memory fails, because memory " |
| 1675 | "[%#010llx-%#010llx] is onlined\n", |
| 1676 | PFN_PHYS(section_nr_to_pfn(mem->start_section_nr)), |
| 1677 | PFN_PHYS(section_nr_to_pfn(mem->end_section_nr + 1))-1); |
| 1678 | |
| 1679 | return ret; |
| 1680 | } |
| 1681 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 1682 | int __ref remove_memory(u64 start, u64 size) |
Wen Congyang | bbc76be | 2013-02-22 16:32:54 -0800 | [diff] [blame] | 1683 | { |
| 1684 | unsigned long start_pfn, end_pfn; |
| 1685 | int ret = 0; |
| 1686 | int retry = 1; |
| 1687 | |
| 1688 | start_pfn = PFN_DOWN(start); |
| 1689 | end_pfn = start_pfn + PFN_DOWN(size); |
| 1690 | |
| 1691 | /* |
| 1692 | * When CONFIG_MEMCG is on, one memory block may be used by other |
| 1693 | * blocks to store page cgroup when onlining pages. But we don't know |
| 1694 | * in what order pages are onlined. So we iterate twice to offline |
| 1695 | * memory: |
| 1696 | * 1st iterate: offline every non primary memory block. |
| 1697 | * 2nd iterate: offline primary (i.e. first added) memory block. |
| 1698 | */ |
| 1699 | repeat: |
| 1700 | walk_memory_range(start_pfn, end_pfn, &ret, |
| 1701 | offline_memory_block_cb); |
| 1702 | if (ret) { |
| 1703 | if (!retry) |
| 1704 | return ret; |
| 1705 | |
| 1706 | retry = 0; |
| 1707 | ret = 0; |
Wen Congyang | 993c1aa | 2013-02-22 16:32:50 -0800 | [diff] [blame] | 1708 | goto repeat; |
| 1709 | } |
| 1710 | |
Yasuaki Ishimatsu | 6677e3e | 2013-02-22 16:32:52 -0800 | [diff] [blame] | 1711 | lock_memory_hotplug(); |
| 1712 | |
| 1713 | /* |
| 1714 | * we have offlined all memory blocks like this: |
| 1715 | * 1. lock memory hotplug |
| 1716 | * 2. offline a memory block |
| 1717 | * 3. unlock memory hotplug |
| 1718 | * |
| 1719 | * repeat step1-3 to offline the memory block. All memory blocks |
| 1720 | * must be offlined before removing memory. But we don't hold the |
| 1721 | * lock in the whole operation. So we should check whether all |
| 1722 | * memory blocks are offlined. |
| 1723 | */ |
| 1724 | |
Wen Congyang | bbc76be | 2013-02-22 16:32:54 -0800 | [diff] [blame] | 1725 | ret = walk_memory_range(start_pfn, end_pfn, NULL, |
| 1726 | is_memblock_offlined_cb); |
| 1727 | if (ret) { |
| 1728 | unlock_memory_hotplug(); |
| 1729 | return ret; |
Yasuaki Ishimatsu | 6677e3e | 2013-02-22 16:32:52 -0800 | [diff] [blame] | 1730 | } |
| 1731 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 1732 | /* remove memmap entry */ |
| 1733 | firmware_map_remove(start, start + size, "System RAM"); |
| 1734 | |
Wen Congyang | 24d335c | 2013-02-22 16:32:58 -0800 | [diff] [blame] | 1735 | arch_remove_memory(start, size); |
| 1736 | |
Yasuaki Ishimatsu | 6677e3e | 2013-02-22 16:32:52 -0800 | [diff] [blame] | 1737 | unlock_memory_hotplug(); |
| 1738 | |
Wen Congyang | e90bdb7 | 2012-10-08 16:34:01 -0700 | [diff] [blame] | 1739 | return 0; |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 1740 | } |
KAMEZAWA Hiroyuki | 48e9419 | 2007-10-16 01:26:14 -0700 | [diff] [blame] | 1741 | #else |
Wen Congyang | a16cee1 | 2012-10-08 16:33:58 -0700 | [diff] [blame] | 1742 | int offline_pages(unsigned long start_pfn, unsigned long nr_pages) |
| 1743 | { |
| 1744 | return -EINVAL; |
| 1745 | } |
KAMEZAWA Hiroyuki | 48e9419 | 2007-10-16 01:26:14 -0700 | [diff] [blame] | 1746 | int remove_memory(u64 start, u64 size) |
| 1747 | { |
| 1748 | return -EINVAL; |
| 1749 | } |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1750 | #endif /* CONFIG_MEMORY_HOTREMOVE */ |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 1751 | EXPORT_SYMBOL_GPL(remove_memory); |