Skip to content

Commit 7262f20

Browse files
x-y-zakpm00
authored andcommitted
mm/migrate: split source folio if it is on deferred split list
If the source folio is on deferred split list, it is likely some subpages are not used. Split it before migration to avoid migrating unused subpages. Commit 616b837 ("mm: thp: enable thp migration in generic path") did not check if a THP is on deferred split list before migration, thus, the destination THP is never put on deferred split list even if the source THP might be. The opportunity of reclaiming free pages in a partially mapped THP during deferred list scanning is lost, but no other harmful consequence is present[1]. [1]: https://lore.kernel.org/linux-mm/[email protected]/ [[email protected]: fix an error in migrate_misplaced_folio()] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 616b837 ("mm: thp: enable thp migration in generic path") Signed-off-by: Zi Yan <[email protected]> Tested-by: Baolin Wang <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Huang, Ying <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: SeongJae Park <[email protected]> Cc: Yang Shi <[email protected]> Cc: Yin Fengwei <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 73bc328 commit 7262f20

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

mm/migrate.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,29 @@ static int migrate_pages_batch(struct list_head *from,
16521652

16531653
cond_resched();
16541654

1655+
/*
1656+
* The rare folio on the deferred split list should
1657+
* be split now. It should not count as a failure.
1658+
* Only check it without removing it from the list.
1659+
* Since the folio can be on deferred_split_scan()
1660+
* local list and removing it can cause the local list
1661+
* corruption. Folio split process below can handle it
1662+
* with the help of folio_ref_freeze().
1663+
*
1664+
* nr_pages > 2 is needed to avoid checking order-1
1665+
* page cache folios. They exist, in contrast to
1666+
* non-existent order-1 anonymous folios, and do not
1667+
* use _deferred_list.
1668+
*/
1669+
if (nr_pages > 2 &&
1670+
!list_empty(&folio->_deferred_list)) {
1671+
if (try_split_folio(folio, split_folios) == 0) {
1672+
stats->nr_thp_split += is_thp;
1673+
stats->nr_split++;
1674+
continue;
1675+
}
1676+
}
1677+
16551678
/*
16561679
* Large folio migration might be unsupported or
16571680
* the allocation might be failed so we should retry

0 commit comments

Comments
 (0)