From b11a0e3d8f9d7d91a884c90dc9cebb185c3a2bbc Mon Sep 17 00:00:00 2001 From: Zi Yan Date: Mon, 25 Sep 2023 16:27:14 -0400 Subject: [PATCH 2/3] mm: set migratetype after free pages are moved between free lists. 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. Signed-off-by: Zi Yan --- mm/page_alloc.c | 10 +++------- mm/page_isolation.c | 2 -- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 72f27d14c8e7..7c41cb5d8a36 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1618,6 +1618,7 @@ static int move_freepages(struct zone *zone, unsigned long start_pfn, pfn += 1 << order; pages_moved += 1 << order; } + set_pageblock_migratetype(pfn_to_page(start_pfn), new_mt); return pages_moved; } @@ -1839,7 +1840,6 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page, if (free_pages + alike_pages >= (1 << (pageblock_order-1)) || page_group_by_mobility_disabled) { move_freepages(zone, start_pfn, end_pfn, block_type, start_type); - set_pageblock_migratetype(page, start_type); block_type = start_type; } @@ -1911,7 +1911,6 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone) if (migratetype_is_mergeable(mt)) { if (move_freepages_block(zone, page, mt, MIGRATE_HIGHATOMIC) != -1) { - set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC); zone->nr_reserved_highatomic += pageblock_nr_pages; } } @@ -1996,7 +1995,6 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, * not fail on zone boundaries. */ WARN_ON_ONCE(ret == -1); - set_pageblock_migratetype(page, ac->migratetype); if (ret > 0) { spin_unlock_irqrestore(&zone->lock, flags); return ret; @@ -2608,10 +2606,8 @@ int __isolate_free_page(struct page *page, unsigned int order) * Only change normal pageblocks (i.e., they can merge * with others) */ - if (migratetype_is_mergeable(mt) && - move_freepages_block(zone, page, mt, - MIGRATE_MOVABLE) != -1) - set_pageblock_migratetype(page, MIGRATE_MOVABLE); + if (migratetype_is_mergeable(mt)) + move_freepages_block(zone, page, mt, MIGRATE_MOVABLE); } } diff --git a/mm/page_isolation.c b/mm/page_isolation.c index b5c7a9d21257..ee7818ff4e12 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -187,7 +187,6 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ spin_unlock_irqrestore(&zone->lock, flags); return -EBUSY; } - set_pageblock_migratetype(page, MIGRATE_ISOLATE); zone->nr_isolate_pageblock++; spin_unlock_irqrestore(&zone->lock, flags); return 0; @@ -262,7 +261,6 @@ static void unset_migratetype_isolate(struct page *page, int migratetype) */ WARN_ON_ONCE(nr_pages == -1); } - set_pageblock_migratetype(page, migratetype); if (isolated_page) __putback_isolated_page(page, order, migratetype); zone->nr_isolate_pageblock--; -- 2.40.1