BACKPORT: 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. Commit616b837153
("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/03CE3A00-917C-48CC-8E1C-6A98713C817C@nvidia.com/ [zi.yan@sent.com: fix an error in migrate_misplaced_folio()] Link: https://lkml.kernel.org/r/20240326150031.569387-1-zi.yan@sent.com Link: https://lkml.kernel.org/r/20240322193304.522496-1-zi.yan@sent.com Fixes:616b837153
("mm: thp: enable thp migration in generic path") Change-Id: I6fc2244e92914289fd67c893fbf7a3e7c7c00109 Signed-off-by: Zi Yan <ziy@nvidia.com> Tested-by: Baolin Wang <baolin.wang@linux.alibaba.com> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Huang, Ying <ying.huang@intel.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: SeongJae Park <sj@kernel.org> Cc: Yang Shi <shy828301@gmail.com> Cc: Yin Fengwei <fengwei.yin@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 7262f208ca681385d133844be8a58d9b4ca185f7) [ Remove increment to stats->nr_split which doesn't exist in 6.6. Pass the required reason parameter to try_split_folio() - Kalesh ] Bug: 419599659 Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
22
mm/migrate.c
22
mm/migrate.c
@@ -1756,6 +1756,28 @@ static int migrate_pages_batch(struct list_head *from,
|
|||||||
|
|
||||||
cond_resched();
|
cond_resched();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The rare folio on the deferred split list should
|
||||||
|
* be split now. It should not count as a failure.
|
||||||
|
* Only check it without removing it from the list.
|
||||||
|
* Since the folio can be on deferred_split_scan()
|
||||||
|
* local list and removing it can cause the local list
|
||||||
|
* corruption. Folio split process below can handle it
|
||||||
|
* with the help of folio_ref_freeze().
|
||||||
|
*
|
||||||
|
* nr_pages > 2 is needed to avoid checking order-1
|
||||||
|
* page cache folios. They exist, in contrast to
|
||||||
|
* non-existent order-1 anonymous folios, and do not
|
||||||
|
* use _deferred_list.
|
||||||
|
*/
|
||||||
|
if (nr_pages > 2 &&
|
||||||
|
!list_empty(&folio->_deferred_list)) {
|
||||||
|
if (try_split_folio(folio, split_folios, reason) == 0) {
|
||||||
|
stats->nr_thp_split += is_thp;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Large folio migration might be unsupported or
|
* Large folio migration might be unsupported or
|
||||||
* the allocation might be failed so we should retry
|
* the allocation might be failed so we should retry
|
||||||
|
Reference in New Issue
Block a user