Skip to content

Commit 844fbae

Browse files
x-y-zakpm00
authored andcommitted
mm: page_isolation: check specified range for unmovable pages
Enable set_migratetype_isolate() to check specified range for unmovable pages during isolation to prepare arbitrary range page isolation. The functionality will take effect in upcoming commits by adjusting the callers of start_isolate_page_range(), which uses set_migratetype_isolate(). For example, alloc_contig_range(), which calls start_isolate_page_range(), accepts unaligned ranges, but because page isolation is currently done at MAX_ORDER_NR_PAEGS granularity, pages that are out of the specified range but withint MAX_ORDER_NR_PAEGS alignment might be attempted for isolation and the failure of isolating these unrelated pages fails the whole operation undesirably. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Zi Yan <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Eric Ren <[email protected]> Cc: kernel test robot <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b48d8a8 commit 844fbae

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

mm/page_isolation.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include <trace/events/page_isolation.h>
1717

1818
/*
19-
* This function checks whether pageblock includes unmovable pages or not.
19+
* This function checks whether the range [start_pfn, end_pfn) includes
20+
* unmovable pages or not. The range must fall into a single pageblock and
21+
* consequently belong to a single zone.
2022
*
2123
* PageLRU check without isolation or lru_lock could race so that
2224
* MIGRATE_MOVABLE block might include unmovable pages. And __PageMovable
@@ -28,12 +30,15 @@
2830
* cannot get removed (e.g., via memory unplug) concurrently.
2931
*
3032
*/
31-
static struct page *has_unmovable_pages(struct zone *zone, struct page *page,
32-
int migratetype, int flags)
33+
static struct page *has_unmovable_pages(unsigned long start_pfn, unsigned long end_pfn,
34+
int migratetype, int flags)
3335
{
34-
unsigned long iter = 0;
35-
unsigned long pfn = page_to_pfn(page);
36-
unsigned long offset = pfn % pageblock_nr_pages;
36+
struct page *page = pfn_to_page(start_pfn);
37+
struct zone *zone = page_zone(page);
38+
unsigned long pfn;
39+
40+
VM_BUG_ON(ALIGN_DOWN(start_pfn, pageblock_nr_pages) !=
41+
ALIGN_DOWN(end_pfn - 1, pageblock_nr_pages));
3742

3843
if (is_migrate_cma_page(page)) {
3944
/*
@@ -47,8 +52,8 @@ static struct page *has_unmovable_pages(struct zone *zone, struct page *page,
4752
return page;
4853
}
4954

50-
for (; iter < pageblock_nr_pages - offset; iter++) {
51-
page = pfn_to_page(pfn + iter);
55+
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
56+
page = pfn_to_page(pfn);
5257

5358
/*
5459
* Both, bootmem allocations and memory holes are marked
@@ -85,7 +90,7 @@ static struct page *has_unmovable_pages(struct zone *zone, struct page *page,
8590
}
8691

8792
skip_pages = compound_nr(head) - (page - head);
88-
iter += skip_pages - 1;
93+
pfn += skip_pages - 1;
8994
continue;
9095
}
9196

@@ -97,7 +102,7 @@ static struct page *has_unmovable_pages(struct zone *zone, struct page *page,
97102
*/
98103
if (!page_ref_count(page)) {
99104
if (PageBuddy(page))
100-
iter += (1 << buddy_order(page)) - 1;
105+
pfn += (1 << buddy_order(page)) - 1;
101106
continue;
102107
}
103108

@@ -134,11 +139,18 @@ static struct page *has_unmovable_pages(struct zone *zone, struct page *page,
134139
return NULL;
135140
}
136141

137-
static int set_migratetype_isolate(struct page *page, int migratetype, int isol_flags)
142+
/*
143+
* This function set pageblock migratetype to isolate if no unmovable page is
144+
* present in [start_pfn, end_pfn). The pageblock must intersect with
145+
* [start_pfn, end_pfn).
146+
*/
147+
static int set_migratetype_isolate(struct page *page, int migratetype, int isol_flags,
148+
unsigned long start_pfn, unsigned long end_pfn)
138149
{
139150
struct zone *zone = page_zone(page);
140151
struct page *unmovable;
141152
unsigned long flags;
153+
unsigned long check_unmovable_start, check_unmovable_end;
142154

143155
spin_lock_irqsave(&zone->lock, flags);
144156

@@ -155,8 +167,16 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_
155167
/*
156168
* FIXME: Now, memory hotplug doesn't call shrink_slab() by itself.
157169
* We just check MOVABLE pages.
170+
*
171+
* Pass the intersection of [start_pfn, end_pfn) and the page's pageblock
172+
* to avoid redundant checks.
158173
*/
159-
unmovable = has_unmovable_pages(zone, page, migratetype, isol_flags);
174+
check_unmovable_start = max(page_to_pfn(page), start_pfn);
175+
check_unmovable_end = min(ALIGN(page_to_pfn(page) + 1, pageblock_nr_pages),
176+
end_pfn);
177+
178+
unmovable = has_unmovable_pages(check_unmovable_start, check_unmovable_end,
179+
migratetype, isol_flags);
160180
if (!unmovable) {
161181
unsigned long nr_pages;
162182
int mt = get_pageblock_migratetype(page);
@@ -313,7 +333,8 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
313333
pfn < end_pfn;
314334
pfn += pageblock_nr_pages) {
315335
page = __first_valid_page(pfn, pageblock_nr_pages);
316-
if (page && set_migratetype_isolate(page, migratetype, flags)) {
336+
if (page && set_migratetype_isolate(page, migratetype, flags,
337+
start_pfn, end_pfn)) {
317338
undo_isolate_page_range(start_pfn, pfn, migratetype);
318339
return -EBUSY;
319340
}

0 commit comments

Comments
 (0)