diff options
Diffstat (limited to 'mm/memory_hotplug.c')
-rw-r--r-- | mm/memory_hotplug.c | 80 |
1 files changed, 71 insertions, 9 deletions
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 833f854eabe5..89fee2dcb039 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c | |||
@@ -62,9 +62,9 @@ static void release_memory_resource(struct resource *res) | |||
62 | 62 | ||
63 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE | 63 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
64 | #ifndef CONFIG_SPARSEMEM_VMEMMAP | 64 | #ifndef CONFIG_SPARSEMEM_VMEMMAP |
65 | static void get_page_bootmem(unsigned long info, struct page *page, int magic) | 65 | static void get_page_bootmem(unsigned long info, struct page *page, int type) |
66 | { | 66 | { |
67 | atomic_set(&page->_mapcount, magic); | 67 | atomic_set(&page->_mapcount, type); |
68 | SetPagePrivate(page); | 68 | SetPagePrivate(page); |
69 | set_page_private(page, info); | 69 | set_page_private(page, info); |
70 | atomic_inc(&page->_count); | 70 | atomic_inc(&page->_count); |
@@ -72,10 +72,10 @@ static void get_page_bootmem(unsigned long info, struct page *page, int magic) | |||
72 | 72 | ||
73 | void put_page_bootmem(struct page *page) | 73 | void put_page_bootmem(struct page *page) |
74 | { | 74 | { |
75 | int magic; | 75 | int type; |
76 | 76 | ||
77 | magic = atomic_read(&page->_mapcount); | 77 | type = atomic_read(&page->_mapcount); |
78 | BUG_ON(magic >= -1); | 78 | BUG_ON(type >= -1); |
79 | 79 | ||
80 | if (atomic_dec_return(&page->_count) == 1) { | 80 | if (atomic_dec_return(&page->_count) == 1) { |
81 | ClearPagePrivate(page); | 81 | ClearPagePrivate(page); |
@@ -86,7 +86,7 @@ void put_page_bootmem(struct page *page) | |||
86 | 86 | ||
87 | } | 87 | } |
88 | 88 | ||
89 | void register_page_bootmem_info_section(unsigned long start_pfn) | 89 | static void register_page_bootmem_info_section(unsigned long start_pfn) |
90 | { | 90 | { |
91 | unsigned long *usemap, mapsize, section_nr, i; | 91 | unsigned long *usemap, mapsize, section_nr, i; |
92 | struct mem_section *ms; | 92 | struct mem_section *ms; |
@@ -119,7 +119,7 @@ void register_page_bootmem_info_section(unsigned long start_pfn) | |||
119 | mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT; | 119 | mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT; |
120 | 120 | ||
121 | for (i = 0; i < mapsize; i++, page++) | 121 | for (i = 0; i < mapsize; i++, page++) |
122 | get_page_bootmem(section_nr, page, MIX_INFO); | 122 | get_page_bootmem(section_nr, page, MIX_SECTION_INFO); |
123 | 123 | ||
124 | } | 124 | } |
125 | 125 | ||
@@ -429,7 +429,9 @@ int online_pages(unsigned long pfn, unsigned long nr_pages) | |||
429 | 429 | ||
430 | if (need_zonelists_rebuild) | 430 | if (need_zonelists_rebuild) |
431 | build_all_zonelists(); | 431 | build_all_zonelists(); |
432 | vm_total_pages = nr_free_pagecache_pages(); | 432 | else |
433 | vm_total_pages = nr_free_pagecache_pages(); | ||
434 | |||
433 | writeback_set_ratelimit(); | 435 | writeback_set_ratelimit(); |
434 | 436 | ||
435 | if (onlined_pages) | 437 | if (onlined_pages) |
@@ -455,7 +457,7 @@ static pg_data_t *hotadd_new_pgdat(int nid, u64 start) | |||
455 | /* we can use NODE_DATA(nid) from here */ | 457 | /* we can use NODE_DATA(nid) from here */ |
456 | 458 | ||
457 | /* init node's zones as empty zones, we don't have any present pages.*/ | 459 | /* init node's zones as empty zones, we don't have any present pages.*/ |
458 | free_area_init_node(nid, pgdat, zones_size, start_pfn, zholes_size); | 460 | free_area_init_node(nid, zones_size, start_pfn, zholes_size); |
459 | 461 | ||
460 | return pgdat; | 462 | return pgdat; |
461 | } | 463 | } |
@@ -521,6 +523,66 @@ EXPORT_SYMBOL_GPL(add_memory); | |||
521 | 523 | ||
522 | #ifdef CONFIG_MEMORY_HOTREMOVE | 524 | #ifdef CONFIG_MEMORY_HOTREMOVE |
523 | /* | 525 | /* |
526 | * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy | ||
527 | * set and the size of the free page is given by page_order(). Using this, | ||
528 | * the function determines if the pageblock contains only free pages. | ||
529 | * Due to buddy contraints, a free page at least the size of a pageblock will | ||
530 | * be located at the start of the pageblock | ||
531 | */ | ||
532 | static inline int pageblock_free(struct page *page) | ||
533 | { | ||
534 | return PageBuddy(page) && page_order(page) >= pageblock_order; | ||
535 | } | ||
536 | |||
537 | /* Return the start of the next active pageblock after a given page */ | ||
538 | static struct page *next_active_pageblock(struct page *page) | ||
539 | { | ||
540 | int pageblocks_stride; | ||
541 | |||
542 | /* Ensure the starting page is pageblock-aligned */ | ||
543 | BUG_ON(page_to_pfn(page) & (pageblock_nr_pages - 1)); | ||
544 | |||
545 | /* Move forward by at least 1 * pageblock_nr_pages */ | ||
546 | pageblocks_stride = 1; | ||
547 | |||
548 | /* If the entire pageblock is free, move to the end of free page */ | ||
549 | if (pageblock_free(page)) | ||
550 | pageblocks_stride += page_order(page) - pageblock_order; | ||
551 | |||
552 | return page + (pageblocks_stride * pageblock_nr_pages); | ||
553 | } | ||
554 | |||
555 | /* Checks if this range of memory is likely to be hot-removable. */ | ||
556 | int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages) | ||
557 | { | ||
558 | int type; | ||
559 | struct page *page = pfn_to_page(start_pfn); | ||
560 | struct page *end_page = page + nr_pages; | ||
561 | |||
562 | /* Check the starting page of each pageblock within the range */ | ||
563 | for (; page < end_page; page = next_active_pageblock(page)) { | ||
564 | type = get_pageblock_migratetype(page); | ||
565 | |||
566 | /* | ||
567 | * A pageblock containing MOVABLE or free pages is considered | ||
568 | * removable | ||
569 | */ | ||
570 | if (type != MIGRATE_MOVABLE && !pageblock_free(page)) | ||
571 | return 0; | ||
572 | |||
573 | /* | ||
574 | * A pageblock starting with a PageReserved page is not | ||
575 | * considered removable. | ||
576 | */ | ||
577 | if (PageReserved(page)) | ||
578 | return 0; | ||
579 | } | ||
580 | |||
581 | /* All pageblocks in the memory block are likely to be hot-removable */ | ||
582 | return 1; | ||
583 | } | ||
584 | |||
585 | /* | ||
524 | * Confirm all pages in a range [start, end) is belongs to the same zone. | 586 | * Confirm all pages in a range [start, end) is belongs to the same zone. |
525 | */ | 587 | */ |
526 | static int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn) | 588 | static int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn) |