aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQian Cai <cai@lca.pw>2019-03-28 23:43:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-29 13:01:37 -0400
commit9b7ea46a82b31c74a37e6ff1c2a1df7d53e392ab (patch)
tree2cb350d34d5fa97854324511572bb38d6b2c474d
parent73601ea5b7b18eb234219ae2adf77530f389da79 (diff)
mm/hotplug: fix offline undo_isolate_page_range()
Commit f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") introduced move_pfn_range_to_zone() which calls memmap_init_zone() during onlining a memory block. memmap_init_zone() will reset pagetype flags and makes migrate type to be MOVABLE. However, in __offline_pages(), it also call undo_isolate_page_range() after offline_isolated_pages() to do the same thing. Due to commit 2ce13640b3f4 ("mm: __first_valid_page skip over offline pages") changed __first_valid_page() to skip offline pages, undo_isolate_page_range() here just waste CPU cycles looping around the offlining PFN range while doing nothing, because __first_valid_page() will return NULL as offline_isolated_pages() has already marked all memory sections within the pfn range as offline via offline_mem_sections(). Also, after calling the "useless" undo_isolate_page_range() here, it reaches the point of no returning by notifying MEM_OFFLINE. Those pages will be marked as MIGRATE_MOVABLE again once onlining. The only thing left to do is to decrease the number of isolated pageblocks zone counter which would make some paths of the page allocation slower that the above commit introduced. Even if alloc_contig_range() can be used to isolate 16GB-hugetlb pages on ppc64, an "int" should still be enough to represent the number of pageblocks there. Fix an incorrect comment along the way. [cai@lca.pw: v4] Link: http://lkml.kernel.org/r/20190314150641.59358-1-cai@lca.pw Link: http://lkml.kernel.org/r/20190313143133.46200-1-cai@lca.pw Fixes: 2ce13640b3f4 ("mm: __first_valid_page skip over offline pages") Signed-off-by: Qian Cai <cai@lca.pw> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Oscar Salvador <osalvador@suse.de> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: <stable@vger.kernel.org> [4.13+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/page-isolation.h10
-rw-r--r--mm/memory_hotplug.c17
-rw-r--r--mm/page_alloc.c2
-rw-r--r--mm/page_isolation.c48
-rw-r--r--mm/sparse.c2
5 files changed, 45 insertions, 34 deletions
diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h
index 4eb26d278046..280ae96dc4c3 100644
--- a/include/linux/page-isolation.h
+++ b/include/linux/page-isolation.h
@@ -41,16 +41,6 @@ int move_freepages_block(struct zone *zone, struct page *page,
41 41
42/* 42/*
43 * Changes migrate type in [start_pfn, end_pfn) to be MIGRATE_ISOLATE. 43 * Changes migrate type in [start_pfn, end_pfn) to be MIGRATE_ISOLATE.
44 * If specified range includes migrate types other than MOVABLE or CMA,
45 * this will fail with -EBUSY.
46 *
47 * For isolating all pages in the range finally, the caller have to
48 * free all pages in the range. test_page_isolated() can be used for
49 * test it.
50 *
51 * The following flags are allowed (they can be combined in a bit mask)
52 * SKIP_HWPOISON - ignore hwpoison pages
53 * REPORT_FAILURE - report details about the failure to isolate the range
54 */ 44 */
55int 45int
56start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, 46start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index f767582af4f8..0e0a16021fd5 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1576,7 +1576,7 @@ static int __ref __offline_pages(unsigned long start_pfn,
1576{ 1576{
1577 unsigned long pfn, nr_pages; 1577 unsigned long pfn, nr_pages;
1578 long offlined_pages; 1578 long offlined_pages;
1579 int ret, node; 1579 int ret, node, nr_isolate_pageblock;
1580 unsigned long flags; 1580 unsigned long flags;
1581 unsigned long valid_start, valid_end; 1581 unsigned long valid_start, valid_end;
1582 struct zone *zone; 1582 struct zone *zone;
@@ -1602,10 +1602,11 @@ static int __ref __offline_pages(unsigned long start_pfn,
1602 ret = start_isolate_page_range(start_pfn, end_pfn, 1602 ret = start_isolate_page_range(start_pfn, end_pfn,
1603 MIGRATE_MOVABLE, 1603 MIGRATE_MOVABLE,
1604 SKIP_HWPOISON | REPORT_FAILURE); 1604 SKIP_HWPOISON | REPORT_FAILURE);
1605 if (ret) { 1605 if (ret < 0) {
1606 reason = "failure to isolate range"; 1606 reason = "failure to isolate range";
1607 goto failed_removal; 1607 goto failed_removal;
1608 } 1608 }
1609 nr_isolate_pageblock = ret;
1609 1610
1610 arg.start_pfn = start_pfn; 1611 arg.start_pfn = start_pfn;
1611 arg.nr_pages = nr_pages; 1612 arg.nr_pages = nr_pages;
@@ -1657,8 +1658,16 @@ static int __ref __offline_pages(unsigned long start_pfn,
1657 /* Ok, all of our target is isolated. 1658 /* Ok, all of our target is isolated.
1658 We cannot do rollback at this point. */ 1659 We cannot do rollback at this point. */
1659 offline_isolated_pages(start_pfn, end_pfn); 1660 offline_isolated_pages(start_pfn, end_pfn);
1660 /* reset pagetype flags and makes migrate type to be MOVABLE */ 1661
1661 undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); 1662 /*
1663 * Onlining will reset pagetype flags and makes migrate type
1664 * MOVABLE, so just need to decrease the number of isolated
1665 * pageblocks zone counter here.
1666 */
1667 spin_lock_irqsave(&zone->lock, flags);
1668 zone->nr_isolate_pageblock -= nr_isolate_pageblock;
1669 spin_unlock_irqrestore(&zone->lock, flags);
1670
1662 /* removal success */ 1671 /* removal success */
1663 adjust_managed_page_count(pfn_to_page(start_pfn), -offlined_pages); 1672 adjust_managed_page_count(pfn_to_page(start_pfn), -offlined_pages);
1664 zone->present_pages -= offlined_pages; 1673 zone->present_pages -= offlined_pages;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 03fcf73d47da..d96ca5bc555b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8233,7 +8233,7 @@ int alloc_contig_range(unsigned long start, unsigned long end,
8233 8233
8234 ret = start_isolate_page_range(pfn_max_align_down(start), 8234 ret = start_isolate_page_range(pfn_max_align_down(start),
8235 pfn_max_align_up(end), migratetype, 0); 8235 pfn_max_align_up(end), migratetype, 0);
8236 if (ret) 8236 if (ret < 0)
8237 return ret; 8237 return ret;
8238 8238
8239 /* 8239 /*
diff --git a/mm/page_isolation.c b/mm/page_isolation.c
index ce323e56b34d..bf4159d771c7 100644
--- a/mm/page_isolation.c
+++ b/mm/page_isolation.c
@@ -160,27 +160,36 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages)
160 return NULL; 160 return NULL;
161} 161}
162 162
163/* 163/**
164 * start_isolate_page_range() -- make page-allocation-type of range of pages 164 * start_isolate_page_range() - make page-allocation-type of range of pages to
165 * to be MIGRATE_ISOLATE. 165 * be MIGRATE_ISOLATE.
166 * @start_pfn: The lower PFN of the range to be isolated. 166 * @start_pfn: The lower PFN of the range to be isolated.
167 * @end_pfn: The upper PFN of the range to be isolated. 167 * @end_pfn: The upper PFN of the range to be isolated.
168 * @migratetype: migrate type to set in error recovery. 168 * start_pfn/end_pfn must be aligned to pageblock_order.
169 * @migratetype: Migrate type to set in error recovery.
170 * @flags: The following flags are allowed (they can be combined in
171 * a bit mask)
172 * SKIP_HWPOISON - ignore hwpoison pages
173 * REPORT_FAILURE - report details about the failure to
174 * isolate the range
169 * 175 *
170 * Making page-allocation-type to be MIGRATE_ISOLATE means free pages in 176 * Making page-allocation-type to be MIGRATE_ISOLATE means free pages in
171 * the range will never be allocated. Any free pages and pages freed in the 177 * the range will never be allocated. Any free pages and pages freed in the
172 * future will not be allocated again. 178 * future will not be allocated again. If specified range includes migrate types
173 * 179 * other than MOVABLE or CMA, this will fail with -EBUSY. For isolating all
174 * start_pfn/end_pfn must be aligned to pageblock_order. 180 * pages in the range finally, the caller have to free all pages in the range.
175 * Return 0 on success and -EBUSY if any part of range cannot be isolated. 181 * test_page_isolated() can be used for test it.
176 * 182 *
177 * There is no high level synchronization mechanism that prevents two threads 183 * There is no high level synchronization mechanism that prevents two threads
178 * from trying to isolate overlapping ranges. If this happens, one thread 184 * from trying to isolate overlapping ranges. If this happens, one thread
179 * will notice pageblocks in the overlapping range already set to isolate. 185 * will notice pageblocks in the overlapping range already set to isolate.
180 * This happens in set_migratetype_isolate, and set_migratetype_isolate 186 * This happens in set_migratetype_isolate, and set_migratetype_isolate
181 * returns an error. We then clean up by restoring the migration type on 187 * returns an error. We then clean up by restoring the migration type on
182 * pageblocks we may have modified and return -EBUSY to caller. This 188 * pageblocks we may have modified and return -EBUSY to caller. This
183 * prevents two threads from simultaneously working on overlapping ranges. 189 * prevents two threads from simultaneously working on overlapping ranges.
190 *
191 * Return: the number of isolated pageblocks on success and -EBUSY if any part
192 * of range cannot be isolated.
184 */ 193 */
185int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, 194int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
186 unsigned migratetype, int flags) 195 unsigned migratetype, int flags)
@@ -188,6 +197,7 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
188 unsigned long pfn; 197 unsigned long pfn;
189 unsigned long undo_pfn; 198 unsigned long undo_pfn;
190 struct page *page; 199 struct page *page;
200 int nr_isolate_pageblock = 0;
191 201
192 BUG_ON(!IS_ALIGNED(start_pfn, pageblock_nr_pages)); 202 BUG_ON(!IS_ALIGNED(start_pfn, pageblock_nr_pages));
193 BUG_ON(!IS_ALIGNED(end_pfn, pageblock_nr_pages)); 203 BUG_ON(!IS_ALIGNED(end_pfn, pageblock_nr_pages));
@@ -196,13 +206,15 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
196 pfn < end_pfn; 206 pfn < end_pfn;
197 pfn += pageblock_nr_pages) { 207 pfn += pageblock_nr_pages) {
198 page = __first_valid_page(pfn, pageblock_nr_pages); 208 page = __first_valid_page(pfn, pageblock_nr_pages);
199 if (page && 209 if (page) {
200 set_migratetype_isolate(page, migratetype, flags)) { 210 if (set_migratetype_isolate(page, migratetype, flags)) {
201 undo_pfn = pfn; 211 undo_pfn = pfn;
202 goto undo; 212 goto undo;
213 }
214 nr_isolate_pageblock++;
203 } 215 }
204 } 216 }
205 return 0; 217 return nr_isolate_pageblock;
206undo: 218undo:
207 for (pfn = start_pfn; 219 for (pfn = start_pfn;
208 pfn < undo_pfn; 220 pfn < undo_pfn;
diff --git a/mm/sparse.c b/mm/sparse.c
index 69904aa6165b..56e057c432f9 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -567,7 +567,7 @@ void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
567} 567}
568 568
569#ifdef CONFIG_MEMORY_HOTREMOVE 569#ifdef CONFIG_MEMORY_HOTREMOVE
570/* Mark all memory sections within the pfn range as online */ 570/* Mark all memory sections within the pfn range as offline */
571void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn) 571void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
572{ 572{
573 unsigned long pfn; 573 unsigned long pfn;