]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - mm/memory_hotplug.c
UBUNTU: [Config] CONFIG_TI_ADC108S102=m
[mirror_ubuntu-artful-kernel.git] / mm / memory_hotplug.c
1 /*
2 * linux/mm/memory_hotplug.c
3 *
4 * Copyright (C)
5 */
6
7 #include <linux/stddef.h>
8 #include <linux/mm.h>
9 #include <linux/sched/signal.h>
10 #include <linux/swap.h>
11 #include <linux/interrupt.h>
12 #include <linux/pagemap.h>
13 #include <linux/compiler.h>
14 #include <linux/export.h>
15 #include <linux/pagevec.h>
16 #include <linux/writeback.h>
17 #include <linux/slab.h>
18 #include <linux/sysctl.h>
19 #include <linux/cpu.h>
20 #include <linux/memory.h>
21 #include <linux/memremap.h>
22 #include <linux/memory_hotplug.h>
23 #include <linux/highmem.h>
24 #include <linux/vmalloc.h>
25 #include <linux/ioport.h>
26 #include <linux/delay.h>
27 #include <linux/migrate.h>
28 #include <linux/page-isolation.h>
29 #include <linux/pfn.h>
30 #include <linux/suspend.h>
31 #include <linux/mm_inline.h>
32 #include <linux/firmware-map.h>
33 #include <linux/stop_machine.h>
34 #include <linux/hugetlb.h>
35 #include <linux/memblock.h>
36 #include <linux/bootmem.h>
37 #include <linux/compaction.h>
38
39 #include <asm/tlbflush.h>
40
41 #include "internal.h"
42
43 /*
44 * online_page_callback contains pointer to current page onlining function.
45 * Initially it is generic_online_page(). If it is required it could be
46 * changed by calling set_online_page_callback() for callback registration
47 * and restore_online_page_callback() for generic callback restore.
48 */
49
50 static void generic_online_page(struct page *page);
51
52 static online_page_callback_t online_page_callback = generic_online_page;
53 static DEFINE_MUTEX(online_page_callback_lock);
54
55 DEFINE_STATIC_PERCPU_RWSEM(mem_hotplug_lock);
56
57 void get_online_mems(void)
58 {
59 percpu_down_read(&mem_hotplug_lock);
60 }
61
62 void put_online_mems(void)
63 {
64 percpu_up_read(&mem_hotplug_lock);
65 }
66
67 bool movable_node_enabled = false;
68
69 #ifndef CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE
70 bool memhp_auto_online;
71 #else
72 bool memhp_auto_online = true;
73 #endif
74 EXPORT_SYMBOL_GPL(memhp_auto_online);
75
76 static int __init setup_memhp_default_state(char *str)
77 {
78 if (!strcmp(str, "online"))
79 memhp_auto_online = true;
80 else if (!strcmp(str, "offline"))
81 memhp_auto_online = false;
82
83 return 1;
84 }
85 __setup("memhp_default_state=", setup_memhp_default_state);
86
87 void mem_hotplug_begin(void)
88 {
89 cpus_read_lock();
90 percpu_down_write(&mem_hotplug_lock);
91 }
92
93 void mem_hotplug_done(void)
94 {
95 percpu_up_write(&mem_hotplug_lock);
96 cpus_read_unlock();
97 }
98
99 /* add this memory to iomem resource */
100 static struct resource *register_memory_resource(u64 start, u64 size)
101 {
102 struct resource *res;
103 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
104 if (!res)
105 return ERR_PTR(-ENOMEM);
106
107 res->name = "System RAM";
108 res->start = start;
109 res->end = start + size - 1;
110 res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
111 if (request_resource(&iomem_resource, res) < 0) {
112 pr_debug("System RAM resource %pR cannot be added\n", res);
113 kfree(res);
114 return ERR_PTR(-EEXIST);
115 }
116 return res;
117 }
118
119 static void release_memory_resource(struct resource *res)
120 {
121 if (!res)
122 return;
123 release_resource(res);
124 kfree(res);
125 return;
126 }
127
128 #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
129 void get_page_bootmem(unsigned long info, struct page *page,
130 unsigned long type)
131 {
132 page->freelist = (void *)type;
133 SetPagePrivate(page);
134 set_page_private(page, info);
135 page_ref_inc(page);
136 }
137
138 void put_page_bootmem(struct page *page)
139 {
140 unsigned long type;
141
142 type = (unsigned long) page->freelist;
143 BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE ||
144 type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);
145
146 if (page_ref_dec_return(page) == 1) {
147 page->freelist = NULL;
148 ClearPagePrivate(page);
149 set_page_private(page, 0);
150 INIT_LIST_HEAD(&page->lru);
151 free_reserved_page(page);
152 }
153 }
154
155 #ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
156 #ifndef CONFIG_SPARSEMEM_VMEMMAP
157 static void register_page_bootmem_info_section(unsigned long start_pfn)
158 {
159 unsigned long *usemap, mapsize, section_nr, i;
160 struct mem_section *ms;
161 struct page *page, *memmap;
162
163 section_nr = pfn_to_section_nr(start_pfn);
164 ms = __nr_to_section(section_nr);
165
166 /* Get section's memmap address */
167 memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
168
169 /*
170 * Get page for the memmap's phys address
171 * XXX: need more consideration for sparse_vmemmap...
172 */
173 page = virt_to_page(memmap);
174 mapsize = sizeof(struct page) * PAGES_PER_SECTION;
175 mapsize = PAGE_ALIGN(mapsize) >> PAGE_SHIFT;
176
177 /* remember memmap's page */
178 for (i = 0; i < mapsize; i++, page++)
179 get_page_bootmem(section_nr, page, SECTION_INFO);
180
181 usemap = __nr_to_section(section_nr)->pageblock_flags;
182 page = virt_to_page(usemap);
183
184 mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT;
185
186 for (i = 0; i < mapsize; i++, page++)
187 get_page_bootmem(section_nr, page, MIX_SECTION_INFO);
188
189 }
190 #else /* CONFIG_SPARSEMEM_VMEMMAP */
191 static void register_page_bootmem_info_section(unsigned long start_pfn)
192 {
193 unsigned long *usemap, mapsize, section_nr, i;
194 struct mem_section *ms;
195 struct page *page, *memmap;
196
197 if (!pfn_valid(start_pfn))
198 return;
199
200 section_nr = pfn_to_section_nr(start_pfn);
201 ms = __nr_to_section(section_nr);
202
203 memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
204
205 register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION);
206
207 usemap = __nr_to_section(section_nr)->pageblock_flags;
208 page = virt_to_page(usemap);
209
210 mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT;
211
212 for (i = 0; i < mapsize; i++, page++)
213 get_page_bootmem(section_nr, page, MIX_SECTION_INFO);
214 }
215 #endif /* !CONFIG_SPARSEMEM_VMEMMAP */
216
217 void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
218 {
219 unsigned long i, pfn, end_pfn, nr_pages;
220 int node = pgdat->node_id;
221 struct page *page;
222
223 nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
224 page = virt_to_page(pgdat);
225
226 for (i = 0; i < nr_pages; i++, page++)
227 get_page_bootmem(node, page, NODE_INFO);
228
229 pfn = pgdat->node_start_pfn;
230 end_pfn = pgdat_end_pfn(pgdat);
231
232 /* register section info */
233 for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
234 /*
235 * Some platforms can assign the same pfn to multiple nodes - on
236 * node0 as well as nodeN. To avoid registering a pfn against
237 * multiple nodes we check that this pfn does not already
238 * reside in some other nodes.
239 */
240 if (pfn_valid(pfn) && (early_pfn_to_nid(pfn) == node))
241 register_page_bootmem_info_section(pfn);
242 }
243 }
244 #endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */
245
246 static void __meminit grow_zone_span(struct zone *zone, unsigned long start_pfn,
247 unsigned long end_pfn)
248 {
249 unsigned long old_zone_end_pfn;
250
251 zone_span_writelock(zone);
252
253 old_zone_end_pfn = zone_end_pfn(zone);
254 if (zone_is_empty(zone) || start_pfn < zone->zone_start_pfn)
255 zone->zone_start_pfn = start_pfn;
256
257 zone->spanned_pages = max(old_zone_end_pfn, end_pfn) -
258 zone->zone_start_pfn;
259
260 zone_span_writeunlock(zone);
261 }
262
263 static void resize_zone(struct zone *zone, unsigned long start_pfn,
264 unsigned long end_pfn)
265 {
266 zone_span_writelock(zone);
267
268 if (end_pfn - start_pfn) {
269 zone->zone_start_pfn = start_pfn;
270 zone->spanned_pages = end_pfn - start_pfn;
271 } else {
272 /*
273 * make it consist as free_area_init_core(),
274 * if spanned_pages = 0, then keep start_pfn = 0
275 */
276 zone->zone_start_pfn = 0;
277 zone->spanned_pages = 0;
278 }
279
280 zone_span_writeunlock(zone);
281 }
282
283 static void fix_zone_id(struct zone *zone, unsigned long start_pfn,
284 unsigned long end_pfn)
285 {
286 enum zone_type zid = zone_idx(zone);
287 int nid = zone->zone_pgdat->node_id;
288 unsigned long pfn;
289
290 for (pfn = start_pfn; pfn < end_pfn; pfn++)
291 set_page_links(pfn_to_page(pfn), zid, nid, pfn);
292 }
293
294 static void __ref ensure_zone_is_initialized(struct zone *zone,
295 unsigned long start_pfn, unsigned long num_pages)
296 {
297 if (!zone_is_initialized(zone))
298 init_currently_empty_zone(zone, start_pfn, num_pages);
299 }
300
301 static int __meminit move_pfn_range_left(struct zone *z1, struct zone *z2,
302 unsigned long start_pfn, unsigned long end_pfn)
303 {
304 unsigned long flags;
305 unsigned long z1_start_pfn;
306
307 ensure_zone_is_initialized(z1, start_pfn, end_pfn - start_pfn);
308
309 pgdat_resize_lock(z1->zone_pgdat, &flags);
310
311 /* can't move pfns which are higher than @z2 */
312 if (end_pfn > zone_end_pfn(z2))
313 goto out_fail;
314 /* the move out part must be at the left most of @z2 */
315 if (start_pfn > z2->zone_start_pfn)
316 goto out_fail;
317 /* must included/overlap */
318 if (end_pfn <= z2->zone_start_pfn)
319 goto out_fail;
320
321 /* use start_pfn for z1's start_pfn if z1 is empty */
322 if (!zone_is_empty(z1))
323 z1_start_pfn = z1->zone_start_pfn;
324 else
325 z1_start_pfn = start_pfn;
326
327 resize_zone(z1, z1_start_pfn, end_pfn);
328 resize_zone(z2, end_pfn, zone_end_pfn(z2));
329
330 pgdat_resize_unlock(z1->zone_pgdat, &flags);
331
332 fix_zone_id(z1, start_pfn, end_pfn);
333
334 return 0;
335 out_fail:
336 pgdat_resize_unlock(z1->zone_pgdat, &flags);
337 return -1;
338 }
339
340 static int __meminit move_pfn_range_right(struct zone *z1, struct zone *z2,
341 unsigned long start_pfn, unsigned long end_pfn)
342 {
343 unsigned long flags;
344 unsigned long z2_end_pfn;
345
346 ensure_zone_is_initialized(z2, start_pfn, end_pfn - start_pfn);
347
348 pgdat_resize_lock(z1->zone_pgdat, &flags);
349
350 /* can't move pfns which are lower than @z1 */
351 if (z1->zone_start_pfn > start_pfn)
352 goto out_fail;
353 /* the move out part mast at the right most of @z1 */
354 if (zone_end_pfn(z1) > end_pfn)
355 goto out_fail;
356 /* must included/overlap */
357 if (start_pfn >= zone_end_pfn(z1))
358 goto out_fail;
359
360 /* use end_pfn for z2's end_pfn if z2 is empty */
361 if (!zone_is_empty(z2))
362 z2_end_pfn = zone_end_pfn(z2);
363 else
364 z2_end_pfn = end_pfn;
365
366 resize_zone(z1, z1->zone_start_pfn, start_pfn);
367 resize_zone(z2, start_pfn, z2_end_pfn);
368
369 pgdat_resize_unlock(z1->zone_pgdat, &flags);
370
371 fix_zone_id(z2, start_pfn, end_pfn);
372
373 return 0;
374 out_fail:
375 pgdat_resize_unlock(z1->zone_pgdat, &flags);
376 return -1;
377 }
378
379 static struct zone * __meminit move_pfn_range(int zone_shift,
380 unsigned long start_pfn, unsigned long end_pfn)
381 {
382 struct zone *zone = page_zone(pfn_to_page(start_pfn));
383 int ret = 0;
384
385 if (zone_shift < 0)
386 ret = move_pfn_range_left(zone + zone_shift, zone,
387 start_pfn, end_pfn);
388 else if (zone_shift)
389 ret = move_pfn_range_right(zone, zone + zone_shift,
390 start_pfn, end_pfn);
391
392 if (ret)
393 return NULL;
394
395 return zone + zone_shift;
396 }
397
398 static void __meminit grow_pgdat_span(struct pglist_data *pgdat, unsigned long start_pfn,
399 unsigned long end_pfn)
400 {
401 unsigned long old_pgdat_end_pfn = pgdat_end_pfn(pgdat);
402
403 if (!pgdat->node_spanned_pages || start_pfn < pgdat->node_start_pfn)
404 pgdat->node_start_pfn = start_pfn;
405
406 pgdat->node_spanned_pages = max(old_pgdat_end_pfn, end_pfn) -
407 pgdat->node_start_pfn;
408 }
409
410 static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
411 {
412 struct pglist_data *pgdat = zone->zone_pgdat;
413 int nr_pages = PAGES_PER_SECTION;
414 int nid = pgdat->node_id;
415 int zone_type;
416 unsigned long flags, pfn;
417
418 zone_type = zone - pgdat->node_zones;
419 ensure_zone_is_initialized(zone, phys_start_pfn, nr_pages);
420
421 pgdat_resize_lock(zone->zone_pgdat, &flags);
422 grow_zone_span(zone, phys_start_pfn, phys_start_pfn + nr_pages);
423 grow_pgdat_span(zone->zone_pgdat, phys_start_pfn,
424 phys_start_pfn + nr_pages);
425 pgdat_resize_unlock(zone->zone_pgdat, &flags);
426 memmap_init_zone(nr_pages, nid, zone_type,
427 phys_start_pfn, MEMMAP_HOTPLUG);
428
429 /* online_page_range is called later and expects pages reserved */
430 for (pfn = phys_start_pfn; pfn < phys_start_pfn + nr_pages; pfn++) {
431 if (!pfn_valid(pfn))
432 continue;
433
434 SetPageReserved(pfn_to_page(pfn));
435 }
436 return 0;
437 }
438
439 static int __meminit __add_section(int nid, struct zone *zone,
440 unsigned long phys_start_pfn, bool want_memblock)
441 {
442 int ret;
443
444 if (pfn_valid(phys_start_pfn))
445 return -EEXIST;
446
447 ret = sparse_add_one_section(zone, phys_start_pfn);
448
449 if (ret < 0)
450 return ret;
451
452 ret = __add_zone(zone, phys_start_pfn);
453
454 if (ret < 0)
455 return ret;
456
457 if (!want_memblock)
458 return 0;
459
460 return register_new_memory(nid, __pfn_to_section(phys_start_pfn));
461 }
462
463 /*
464 * Reasonably generic function for adding memory. It is
465 * expected that archs that support memory hotplug will
466 * call this function after deciding the zone to which to
467 * add the new pages.
468 */
469 int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn,
470 unsigned long nr_pages, bool want_memblock)
471 {
472 unsigned long i;
473 int err = 0;
474 int start_sec, end_sec;
475 struct vmem_altmap *altmap;
476
477 clear_zone_contiguous(zone);
478
479 /* during initialize mem_map, align hot-added range to section */
480 start_sec = pfn_to_section_nr(phys_start_pfn);
481 end_sec = pfn_to_section_nr(phys_start_pfn + nr_pages - 1);
482
483 altmap = to_vmem_altmap((unsigned long) pfn_to_page(phys_start_pfn));
484 if (altmap) {
485 /*
486 * Validate altmap is within bounds of the total request
487 */
488 if (altmap->base_pfn != phys_start_pfn
489 || vmem_altmap_offset(altmap) > nr_pages) {
490 pr_warn_once("memory add fail, invalid altmap\n");
491 err = -EINVAL;
492 goto out;
493 }
494 altmap->alloc = 0;
495 }
496
497 for (i = start_sec; i <= end_sec; i++) {
498 err = __add_section(nid, zone, section_nr_to_pfn(i), want_memblock);
499
500 /*
501 * EEXIST is finally dealt with by ioresource collision
502 * check. see add_memory() => register_memory_resource()
503 * Warning will be printed if there is collision.
504 */
505 if (err && (err != -EEXIST))
506 break;
507 err = 0;
508 }
509 vmemmap_populate_print_last();
510 out:
511 set_zone_contiguous(zone);
512 return err;
513 }
514 EXPORT_SYMBOL_GPL(__add_pages);
515
516 #ifdef CONFIG_MEMORY_HOTREMOVE
517 /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
518 static int find_smallest_section_pfn(int nid, struct zone *zone,
519 unsigned long start_pfn,
520 unsigned long end_pfn)
521 {
522 struct mem_section *ms;
523
524 for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) {
525 ms = __pfn_to_section(start_pfn);
526
527 if (unlikely(!valid_section(ms)))
528 continue;
529
530 if (unlikely(pfn_to_nid(start_pfn) != nid))
531 continue;
532
533 if (zone && zone != page_zone(pfn_to_page(start_pfn)))
534 continue;
535
536 return start_pfn;
537 }
538
539 return 0;
540 }
541
542 /* find the biggest valid pfn in the range [start_pfn, end_pfn). */
543 static int find_biggest_section_pfn(int nid, struct zone *zone,
544 unsigned long start_pfn,
545 unsigned long end_pfn)
546 {
547 struct mem_section *ms;
548 unsigned long pfn;
549
550 /* pfn is the end pfn of a memory section. */
551 pfn = end_pfn - 1;
552 for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) {
553 ms = __pfn_to_section(pfn);
554
555 if (unlikely(!valid_section(ms)))
556 continue;
557
558 if (unlikely(pfn_to_nid(pfn) != nid))
559 continue;
560
561 if (zone && zone != page_zone(pfn_to_page(pfn)))
562 continue;
563
564 return pfn;
565 }
566
567 return 0;
568 }
569
570 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
571 unsigned long end_pfn)
572 {
573 unsigned long zone_start_pfn = zone->zone_start_pfn;
574 unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */
575 unsigned long zone_end_pfn = z;
576 unsigned long pfn;
577 struct mem_section *ms;
578 int nid = zone_to_nid(zone);
579
580 zone_span_writelock(zone);
581 if (zone_start_pfn == start_pfn) {
582 /*
583 * If the section is smallest section in the zone, it need
584 * shrink zone->zone_start_pfn and zone->zone_spanned_pages.
585 * In this case, we find second smallest valid mem_section
586 * for shrinking zone.
587 */
588 pfn = find_smallest_section_pfn(nid, zone, end_pfn,
589 zone_end_pfn);
590 if (pfn) {
591 zone->zone_start_pfn = pfn;
592 zone->spanned_pages = zone_end_pfn - pfn;
593 }
594 } else if (zone_end_pfn == end_pfn) {
595 /*
596 * If the section is biggest section in the zone, it need
597 * shrink zone->spanned_pages.
598 * In this case, we find second biggest valid mem_section for
599 * shrinking zone.
600 */
601 pfn = find_biggest_section_pfn(nid, zone, zone_start_pfn,
602 start_pfn);
603 if (pfn)
604 zone->spanned_pages = pfn - zone_start_pfn + 1;
605 }
606
607 /*
608 * The section is not biggest or smallest mem_section in the zone, it
609 * only creates a hole in the zone. So in this case, we need not
610 * change the zone. But perhaps, the zone has only hole data. Thus
611 * it check the zone has only hole or not.
612 */
613 pfn = zone_start_pfn;
614 for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) {
615 ms = __pfn_to_section(pfn);
616
617 if (unlikely(!valid_section(ms)))
618 continue;
619
620 if (page_zone(pfn_to_page(pfn)) != zone)
621 continue;
622
623 /* If the section is current section, it continues the loop */
624 if (start_pfn == pfn)
625 continue;
626
627 /* If we find valid section, we have nothing to do */
628 zone_span_writeunlock(zone);
629 return;
630 }
631
632 /* The zone has no valid section */
633 zone->zone_start_pfn = 0;
634 zone->spanned_pages = 0;
635 zone_span_writeunlock(zone);
636 }
637
638 static void shrink_pgdat_span(struct pglist_data *pgdat,
639 unsigned long start_pfn, unsigned long end_pfn)
640 {
641 unsigned long pgdat_start_pfn = pgdat->node_start_pfn;
642 unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */
643 unsigned long pgdat_end_pfn = p;
644 unsigned long pfn;
645 struct mem_section *ms;
646 int nid = pgdat->node_id;
647
648 if (pgdat_start_pfn == start_pfn) {
649 /*
650 * If the section is smallest section in the pgdat, it need
651 * shrink pgdat->node_start_pfn and pgdat->node_spanned_pages.
652 * In this case, we find second smallest valid mem_section
653 * for shrinking zone.
654 */
655 pfn = find_smallest_section_pfn(nid, NULL, end_pfn,
656 pgdat_end_pfn);
657 if (pfn) {
658 pgdat->node_start_pfn = pfn;
659 pgdat->node_spanned_pages = pgdat_end_pfn - pfn;
660 }
661 } else if (pgdat_end_pfn == end_pfn) {
662 /*
663 * If the section is biggest section in the pgdat, it need
664 * shrink pgdat->node_spanned_pages.
665 * In this case, we find second biggest valid mem_section for
666 * shrinking zone.
667 */
668 pfn = find_biggest_section_pfn(nid, NULL, pgdat_start_pfn,
669 start_pfn);
670 if (pfn)
671 pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1;
672 }
673
674 /*
675 * If the section is not biggest or smallest mem_section in the pgdat,
676 * it only creates a hole in the pgdat. So in this case, we need not
677 * change the pgdat.
678 * But perhaps, the pgdat has only hole data. Thus it check the pgdat
679 * has only hole or not.
680 */
681 pfn = pgdat_start_pfn;
682 for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SECTION) {
683 ms = __pfn_to_section(pfn);
684
685 if (unlikely(!valid_section(ms)))
686 continue;
687
688 if (pfn_to_nid(pfn) != nid)
689 continue;
690
691 /* If the section is current section, it continues the loop */
692 if (start_pfn == pfn)
693 continue;
694
695 /* If we find valid section, we have nothing to do */
696 return;
697 }
698
699 /* The pgdat has no valid section */
700 pgdat->node_start_pfn = 0;
701 pgdat->node_spanned_pages = 0;
702 }
703
704 static void __remove_zone(struct zone *zone, unsigned long start_pfn)
705 {
706 struct pglist_data *pgdat = zone->zone_pgdat;
707 int nr_pages = PAGES_PER_SECTION;
708 unsigned long flags;
709
710 pgdat_resize_lock(zone->zone_pgdat, &flags);
711 shrink_zone_span(zone, start_pfn, start_pfn + nr_pages);
712 shrink_pgdat_span(pgdat, start_pfn, start_pfn + nr_pages);
713 pgdat_resize_unlock(zone->zone_pgdat, &flags);
714 }
715
716 static int __remove_section(struct zone *zone, struct mem_section *ms,
717 unsigned long map_offset)
718 {
719 unsigned long start_pfn;
720 int scn_nr;
721 int ret = -EINVAL;
722
723 if (!valid_section(ms))
724 return ret;
725
726 ret = unregister_memory_section(ms);
727 if (ret)
728 return ret;
729
730 scn_nr = __section_nr(ms);
731 start_pfn = section_nr_to_pfn(scn_nr);
732 __remove_zone(zone, start_pfn);
733
734 sparse_remove_one_section(zone, ms, map_offset);
735 return 0;
736 }
737
738 /**
739 * __remove_pages() - remove sections of pages from a zone
740 * @zone: zone from which pages need to be removed
741 * @phys_start_pfn: starting pageframe (must be aligned to start of a section)
742 * @nr_pages: number of pages to remove (must be multiple of section size)
743 *
744 * Generic helper function to remove section mappings and sysfs entries
745 * for the section of the memory we are removing. Caller needs to make
746 * sure that pages are marked reserved and zones are adjust properly by
747 * calling offline_pages().
748 */
749 int __remove_pages(struct zone *zone, unsigned long phys_start_pfn,
750 unsigned long nr_pages)
751 {
752 unsigned long i;
753 unsigned long map_offset = 0;
754 int sections_to_remove, ret = 0;
755
756 /* In the ZONE_DEVICE case device driver owns the memory region */
757 if (is_dev_zone(zone)) {
758 struct page *page = pfn_to_page(phys_start_pfn);
759 struct vmem_altmap *altmap;
760
761 altmap = to_vmem_altmap((unsigned long) page);
762 if (altmap)
763 map_offset = vmem_altmap_offset(altmap);
764 } else {
765 resource_size_t start, size;
766
767 start = phys_start_pfn << PAGE_SHIFT;
768 size = nr_pages * PAGE_SIZE;
769
770 ret = release_mem_region_adjustable(&iomem_resource, start,
771 size);
772 if (ret) {
773 resource_size_t endres = start + size - 1;
774
775 pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
776 &start, &endres, ret);
777 }
778 }
779
780 clear_zone_contiguous(zone);
781
782 /*
783 * We can only remove entire sections
784 */
785 BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
786 BUG_ON(nr_pages % PAGES_PER_SECTION);
787
788 sections_to_remove = nr_pages / PAGES_PER_SECTION;
789 for (i = 0; i < sections_to_remove; i++) {
790 unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION;
791
792 ret = __remove_section(zone, __pfn_to_section(pfn), map_offset);
793 map_offset = 0;
794 if (ret)
795 break;
796 }
797
798 set_zone_contiguous(zone);
799
800 return ret;
801 }
802 #endif /* CONFIG_MEMORY_HOTREMOVE */
803
804 int set_online_page_callback(online_page_callback_t callback)
805 {
806 int rc = -EINVAL;
807
808 get_online_mems();
809 mutex_lock(&online_page_callback_lock);
810
811 if (online_page_callback == generic_online_page) {
812 online_page_callback = callback;
813 rc = 0;
814 }
815
816 mutex_unlock(&online_page_callback_lock);
817 put_online_mems();
818
819 return rc;
820 }
821 EXPORT_SYMBOL_GPL(set_online_page_callback);
822
823 int restore_online_page_callback(online_page_callback_t callback)
824 {
825 int rc = -EINVAL;
826
827 get_online_mems();
828 mutex_lock(&online_page_callback_lock);
829
830 if (online_page_callback == callback) {
831 online_page_callback = generic_online_page;
832 rc = 0;
833 }
834
835 mutex_unlock(&online_page_callback_lock);
836 put_online_mems();
837
838 return rc;
839 }
840 EXPORT_SYMBOL_GPL(restore_online_page_callback);
841
842 void __online_page_set_limits(struct page *page)
843 {
844 }
845 EXPORT_SYMBOL_GPL(__online_page_set_limits);
846
847 void __online_page_increment_counters(struct page *page)
848 {
849 adjust_managed_page_count(page, 1);
850 }
851 EXPORT_SYMBOL_GPL(__online_page_increment_counters);
852
853 void __online_page_free(struct page *page)
854 {
855 __free_reserved_page(page);
856 }
857 EXPORT_SYMBOL_GPL(__online_page_free);
858
859 static void generic_online_page(struct page *page)
860 {
861 __online_page_set_limits(page);
862 __online_page_increment_counters(page);
863 __online_page_free(page);
864 }
865
866 static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
867 void *arg)
868 {
869 unsigned long i;
870 unsigned long onlined_pages = *(unsigned long *)arg;
871 struct page *page;
872
873 if (PageReserved(pfn_to_page(start_pfn)))
874 for (i = 0; i < nr_pages; i++) {
875 page = pfn_to_page(start_pfn + i);
876 (*online_page_callback)(page);
877 onlined_pages++;
878 }
879
880 online_mem_sections(start_pfn, start_pfn + nr_pages);
881
882 *(unsigned long *)arg = onlined_pages;
883 return 0;
884 }
885
886 #ifdef CONFIG_MOVABLE_NODE
887 /*
888 * When CONFIG_MOVABLE_NODE, we permit onlining of a node which doesn't have
889 * normal memory.
890 */
891 static bool can_online_high_movable(int nid)
892 {
893 return true;
894 }
895 #else /* CONFIG_MOVABLE_NODE */
896 /* ensure every online node has NORMAL memory */
897 static bool can_online_high_movable(int nid)
898 {
899 return node_state(nid, N_NORMAL_MEMORY);
900 }
901 #endif /* CONFIG_MOVABLE_NODE */
902
903 /* check which state of node_states will be changed when online memory */
904 static void node_states_check_changes_online(unsigned long nr_pages,
905 struct zone *zone, struct memory_notify *arg)
906 {
907 int nid = zone_to_nid(zone);
908 enum zone_type zone_last = ZONE_NORMAL;
909
910 /*
911 * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY]
912 * contains nodes which have zones of 0...ZONE_NORMAL,
913 * set zone_last to ZONE_NORMAL.
914 *
915 * If we don't have HIGHMEM nor movable node,
916 * node_states[N_NORMAL_MEMORY] contains nodes which have zones of
917 * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE.
918 */
919 if (N_MEMORY == N_NORMAL_MEMORY)
920 zone_last = ZONE_MOVABLE;
921
922 /*
923 * if the memory to be online is in a zone of 0...zone_last, and
924 * the zones of 0...zone_last don't have memory before online, we will
925 * need to set the node to node_states[N_NORMAL_MEMORY] after
926 * the memory is online.
927 */
928 if (zone_idx(zone) <= zone_last && !node_state(nid, N_NORMAL_MEMORY))
929 arg->status_change_nid_normal = nid;
930 else
931 arg->status_change_nid_normal = -1;
932
933 #ifdef CONFIG_HIGHMEM
934 /*
935 * If we have movable node, node_states[N_HIGH_MEMORY]
936 * contains nodes which have zones of 0...ZONE_HIGHMEM,
937 * set zone_last to ZONE_HIGHMEM.
938 *
939 * If we don't have movable node, node_states[N_NORMAL_MEMORY]
940 * contains nodes which have zones of 0...ZONE_MOVABLE,
941 * set zone_last to ZONE_MOVABLE.
942 */
943 zone_last = ZONE_HIGHMEM;
944 if (N_MEMORY == N_HIGH_MEMORY)
945 zone_last = ZONE_MOVABLE;
946
947 if (zone_idx(zone) <= zone_last && !node_state(nid, N_HIGH_MEMORY))
948 arg->status_change_nid_high = nid;
949 else
950 arg->status_change_nid_high = -1;
951 #else
952 arg->status_change_nid_high = arg->status_change_nid_normal;
953 #endif
954
955 /*
956 * if the node don't have memory befor online, we will need to
957 * set the node to node_states[N_MEMORY] after the memory
958 * is online.
959 */
960 if (!node_state(nid, N_MEMORY))
961 arg->status_change_nid = nid;
962 else
963 arg->status_change_nid = -1;
964 }
965
966 static void node_states_set_node(int node, struct memory_notify *arg)
967 {
968 if (arg->status_change_nid_normal >= 0)
969 node_set_state(node, N_NORMAL_MEMORY);
970
971 if (arg->status_change_nid_high >= 0)
972 node_set_state(node, N_HIGH_MEMORY);
973
974 node_set_state(node, N_MEMORY);
975 }
976
977 bool zone_can_shift(unsigned long pfn, unsigned long nr_pages,
978 enum zone_type target, int *zone_shift)
979 {
980 struct zone *zone = page_zone(pfn_to_page(pfn));
981 enum zone_type idx = zone_idx(zone);
982 int i;
983
984 *zone_shift = 0;
985
986 if (idx < target) {
987 /* pages must be at end of current zone */
988 if (pfn + nr_pages != zone_end_pfn(zone))
989 return false;
990
991 /* no zones in use between current zone and target */
992 for (i = idx + 1; i < target; i++)
993 if (zone_is_initialized(zone - idx + i))
994 return false;
995 }
996
997 if (target < idx) {
998 /* pages must be at beginning of current zone */
999 if (pfn != zone->zone_start_pfn)
1000 return false;
1001
1002 /* no zones in use between current zone and target */
1003 for (i = target + 1; i < idx; i++)
1004 if (zone_is_initialized(zone - idx + i))
1005 return false;
1006 }
1007
1008 *zone_shift = target - idx;
1009 return true;
1010 }
1011
1012 /* Must be protected by mem_hotplug_begin() */
1013 int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_type)
1014 {
1015 unsigned long flags;
1016 unsigned long onlined_pages = 0;
1017 struct zone *zone;
1018 int need_zonelists_rebuild = 0;
1019 int nid;
1020 int ret;
1021 struct memory_notify arg;
1022 int zone_shift = 0;
1023
1024 /*
1025 * This doesn't need a lock to do pfn_to_page().
1026 * The section can't be removed here because of the
1027 * memory_block->state_mutex.
1028 */
1029 zone = page_zone(pfn_to_page(pfn));
1030
1031 if ((zone_idx(zone) > ZONE_NORMAL ||
1032 online_type == MMOP_ONLINE_MOVABLE) &&
1033 !can_online_high_movable(pfn_to_nid(pfn)))
1034 return -EINVAL;
1035
1036 if (online_type == MMOP_ONLINE_KERNEL) {
1037 if (!zone_can_shift(pfn, nr_pages, ZONE_NORMAL, &zone_shift))
1038 return -EINVAL;
1039 } else if (online_type == MMOP_ONLINE_MOVABLE) {
1040 if (!zone_can_shift(pfn, nr_pages, ZONE_MOVABLE, &zone_shift))
1041 return -EINVAL;
1042 }
1043
1044 zone = move_pfn_range(zone_shift, pfn, pfn + nr_pages);
1045 if (!zone)
1046 return -EINVAL;
1047
1048 arg.start_pfn = pfn;
1049 arg.nr_pages = nr_pages;
1050 node_states_check_changes_online(nr_pages, zone, &arg);
1051
1052 nid = zone_to_nid(zone);
1053
1054 ret = memory_notify(MEM_GOING_ONLINE, &arg);
1055 ret = notifier_to_errno(ret);
1056 if (ret)
1057 goto failed_addition;
1058
1059 /*
1060 * If this zone is not populated, then it is not in zonelist.
1061 * This means the page allocator ignores this zone.
1062 * So, zonelist must be updated after online.
1063 */
1064 mutex_lock(&zonelists_mutex);
1065 if (!populated_zone(zone)) {
1066 need_zonelists_rebuild = 1;
1067 build_all_zonelists(NULL, zone);
1068 }
1069
1070 ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages,
1071 online_pages_range);
1072 if (ret) {
1073 if (need_zonelists_rebuild)
1074 zone_pcp_reset(zone);
1075 mutex_unlock(&zonelists_mutex);
1076 goto failed_addition;
1077 }
1078
1079 zone->present_pages += onlined_pages;
1080
1081 pgdat_resize_lock(zone->zone_pgdat, &flags);
1082 zone->zone_pgdat->node_present_pages += onlined_pages;
1083 pgdat_resize_unlock(zone->zone_pgdat, &flags);
1084
1085 if (onlined_pages) {
1086 node_states_set_node(nid, &arg);
1087 if (need_zonelists_rebuild)
1088 build_all_zonelists(NULL, NULL);
1089 else
1090 zone_pcp_update(zone);
1091 }
1092
1093 mutex_unlock(&zonelists_mutex);
1094
1095 init_per_zone_wmark_min();
1096
1097 if (onlined_pages) {
1098 kswapd_run(nid);
1099 kcompactd_run(nid);
1100 }
1101
1102 vm_total_pages = nr_free_pagecache_pages();
1103
1104 writeback_set_ratelimit();
1105
1106 if (onlined_pages)
1107 memory_notify(MEM_ONLINE, &arg);
1108 return 0;
1109
1110 failed_addition:
1111 pr_debug("online_pages [mem %#010llx-%#010llx] failed\n",
1112 (unsigned long long) pfn << PAGE_SHIFT,
1113 (((unsigned long long) pfn + nr_pages) << PAGE_SHIFT) - 1);
1114 memory_notify(MEM_CANCEL_ONLINE, &arg);
1115 return ret;
1116 }
1117 #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
1118
1119 static void reset_node_present_pages(pg_data_t *pgdat)
1120 {
1121 struct zone *z;
1122
1123 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
1124 z->present_pages = 0;
1125
1126 pgdat->node_present_pages = 0;
1127 }
1128
1129 /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
1130 static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
1131 {
1132 struct pglist_data *pgdat;
1133 unsigned long zones_size[MAX_NR_ZONES] = {0};
1134 unsigned long zholes_size[MAX_NR_ZONES] = {0};
1135 unsigned long start_pfn = PFN_DOWN(start);
1136
1137 pgdat = NODE_DATA(nid);
1138 if (!pgdat) {
1139 pgdat = arch_alloc_nodedata(nid);
1140 if (!pgdat)
1141 return NULL;
1142
1143 arch_refresh_nodedata(nid, pgdat);
1144 } else {
1145 /*
1146 * Reset the nr_zones, order and classzone_idx before reuse.
1147 * Note that kswapd will init kswapd_classzone_idx properly
1148 * when it starts in the near future.
1149 */
1150 pgdat->nr_zones = 0;
1151 pgdat->kswapd_order = 0;
1152 pgdat->kswapd_classzone_idx = 0;
1153 }
1154
1155 /* we can use NODE_DATA(nid) from here */
1156
1157 /* init node's zones as empty zones, we don't have any present pages.*/
1158 free_area_init_node(nid, zones_size, start_pfn, zholes_size);
1159 pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat);
1160
1161 /*
1162 * The node we allocated has no zone fallback lists. For avoiding
1163 * to access not-initialized zonelist, build here.
1164 */
1165 mutex_lock(&zonelists_mutex);
1166 build_all_zonelists(pgdat, NULL);
1167 mutex_unlock(&zonelists_mutex);
1168
1169 /*
1170 * zone->managed_pages is set to an approximate value in
1171 * free_area_init_core(), which will cause
1172 * /sys/device/system/node/nodeX/meminfo has wrong data.
1173 * So reset it to 0 before any memory is onlined.
1174 */
1175 reset_node_managed_pages(pgdat);
1176
1177 /*
1178 * When memory is hot-added, all the memory is in offline state. So
1179 * clear all zones' present_pages because they will be updated in
1180 * online_pages() and offline_pages().
1181 */
1182 reset_node_present_pages(pgdat);
1183
1184 return pgdat;
1185 }
1186
1187 static void rollback_node_hotadd(int nid, pg_data_t *pgdat)
1188 {
1189 arch_refresh_nodedata(nid, NULL);
1190 free_percpu(pgdat->per_cpu_nodestats);
1191 arch_free_nodedata(pgdat);
1192 return;
1193 }
1194
1195
1196 /**
1197 * try_online_node - online a node if offlined
1198 *
1199 * called by cpu_up() to online a node without onlined memory.
1200 */
1201 int try_online_node(int nid)
1202 {
1203 pg_data_t *pgdat;
1204 int ret;
1205
1206 if (node_online(nid))
1207 return 0;
1208
1209 mem_hotplug_begin();
1210 pgdat = hotadd_new_pgdat(nid, 0);
1211 if (!pgdat) {
1212 pr_err("Cannot online node %d due to NULL pgdat\n", nid);
1213 ret = -ENOMEM;
1214 goto out;
1215 }
1216 node_set_online(nid);
1217 ret = register_one_node(nid);
1218 BUG_ON(ret);
1219
1220 if (pgdat->node_zonelists->_zonerefs->zone == NULL) {
1221 mutex_lock(&zonelists_mutex);
1222 build_all_zonelists(NULL, NULL);
1223 mutex_unlock(&zonelists_mutex);
1224 }
1225
1226 out:
1227 mem_hotplug_done();
1228 return ret;
1229 }
1230
1231 static int check_hotplug_memory_range(u64 start, u64 size)
1232 {
1233 u64 start_pfn = PFN_DOWN(start);
1234 u64 nr_pages = size >> PAGE_SHIFT;
1235
1236 /* Memory range must be aligned with section */
1237 if ((start_pfn & ~PAGE_SECTION_MASK) ||
1238 (nr_pages % PAGES_PER_SECTION) || (!nr_pages)) {
1239 pr_err("Section-unaligned hotplug range: start 0x%llx, size 0x%llx\n",
1240 (unsigned long long)start,
1241 (unsigned long long)size);
1242 return -EINVAL;
1243 }
1244
1245 return 0;
1246 }
1247
1248 /*
1249 * If movable zone has already been setup, newly added memory should be check.
1250 * If its address is higher than movable zone, it should be added as movable.
1251 * Without this check, movable zone may overlap with other zone.
1252 */
1253 static int should_add_memory_movable(int nid, u64 start, u64 size)
1254 {
1255 unsigned long start_pfn = start >> PAGE_SHIFT;
1256 pg_data_t *pgdat = NODE_DATA(nid);
1257 struct zone *movable_zone = pgdat->node_zones + ZONE_MOVABLE;
1258
1259 if (zone_is_empty(movable_zone))
1260 return 0;
1261
1262 if (movable_zone->zone_start_pfn <= start_pfn)
1263 return 1;
1264
1265 return 0;
1266 }
1267
1268 int zone_for_memory(int nid, u64 start, u64 size, int zone_default,
1269 bool for_device)
1270 {
1271 #ifdef CONFIG_ZONE_DEVICE
1272 if (for_device)
1273 return ZONE_DEVICE;
1274 #endif
1275 if (should_add_memory_movable(nid, start, size))
1276 return ZONE_MOVABLE;
1277
1278 return zone_default;
1279 }
1280
1281 static int online_memory_block(struct memory_block *mem, void *arg)
1282 {
1283 return device_online(&mem->dev);
1284 }
1285
1286 /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
1287 int __ref add_memory_resource(int nid, struct resource *res, bool online)
1288 {
1289 u64 start, size;
1290 pg_data_t *pgdat = NULL;
1291 bool new_pgdat;
1292 bool new_node;
1293 int ret;
1294
1295 start = res->start;
1296 size = resource_size(res);
1297
1298 ret = check_hotplug_memory_range(start, size);
1299 if (ret)
1300 return ret;
1301
1302 { /* Stupid hack to suppress address-never-null warning */
1303 void *p = NODE_DATA(nid);
1304 new_pgdat = !p;
1305 }
1306
1307 mem_hotplug_begin();
1308
1309 /*
1310 * Add new range to memblock so that when hotadd_new_pgdat() is called
1311 * to allocate new pgdat, get_pfn_range_for_nid() will be able to find
1312 * this new range and calculate total pages correctly. The range will
1313 * be removed at hot-remove time.
1314 */
1315 memblock_add_node(start, size, nid);
1316
1317 new_node = !node_online(nid);
1318 if (new_node) {
1319 pgdat = hotadd_new_pgdat(nid, start);
1320 ret = -ENOMEM;
1321 if (!pgdat)
1322 goto error;
1323 }
1324
1325 /* call arch's memory hotadd */
1326 ret = arch_add_memory(nid, start, size, true);
1327
1328 if (ret < 0)
1329 goto error;
1330
1331 /* we online node here. we can't roll back from here. */
1332 node_set_online(nid);
1333
1334 if (new_node) {
1335 unsigned long start_pfn = start >> PAGE_SHIFT;
1336 unsigned long nr_pages = size >> PAGE_SHIFT;
1337
1338 ret = __register_one_node(nid);
1339 if (ret)
1340 goto register_fail;
1341
1342 /*
1343 * link memory sections under this node. This is already
1344 * done when creatig memory section in register_new_memory
1345 * but that depends to have the node registered so offline
1346 * nodes have to go through register_node.
1347 * TODO clean up this mess.
1348 */
1349 ret = link_mem_sections(nid, start_pfn, nr_pages);
1350 register_fail:
1351 /*
1352 * If sysfs file of new node can't create, cpu on the node
1353 * can't be hot-added. There is no rollback way now.
1354 * So, check by BUG_ON() to catch it reluctantly..
1355 */
1356 BUG_ON(ret);
1357 }
1358
1359 /* create new memmap entry */
1360 firmware_map_add_hotplug(start, start + size, "System RAM");
1361
1362 /* online pages if requested */
1363 if (online)
1364 walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1),
1365 NULL, online_memory_block);
1366
1367 goto out;
1368
1369 error:
1370 /* rollback pgdat allocation and others */
1371 if (new_pgdat && pgdat)
1372 rollback_node_hotadd(nid, pgdat);
1373 memblock_remove(start, size);
1374
1375 out:
1376 mem_hotplug_done();
1377 return ret;
1378 }
1379 EXPORT_SYMBOL_GPL(add_memory_resource);
1380
1381 int __ref add_memory(int nid, u64 start, u64 size)
1382 {
1383 struct resource *res;
1384 int ret;
1385
1386 res = register_memory_resource(start, size);
1387 if (IS_ERR(res))
1388 return PTR_ERR(res);
1389
1390 ret = add_memory_resource(nid, res, memhp_auto_online);
1391 if (ret < 0)
1392 release_memory_resource(res);
1393 return ret;
1394 }
1395 EXPORT_SYMBOL_GPL(add_memory);
1396
1397 #ifdef CONFIG_MEMORY_HOTREMOVE
1398 /*
1399 * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy
1400 * set and the size of the free page is given by page_order(). Using this,
1401 * the function determines if the pageblock contains only free pages.
1402 * Due to buddy contraints, a free page at least the size of a pageblock will
1403 * be located at the start of the pageblock
1404 */
1405 static inline int pageblock_free(struct page *page)
1406 {
1407 return PageBuddy(page) && page_order(page) >= pageblock_order;
1408 }
1409
1410 /* Return the start of the next active pageblock after a given page */
1411 static struct page *next_active_pageblock(struct page *page)
1412 {
1413 /* Ensure the starting page is pageblock-aligned */
1414 BUG_ON(page_to_pfn(page) & (pageblock_nr_pages - 1));
1415
1416 /* If the entire pageblock is free, move to the end of free page */
1417 if (pageblock_free(page)) {
1418 int order;
1419 /* be careful. we don't have locks, page_order can be changed.*/
1420 order = page_order(page);
1421 if ((order < MAX_ORDER) && (order >= pageblock_order))
1422 return page + (1 << order);
1423 }
1424
1425 return page + pageblock_nr_pages;
1426 }
1427
1428 /* Checks if this range of memory is likely to be hot-removable. */
1429 bool is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
1430 {
1431 struct page *page = pfn_to_page(start_pfn);
1432 struct page *end_page = page + nr_pages;
1433
1434 /* Check the starting page of each pageblock within the range */
1435 for (; page < end_page; page = next_active_pageblock(page)) {
1436 if (!is_pageblock_removable_nolock(page))
1437 return false;
1438 cond_resched();
1439 }
1440
1441 /* All pageblocks in the memory block are likely to be hot-removable */
1442 return true;
1443 }
1444
1445 /*
1446 * Confirm all pages in a range [start, end) belong to the same zone.
1447 * When true, return its valid [start, end).
1448 */
1449 int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn,
1450 unsigned long *valid_start, unsigned long *valid_end)
1451 {
1452 unsigned long pfn, sec_end_pfn;
1453 unsigned long start, end;
1454 struct zone *zone = NULL;
1455 struct page *page;
1456 int i;
1457 for (pfn = start_pfn, sec_end_pfn = SECTION_ALIGN_UP(start_pfn + 1);
1458 pfn < end_pfn;
1459 pfn = sec_end_pfn, sec_end_pfn += PAGES_PER_SECTION) {
1460 /* Make sure the memory section is present first */
1461 if (!present_section_nr(pfn_to_section_nr(pfn)))
1462 continue;
1463 for (; pfn < sec_end_pfn && pfn < end_pfn;
1464 pfn += MAX_ORDER_NR_PAGES) {
1465 i = 0;
1466 /* This is just a CONFIG_HOLES_IN_ZONE check.*/
1467 while ((i < MAX_ORDER_NR_PAGES) &&
1468 !pfn_valid_within(pfn + i))
1469 i++;
1470 if (i == MAX_ORDER_NR_PAGES || pfn + i >= end_pfn)
1471 continue;
1472 page = pfn_to_page(pfn + i);
1473 if (zone && page_zone(page) != zone)
1474 return 0;
1475 if (!zone)
1476 start = pfn + i;
1477 zone = page_zone(page);
1478 end = pfn + MAX_ORDER_NR_PAGES;
1479 }
1480 }
1481
1482 if (zone) {
1483 *valid_start = start;
1484 *valid_end = min(end, end_pfn);
1485 return 1;
1486 } else {
1487 return 0;
1488 }
1489 }
1490
1491 /*
1492 * Scan pfn range [start,end) to find movable/migratable pages (LRU pages,
1493 * non-lru movable pages and hugepages). We scan pfn because it's much
1494 * easier than scanning over linked list. This function returns the pfn
1495 * of the first found movable page if it's found, otherwise 0.
1496 */
1497 static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
1498 {
1499 unsigned long pfn;
1500 struct page *page;
1501 for (pfn = start; pfn < end; pfn++) {
1502 if (pfn_valid(pfn)) {
1503 page = pfn_to_page(pfn);
1504 if (PageLRU(page))
1505 return pfn;
1506 if (__PageMovable(page))
1507 return pfn;
1508 if (PageHuge(page)) {
1509 if (page_huge_active(page))
1510 return pfn;
1511 else
1512 pfn = round_up(pfn + 1,
1513 1 << compound_order(page)) - 1;
1514 }
1515 }
1516 }
1517 return 0;
1518 }
1519
1520 static struct page *new_node_page(struct page *page, unsigned long private,
1521 int **result)
1522 {
1523 int nid = page_to_nid(page);
1524 nodemask_t nmask = node_states[N_MEMORY];
1525
1526 /*
1527 * try to allocate from a different node but reuse this node if there
1528 * are no other online nodes to be used (e.g. we are offlining a part
1529 * of the only existing node)
1530 */
1531 node_clear(nid, nmask);
1532 if (nodes_empty(nmask))
1533 node_set(nid, nmask);
1534
1535 return new_page_nodemask(page, nid, &nmask);
1536 }
1537
1538 #define NR_OFFLINE_AT_ONCE_PAGES (256)
1539 static int
1540 do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
1541 {
1542 unsigned long pfn;
1543 struct page *page;
1544 int move_pages = NR_OFFLINE_AT_ONCE_PAGES;
1545 int not_managed = 0;
1546 int ret = 0;
1547 LIST_HEAD(source);
1548
1549 for (pfn = start_pfn; pfn < end_pfn && move_pages > 0; pfn++) {
1550 if (!pfn_valid(pfn))
1551 continue;
1552 page = pfn_to_page(pfn);
1553
1554 if (PageHuge(page)) {
1555 struct page *head = compound_head(page);
1556 pfn = page_to_pfn(head) + (1<<compound_order(head)) - 1;
1557 if (compound_order(head) > PFN_SECTION_SHIFT) {
1558 ret = -EBUSY;
1559 break;
1560 }
1561 if (isolate_huge_page(page, &source))
1562 move_pages -= 1 << compound_order(head);
1563 continue;
1564 }
1565
1566 if (!get_page_unless_zero(page))
1567 continue;
1568 /*
1569 * We can skip free pages. And we can deal with pages on
1570 * LRU and non-lru movable pages.
1571 */
1572 if (PageLRU(page))
1573 ret = isolate_lru_page(page);
1574 else
1575 ret = isolate_movable_page(page, ISOLATE_UNEVICTABLE);
1576 if (!ret) { /* Success */
1577 put_page(page);
1578 list_add_tail(&page->lru, &source);
1579 move_pages--;
1580 if (!__PageMovable(page))
1581 inc_node_page_state(page, NR_ISOLATED_ANON +
1582 page_is_file_cache(page));
1583
1584 } else {
1585 #ifdef CONFIG_DEBUG_VM
1586 pr_alert("failed to isolate pfn %lx\n", pfn);
1587 dump_page(page, "isolation failed");
1588 #endif
1589 put_page(page);
1590 /* Because we don't have big zone->lock. we should
1591 check this again here. */
1592 if (page_count(page)) {
1593 not_managed++;
1594 ret = -EBUSY;
1595 break;
1596 }
1597 }
1598 }
1599 if (!list_empty(&source)) {
1600 if (not_managed) {
1601 putback_movable_pages(&source);
1602 goto out;
1603 }
1604
1605 /* Allocate a new page from the nearest neighbor node */
1606 ret = migrate_pages(&source, new_node_page, NULL, 0,
1607 MIGRATE_SYNC, MR_MEMORY_HOTPLUG);
1608 if (ret)
1609 putback_movable_pages(&source);
1610 }
1611 out:
1612 return ret;
1613 }
1614
1615 /*
1616 * remove from free_area[] and mark all as Reserved.
1617 */
1618 static int
1619 offline_isolated_pages_cb(unsigned long start, unsigned long nr_pages,
1620 void *data)
1621 {
1622 __offline_isolated_pages(start, start + nr_pages);
1623 return 0;
1624 }
1625
1626 static void
1627 offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
1628 {
1629 walk_system_ram_range(start_pfn, end_pfn - start_pfn, NULL,
1630 offline_isolated_pages_cb);
1631 }
1632
1633 /*
1634 * Check all pages in range, recoreded as memory resource, are isolated.
1635 */
1636 static int
1637 check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages,
1638 void *data)
1639 {
1640 int ret;
1641 long offlined = *(long *)data;
1642 ret = test_pages_isolated(start_pfn, start_pfn + nr_pages, true);
1643 offlined = nr_pages;
1644 if (!ret)
1645 *(long *)data += offlined;
1646 return ret;
1647 }
1648
1649 static long
1650 check_pages_isolated(unsigned long start_pfn, unsigned long end_pfn)
1651 {
1652 long offlined = 0;
1653 int ret;
1654
1655 ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn, &offlined,
1656 check_pages_isolated_cb);
1657 if (ret < 0)
1658 offlined = (long)ret;
1659 return offlined;
1660 }
1661
1662 static int __init cmdline_parse_movable_node(char *p)
1663 {
1664 #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
1665 movable_node_enabled = true;
1666 #else
1667 pr_warn("movable_node parameter depends on CONFIG_HAVE_MEMBLOCK_NODE_MAP to work properly\n");
1668 #endif
1669 return 0;
1670 }
1671 early_param("movable_node", cmdline_parse_movable_node);
1672
1673 /* check which state of node_states will be changed when offline memory */
1674 static void node_states_check_changes_offline(unsigned long nr_pages,
1675 struct zone *zone, struct memory_notify *arg)
1676 {
1677 struct pglist_data *pgdat = zone->zone_pgdat;
1678 unsigned long present_pages = 0;
1679 enum zone_type zt, zone_last = ZONE_NORMAL;
1680
1681 /*
1682 * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY]
1683 * contains nodes which have zones of 0...ZONE_NORMAL,
1684 * set zone_last to ZONE_NORMAL.
1685 *
1686 * If we don't have HIGHMEM nor movable node,
1687 * node_states[N_NORMAL_MEMORY] contains nodes which have zones of
1688 * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE.
1689 */
1690 if (N_MEMORY == N_NORMAL_MEMORY)
1691 zone_last = ZONE_MOVABLE;
1692
1693 /*
1694 * check whether node_states[N_NORMAL_MEMORY] will be changed.
1695 * If the memory to be offline is in a zone of 0...zone_last,
1696 * and it is the last present memory, 0...zone_last will
1697 * become empty after offline , thus we can determind we will
1698 * need to clear the node from node_states[N_NORMAL_MEMORY].
1699 */
1700 for (zt = 0; zt <= zone_last; zt++)
1701 present_pages += pgdat->node_zones[zt].present_pages;
1702 if (zone_idx(zone) <= zone_last && nr_pages >= present_pages)
1703 arg->status_change_nid_normal = zone_to_nid(zone);
1704 else
1705 arg->status_change_nid_normal = -1;
1706
1707 #ifdef CONFIG_HIGHMEM
1708 /*
1709 * If we have movable node, node_states[N_HIGH_MEMORY]
1710 * contains nodes which have zones of 0...ZONE_HIGHMEM,
1711 * set zone_last to ZONE_HIGHMEM.
1712 *
1713 * If we don't have movable node, node_states[N_NORMAL_MEMORY]
1714 * contains nodes which have zones of 0...ZONE_MOVABLE,
1715 * set zone_last to ZONE_MOVABLE.
1716 */
1717 zone_last = ZONE_HIGHMEM;
1718 if (N_MEMORY == N_HIGH_MEMORY)
1719 zone_last = ZONE_MOVABLE;
1720
1721 for (; zt <= zone_last; zt++)
1722 present_pages += pgdat->node_zones[zt].present_pages;
1723 if (zone_idx(zone) <= zone_last && nr_pages >= present_pages)
1724 arg->status_change_nid_high = zone_to_nid(zone);
1725 else
1726 arg->status_change_nid_high = -1;
1727 #else
1728 arg->status_change_nid_high = arg->status_change_nid_normal;
1729 #endif
1730
1731 /*
1732 * node_states[N_HIGH_MEMORY] contains nodes which have 0...ZONE_MOVABLE
1733 */
1734 zone_last = ZONE_MOVABLE;
1735
1736 /*
1737 * check whether node_states[N_HIGH_MEMORY] will be changed
1738 * If we try to offline the last present @nr_pages from the node,
1739 * we can determind we will need to clear the node from
1740 * node_states[N_HIGH_MEMORY].
1741 */
1742 for (; zt <= zone_last; zt++)
1743 present_pages += pgdat->node_zones[zt].present_pages;
1744 if (nr_pages >= present_pages)
1745 arg->status_change_nid = zone_to_nid(zone);
1746 else
1747 arg->status_change_nid = -1;
1748 }
1749
1750 static void node_states_clear_node(int node, struct memory_notify *arg)
1751 {
1752 if (arg->status_change_nid_normal >= 0)
1753 node_clear_state(node, N_NORMAL_MEMORY);
1754
1755 if ((N_MEMORY != N_NORMAL_MEMORY) &&
1756 (arg->status_change_nid_high >= 0))
1757 node_clear_state(node, N_HIGH_MEMORY);
1758
1759 if ((N_MEMORY != N_HIGH_MEMORY) &&
1760 (arg->status_change_nid >= 0))
1761 node_clear_state(node, N_MEMORY);
1762 }
1763
1764 static int __ref __offline_pages(unsigned long start_pfn,
1765 unsigned long end_pfn, unsigned long timeout)
1766 {
1767 unsigned long pfn, nr_pages, expire;
1768 long offlined_pages;
1769 int ret, drain, retry_max, node;
1770 unsigned long flags;
1771 unsigned long valid_start, valid_end;
1772 struct zone *zone;
1773 struct memory_notify arg;
1774
1775 /* at least, alignment against pageblock is necessary */
1776 if (!IS_ALIGNED(start_pfn, pageblock_nr_pages))
1777 return -EINVAL;
1778 if (!IS_ALIGNED(end_pfn, pageblock_nr_pages))
1779 return -EINVAL;
1780 /* This makes hotplug much easier...and readable.
1781 we assume this for now. .*/
1782 if (!test_pages_in_a_zone(start_pfn, end_pfn, &valid_start, &valid_end))
1783 return -EINVAL;
1784
1785 zone = page_zone(pfn_to_page(valid_start));
1786 node = zone_to_nid(zone);
1787 nr_pages = end_pfn - start_pfn;
1788
1789 /* set above range as isolated */
1790 ret = start_isolate_page_range(start_pfn, end_pfn,
1791 MIGRATE_MOVABLE, true);
1792 if (ret)
1793 return ret;
1794
1795 arg.start_pfn = start_pfn;
1796 arg.nr_pages = nr_pages;
1797 node_states_check_changes_offline(nr_pages, zone, &arg);
1798
1799 ret = memory_notify(MEM_GOING_OFFLINE, &arg);
1800 ret = notifier_to_errno(ret);
1801 if (ret)
1802 goto failed_removal;
1803
1804 pfn = start_pfn;
1805 expire = jiffies + timeout;
1806 drain = 0;
1807 retry_max = 5;
1808 repeat:
1809 /* start memory hot removal */
1810 ret = -EAGAIN;
1811 if (time_after(jiffies, expire))
1812 goto failed_removal;
1813 ret = -EINTR;
1814 if (signal_pending(current))
1815 goto failed_removal;
1816 ret = 0;
1817 if (drain) {
1818 lru_add_drain_all_cpuslocked();
1819 cond_resched();
1820 drain_all_pages(zone);
1821 }
1822
1823 pfn = scan_movable_pages(start_pfn, end_pfn);
1824 if (pfn) { /* We have movable pages */
1825 ret = do_migrate_range(pfn, end_pfn);
1826 if (!ret) {
1827 drain = 1;
1828 goto repeat;
1829 } else {
1830 if (ret < 0)
1831 if (--retry_max == 0)
1832 goto failed_removal;
1833 yield();
1834 drain = 1;
1835 goto repeat;
1836 }
1837 }
1838 /* drain all zone's lru pagevec, this is asynchronous... */
1839 lru_add_drain_all_cpuslocked();
1840 yield();
1841 /* drain pcp pages, this is synchronous. */
1842 drain_all_pages(zone);
1843 /*
1844 * dissolve free hugepages in the memory block before doing offlining
1845 * actually in order to make hugetlbfs's object counting consistent.
1846 */
1847 ret = dissolve_free_huge_pages(start_pfn, end_pfn);
1848 if (ret)
1849 goto failed_removal;
1850 /* check again */
1851 offlined_pages = check_pages_isolated(start_pfn, end_pfn);
1852 if (offlined_pages < 0) {
1853 ret = -EBUSY;
1854 goto failed_removal;
1855 }
1856 pr_info("Offlined Pages %ld\n", offlined_pages);
1857 /* Ok, all of our target is isolated.
1858 We cannot do rollback at this point. */
1859 offline_isolated_pages(start_pfn, end_pfn);
1860 /* reset pagetype flags and makes migrate type to be MOVABLE */
1861 undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
1862 /* removal success */
1863 adjust_managed_page_count(pfn_to_page(start_pfn), -offlined_pages);
1864 zone->present_pages -= offlined_pages;
1865
1866 pgdat_resize_lock(zone->zone_pgdat, &flags);
1867 zone->zone_pgdat->node_present_pages -= offlined_pages;
1868 pgdat_resize_unlock(zone->zone_pgdat, &flags);
1869
1870 init_per_zone_wmark_min();
1871
1872 if (!populated_zone(zone)) {
1873 zone_pcp_reset(zone);
1874 mutex_lock(&zonelists_mutex);
1875 build_all_zonelists(NULL, NULL);
1876 mutex_unlock(&zonelists_mutex);
1877 } else
1878 zone_pcp_update(zone);
1879
1880 node_states_clear_node(node, &arg);
1881 if (arg.status_change_nid >= 0) {
1882 kswapd_stop(node);
1883 kcompactd_stop(node);
1884 }
1885
1886 vm_total_pages = nr_free_pagecache_pages();
1887 writeback_set_ratelimit();
1888
1889 memory_notify(MEM_OFFLINE, &arg);
1890 return 0;
1891
1892 failed_removal:
1893 pr_debug("memory offlining [mem %#010llx-%#010llx] failed\n",
1894 (unsigned long long) start_pfn << PAGE_SHIFT,
1895 ((unsigned long long) end_pfn << PAGE_SHIFT) - 1);
1896 memory_notify(MEM_CANCEL_OFFLINE, &arg);
1897 /* pushback to free area */
1898 undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
1899 return ret;
1900 }
1901
1902 /* Must be protected by mem_hotplug_begin() */
1903 int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
1904 {
1905 return __offline_pages(start_pfn, start_pfn + nr_pages, 120 * HZ);
1906 }
1907 #endif /* CONFIG_MEMORY_HOTREMOVE */
1908
1909 /**
1910 * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn)
1911 * @start_pfn: start pfn of the memory range
1912 * @end_pfn: end pfn of the memory range
1913 * @arg: argument passed to func
1914 * @func: callback for each memory section walked
1915 *
1916 * This function walks through all present mem sections in range
1917 * [start_pfn, end_pfn) and call func on each mem section.
1918 *
1919 * Returns the return value of func.
1920 */
1921 int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
1922 void *arg, int (*func)(struct memory_block *, void *))
1923 {
1924 struct memory_block *mem = NULL;
1925 struct mem_section *section;
1926 unsigned long pfn, section_nr;
1927 int ret;
1928
1929 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
1930 section_nr = pfn_to_section_nr(pfn);
1931 if (!present_section_nr(section_nr))
1932 continue;
1933
1934 section = __nr_to_section(section_nr);
1935 /* same memblock? */
1936 if (mem)
1937 if ((section_nr >= mem->start_section_nr) &&
1938 (section_nr <= mem->end_section_nr))
1939 continue;
1940
1941 mem = find_memory_block_hinted(section, mem);
1942 if (!mem)
1943 continue;
1944
1945 ret = func(mem, arg);
1946 if (ret) {
1947 kobject_put(&mem->dev.kobj);
1948 return ret;
1949 }
1950 }
1951
1952 if (mem)
1953 kobject_put(&mem->dev.kobj);
1954
1955 return 0;
1956 }
1957
1958 #ifdef CONFIG_MEMORY_HOTREMOVE
1959 static int check_memblock_offlined_cb(struct memory_block *mem, void *arg)
1960 {
1961 int ret = !is_memblock_offlined(mem);
1962
1963 if (unlikely(ret)) {
1964 phys_addr_t beginpa, endpa;
1965
1966 beginpa = PFN_PHYS(section_nr_to_pfn(mem->start_section_nr));
1967 endpa = PFN_PHYS(section_nr_to_pfn(mem->end_section_nr + 1))-1;
1968 pr_warn("removing memory fails, because memory [%pa-%pa] is onlined\n",
1969 &beginpa, &endpa);
1970 }
1971
1972 return ret;
1973 }
1974
1975 static int check_cpu_on_node(pg_data_t *pgdat)
1976 {
1977 int cpu;
1978
1979 for_each_present_cpu(cpu) {
1980 if (cpu_to_node(cpu) == pgdat->node_id)
1981 /*
1982 * the cpu on this node isn't removed, and we can't
1983 * offline this node.
1984 */
1985 return -EBUSY;
1986 }
1987
1988 return 0;
1989 }
1990
1991 static void unmap_cpu_on_node(pg_data_t *pgdat)
1992 {
1993 #ifdef CONFIG_ACPI_NUMA
1994 int cpu;
1995
1996 for_each_possible_cpu(cpu)
1997 if (cpu_to_node(cpu) == pgdat->node_id)
1998 numa_clear_node(cpu);
1999 #endif
2000 }
2001
2002 static int check_and_unmap_cpu_on_node(pg_data_t *pgdat)
2003 {
2004 int ret;
2005
2006 ret = check_cpu_on_node(pgdat);
2007 if (ret)
2008 return ret;
2009
2010 /*
2011 * the node will be offlined when we come here, so we can clear
2012 * the cpu_to_node() now.
2013 */
2014
2015 unmap_cpu_on_node(pgdat);
2016 return 0;
2017 }
2018
2019 /**
2020 * try_offline_node
2021 *
2022 * Offline a node if all memory sections and cpus of the node are removed.
2023 *
2024 * NOTE: The caller must call lock_device_hotplug() to serialize hotplug
2025 * and online/offline operations before this call.
2026 */
2027 void try_offline_node(int nid)
2028 {
2029 pg_data_t *pgdat = NODE_DATA(nid);
2030 unsigned long start_pfn = pgdat->node_start_pfn;
2031 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
2032 unsigned long pfn;
2033
2034 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
2035 unsigned long section_nr = pfn_to_section_nr(pfn);
2036
2037 if (!present_section_nr(section_nr))
2038 continue;
2039
2040 if (pfn_to_nid(pfn) != nid)
2041 continue;
2042
2043 /*
2044 * some memory sections of this node are not removed, and we
2045 * can't offline node now.
2046 */
2047 return;
2048 }
2049
2050 if (check_and_unmap_cpu_on_node(pgdat))
2051 return;
2052
2053 /*
2054 * all memory/cpu of this node are removed, we can offline this
2055 * node now.
2056 */
2057 node_set_offline(nid);
2058 unregister_one_node(nid);
2059 }
2060 EXPORT_SYMBOL(try_offline_node);
2061
2062 /**
2063 * remove_memory
2064 *
2065 * NOTE: The caller must call lock_device_hotplug() to serialize hotplug
2066 * and online/offline operations before this call, as required by
2067 * try_offline_node().
2068 */
2069 void __ref remove_memory(int nid, u64 start, u64 size)
2070 {
2071 int ret;
2072
2073 BUG_ON(check_hotplug_memory_range(start, size));
2074
2075 mem_hotplug_begin();
2076
2077 /*
2078 * All memory blocks must be offlined before removing memory. Check
2079 * whether all memory blocks in question are offline and trigger a BUG()
2080 * if this is not the case.
2081 */
2082 ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL,
2083 check_memblock_offlined_cb);
2084 if (ret)
2085 BUG();
2086
2087 /* remove memmap entry */
2088 firmware_map_remove(start, start + size, "System RAM");
2089 memblock_free(start, size);
2090 memblock_remove(start, size);
2091
2092 arch_remove_memory(start, size);
2093
2094 try_offline_node(nid);
2095
2096 mem_hotplug_done();
2097 }
2098 EXPORT_SYMBOL_GPL(remove_memory);
2099 #endif /* CONFIG_MEMORY_HOTREMOVE */