Skip to content

Commit f37c0f6

Browse files
x-y-zakpm00
authored andcommitted
mm: page_alloc: set migratetype inside move_freepages()
This avoids changing migratetype after move_freepages() or move_freepages_block(), which is error prone. It also prepares for upcoming changes to fix move_freepages() not moving free pages partially in the range. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Zi Yan <[email protected]> Signed-off-by: Johannes Weiner <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Tested-by: Baolin Wang <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: "Huang, Ying" <[email protected]> Cc: Mel Gorman <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 55612e8 commit f37c0f6

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

mm/page_alloc.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,9 +1586,8 @@ static inline struct page *__rmqueue_cma_fallback(struct zone *zone,
15861586
#endif
15871587

15881588
/*
1589-
* Move the free pages in a range to the freelist tail of the requested type.
1590-
* Note that start_page and end_pages are not aligned on a pageblock
1591-
* boundary. If alignment is required, use move_freepages_block()
1589+
* Change the type of a block and move all its free pages to that
1590+
* type's freelist.
15921591
*/
15931592
static int move_freepages(struct zone *zone, unsigned long start_pfn,
15941593
unsigned long end_pfn, int migratetype)
@@ -1598,6 +1597,9 @@ static int move_freepages(struct zone *zone, unsigned long start_pfn,
15981597
unsigned int order;
15991598
int pages_moved = 0;
16001599

1600+
VM_WARN_ON(start_pfn & (pageblock_nr_pages - 1));
1601+
VM_WARN_ON(start_pfn + pageblock_nr_pages - 1 != end_pfn);
1602+
16011603
for (pfn = start_pfn; pfn <= end_pfn;) {
16021604
page = pfn_to_page(pfn);
16031605
if (!PageBuddy(page)) {
@@ -1615,6 +1617,8 @@ static int move_freepages(struct zone *zone, unsigned long start_pfn,
16151617
pages_moved += 1 << order;
16161618
}
16171619

1620+
set_pageblock_migratetype(pfn_to_page(start_pfn), migratetype);
1621+
16181622
return pages_moved;
16191623
}
16201624

@@ -1842,7 +1846,6 @@ steal_suitable_fallback(struct zone *zone, struct page *page,
18421846
if (free_pages + alike_pages >= (1 << (pageblock_order-1)) ||
18431847
page_group_by_mobility_disabled) {
18441848
move_freepages(zone, start_pfn, end_pfn, start_type);
1845-
set_pageblock_migratetype(page, start_type);
18461849
return __rmqueue_smallest(zone, order, start_type);
18471850
}
18481851

@@ -1916,12 +1919,10 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone)
19161919
/* Yoink! */
19171920
mt = get_pageblock_migratetype(page);
19181921
/* Only reserve normal pageblocks (i.e., they can merge with others) */
1919-
if (migratetype_is_mergeable(mt)) {
1920-
if (move_freepages_block(zone, page, MIGRATE_HIGHATOMIC) != -1) {
1921-
set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC);
1922+
if (migratetype_is_mergeable(mt))
1923+
if (move_freepages_block(zone, page,
1924+
MIGRATE_HIGHATOMIC) != -1)
19221925
zone->nr_reserved_highatomic += pageblock_nr_pages;
1923-
}
1924-
}
19251926

19261927
out_unlock:
19271928
spin_unlock_irqrestore(&zone->lock, flags);
@@ -2000,7 +2001,6 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,
20002001
* not fail on zone boundaries.
20012002
*/
20022003
WARN_ON_ONCE(ret == -1);
2003-
set_pageblock_migratetype(page, ac->migratetype);
20042004
if (ret > 0) {
20052005
spin_unlock_irqrestore(&zone->lock, flags);
20062006
return ret;
@@ -2682,10 +2682,9 @@ int __isolate_free_page(struct page *page, unsigned int order)
26822682
* Only change normal pageblocks (i.e., they can merge
26832683
* with others)
26842684
*/
2685-
if (migratetype_is_mergeable(mt) &&
2686-
move_freepages_block(zone, page,
2687-
MIGRATE_MOVABLE) != -1)
2688-
set_pageblock_migratetype(page, MIGRATE_MOVABLE);
2685+
if (migratetype_is_mergeable(mt))
2686+
move_freepages_block(zone, page,
2687+
MIGRATE_MOVABLE);
26892688
}
26902689
}
26912690

mm/page_isolation.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_
188188
return -EBUSY;
189189
}
190190
__mod_zone_freepage_state(zone, -nr_pages, mt);
191-
set_pageblock_migratetype(page, MIGRATE_ISOLATE);
192191
zone->nr_isolate_pageblock++;
193192
spin_unlock_irqrestore(&zone->lock, flags);
194193
return 0;
@@ -262,10 +261,10 @@ static void unset_migratetype_isolate(struct page *page, int migratetype)
262261
*/
263262
WARN_ON_ONCE(nr_pages == -1);
264263
__mod_zone_freepage_state(zone, nr_pages, migratetype);
265-
}
266-
set_pageblock_migratetype(page, migratetype);
267-
if (isolated_page)
264+
} else {
265+
set_pageblock_migratetype(page, migratetype);
268266
__putback_isolated_page(page, order, migratetype);
267+
}
269268
zone->nr_isolate_pageblock--;
270269
out:
271270
spin_unlock_irqrestore(&zone->lock, flags);

0 commit comments

Comments
 (0)