History

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>

Qian Cai committed 7 years ago

Commit 9b7ea461 parent 73601ea5 files · +45 −34Browse files

Unified · Split

5 files
  1. include/linux/page-isolation.h +0 −10
  2. mm/memory_hotplug.c +13 −4
  3. mm/page_alloc.c +1 −1
  4. mm/page_isolation.c +30 −18
  5. mm/sparse.c +1 −1
include/linux/page-isolation.h+0−10
@@ -41,16 +41,6 @@ int move_freepages_block(struct zone *zone, struct page *page, · 40 unmodified lines
4141
4242 /*
4343 * 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
5444 */
5545 int
5646 start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
mm/memory_hotplug.c+13−4
@@ -1576,7 +1576,7 @@ static int __ref __offline_pages(unsigned long start_pfn, · 1575 unmodified lines
15761576 {
15771577 unsigned long pfn, nr_pages;
15781578 long offlined_pages;
1579− int ret, node;
1579+ int ret, node, nr_isolate_pageblock;
15801580 unsigned long flags;
15811581 unsigned long valid_start, valid_end;
15821582 struct zone *zone;
@@ -1602,10 +1602,11 @@ static int __ref __offline_pages(unsigned long start_pfn, · 19 unmodified lines
16021602 ret = start_isolate_page_range(start_pfn, end_pfn,
16031603 MIGRATE_MOVABLE,
16041604 SKIP_HWPOISON | REPORT_FAILURE);
1605− if (ret) {
1605+ if (ret < 0) {
16061606 reason = "failure to isolate range";
16071607 goto failed_removal;
16081608 }
1609+ nr_isolate_pageblock = ret;
16091610
16101611 arg.start_pfn = start_pfn;
16111612 arg.nr_pages = nr_pages;
@@ -1657,8 +1658,16 @@ static int __ref __offline_pages(unsigned long start_pfn, · 45 unmodified lines
16571658 /* Ok, all of our target is isolated.
16581659 We cannot do rollback at this point. */
16591660 offline_isolated_pages(start_pfn, end_pfn);
1660− /* reset pagetype flags and makes migrate type to be MOVABLE */
1661− undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
1661+
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+
16621671 /* removal success */
16631672 adjust_managed_page_count(pfn_to_page(start_pfn), -offlined_pages);
16641673 zone->present_pages -= offlined_pages;
mm/page_alloc.c+1−1
@@ -8233,7 +8233,7 @@ int alloc_contig_range(unsigned long start, unsigned long end, · 8232 unmodified lines
82338233
82348234 ret = start_isolate_page_range(pfn_max_align_down(start),
82358235 pfn_max_align_up(end), migratetype, 0);
8236− if (ret)
8236+ if (ret < 0)
82378237 return ret;
82388238
82398239 /*
mm/page_isolation.c+30−18
@@ -160,27 +160,36 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages) · 159 unmodified lines
160160 return NULL;
161161 }
162162
163−/*
164− * start_isolate_page_range() -- make page-allocation-type of range of pages
165− * to be MIGRATE_ISOLATE.
166− * @start_pfn: The lower 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.
163+/**
164+ * start_isolate_page_range() - make page-allocation-type of range of pages to
165+ * be MIGRATE_ISOLATE.
166+ * @start_pfn: The lower PFN of the range to be isolated.
167+ * @end_pfn: The upper PFN of the range to be isolated.
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
169175 *
170176 * Making page-allocation-type to be MIGRATE_ISOLATE means free pages in
171177 * the range will never be allocated. Any free pages and pages freed in the
172− * future will not be allocated again.
173− *
174− * start_pfn/end_pfn must be aligned to pageblock_order.
175− * Return 0 on success and -EBUSY if any part of range cannot be isolated.
178+ * future will not be allocated again. If specified range includes migrate types
179+ * other than MOVABLE or CMA, this will fail with -EBUSY. For isolating all
180+ * pages in the range finally, the caller have to free all pages in the range.
181+ * test_page_isolated() can be used for test it.
176182 *
177183 * 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
179185 * will notice pageblocks in the overlapping range already set to isolate.
180186 * This happens in set_migratetype_isolate, and set_migratetype_isolate
181− * 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
187+ * returns an error. We then clean up by restoring the migration type on
188+ * pageblocks we may have modified and return -EBUSY to caller. This
183189 * 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.
184193 */
185194 int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
186195 unsigned migratetype, int flags)
@@ -188,6 +197,7 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, · 1 unmodified line
188197 unsigned long pfn;
189198 unsigned long undo_pfn;
190199 struct page *page;
200+ int nr_isolate_pageblock = 0;
191201
192202 BUG_ON(!IS_ALIGNED(start_pfn, pageblock_nr_pages));
193203 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, · 2 unmodified lines
196206 pfn < end_pfn;
197207 pfn += pageblock_nr_pages) {
198208 page = __first_valid_page(pfn, pageblock_nr_pages);
199− if (page &&
200− set_migratetype_isolate(page, migratetype, flags)) {
201− undo_pfn = pfn;
202− goto undo;
209+ if (page) {
210+ if (set_migratetype_isolate(page, migratetype, flags)) {
211+ undo_pfn = pfn;
212+ goto undo;
213+ }
214+ nr_isolate_pageblock++;
203215 }
204216 }
205− return 0;
217+ return nr_isolate_pageblock;
206218 undo:
207219 for (pfn = start_pfn;
208220 pfn < undo_pfn;
mm/sparse.c+1−1
@@ -567,7 +567,7 @@ void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn) · 566 unmodified lines
567567 }
568568
569569 #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 */
571571 void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
572572 {
573573 unsigned long pfn;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t