The patch titled Subject: mm/compaction: fix misbehaviors of fast_find_migrateblock() has been added to the -mm tree. Its filename is mm-compactoin-fix-misbehaviors-of-fast_find_migrateblock.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-compactoin-fix-misbehaviors-of-fast_find_migrateblock.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-compactoin-fix-misbehaviors-of-fast_find_migrateblock.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Wonhyuk Yang <vvghjk1234@xxxxxxxxx> Subject: mm/compaction: fix misbehaviors of fast_find_migrateblock() In the fast_find_migrateblock(), It iterate freelist to find proper pageblock. But there are some misbehaviors. First, if the page we found is equal to cc->migrate_pfn, it is considered that we didn't found suitable pageblock. Second, if the loop was terminated because order is less than PAGE_ALLOC_COSTLY_ORDER, it could be considered that we found suitable one. Third, if the skip bit is set on the page block and go continue, it doesn't check the nr_scanned. Fourth, if the page block's skip bit is set, it check that page block is the last of list. But it is unnecessary. Link: https://lkml.kernel.org/r/20210128130411.6125-1-vvghjk1234@xxxxxxxxx Fixes: 70b44595eafe9 ("mm, compaction: use free lists to quickly locate a migration source") Signed-off-by: Wonhyuk Yang <vvghjk1234@xxxxxxxxx> Acked-by: Vlastimil Babka <vbabka@xxxxxxx> Cc: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/compaction.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) --- a/mm/compaction.c~mm-compactoin-fix-misbehaviors-of-fast_find_migrateblock +++ a/mm/compaction.c @@ -1698,6 +1698,7 @@ static unsigned long fast_find_migratebl unsigned long pfn = cc->migrate_pfn; unsigned long high_pfn; int order; + bool found_block = false; /* Skip hints are relied on to avoid repeats on the fast search */ if (cc->ignore_skip_hint) @@ -1740,7 +1741,7 @@ static unsigned long fast_find_migratebl high_pfn = pageblock_start_pfn(cc->migrate_pfn + distance); for (order = cc->order - 1; - order >= PAGE_ALLOC_COSTLY_ORDER && pfn == cc->migrate_pfn && nr_scanned < limit; + order >= PAGE_ALLOC_COSTLY_ORDER && !found_block && nr_scanned < limit; order--) { struct free_area *area = &cc->zone->free_area[order]; struct list_head *freelist; @@ -1755,7 +1756,11 @@ static unsigned long fast_find_migratebl list_for_each_entry(freepage, freelist, lru) { unsigned long free_pfn; - nr_scanned++; + if (nr_scanned++ >= limit) { + move_freelist_tail(freelist, freepage); + break; + } + free_pfn = page_to_pfn(freepage); if (free_pfn < high_pfn) { /* @@ -1764,12 +1769,8 @@ static unsigned long fast_find_migratebl * the list assumes an entry is deleted, not * reordered. */ - if (get_pageblock_skip(freepage)) { - if (list_is_last(freelist, &freepage->lru)) - break; - + if (get_pageblock_skip(freepage)) continue; - } /* Reorder to so a future search skips recent pages */ move_freelist_tail(freelist, freepage); @@ -1777,15 +1778,10 @@ static unsigned long fast_find_migratebl update_fast_start_pfn(cc, free_pfn); pfn = pageblock_start_pfn(free_pfn); cc->fast_search_fail = 0; + found_block = true; set_pageblock_skip(freepage); break; } - - if (nr_scanned >= limit) { - cc->fast_search_fail++; - move_freelist_tail(freelist, freepage); - break; - } } spin_unlock_irqrestore(&cc->zone->lock, flags); } @@ -1796,9 +1792,10 @@ static unsigned long fast_find_migratebl * If fast scanning failed then use a cached entry for a page block * that had free pages as the basis for starting a linear scan. */ - if (pfn == cc->migrate_pfn) + if (!found_block) { + cc->fast_search_fail++; pfn = reinit_migrate_pfn(cc); - + } return pfn; } _ Patches currently in -mm which might be from vvghjk1234@xxxxxxxxx are mm-compactoin-fix-misbehaviors-of-fast_find_migrateblock.patch