folio_migrate_copy() will call cond_resched(), even if it only needs to be copied once, restore the previous implementation before there is a better solution: use copy_highpage() when copy once. Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:105 ___might_sleep.cold+0x1f3/0x239 kernel/sched/core.c:9182 folio_copy+0x10c/0x1a0 mm/util.c:761 folio_migrate_copy+0x19/0x30 mm/migrate.c:619 __buffer_migrate_page+0x820/0xa80 mm/migrate.c:757 move_to_new_page+0x339/0xf00 mm/migrate.c:904 __unmap_and_move mm/migrate.c:1069 [inline] unmap_and_move mm/migrate.c:1210 [inline] migrate_pages+0x2867/0x3890 mm/migrate.c:1487 compact_zone+0x1abb/0x3860 mm/compaction.c:2393 kcompactd_do_work+0x2c9/0x730 mm/compaction.c:2808 kcompactd+0x262/0xd10 mm/compaction.c:2903 kthread+0x3e5/0x4d0 kernel/kthread.c:319 Reported-by: syzbot+bb4c69145b4a52b40b27@xxxxxxxxxxxxxxxxxxxxxxxxx Signed-off-by: Wang Qing <wangqing@xxxxxxxx> --- mm/folio-compat.c | 6 ------ mm/migrate.c | 15 +++++++++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 5b6ae1d..13ec6aa --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -64,12 +64,6 @@ void migrate_page_states(struct page *newpage, struct page *page) folio_migrate_flags(page_folio(newpage), page_folio(page)); } EXPORT_SYMBOL(migrate_page_states); - -void migrate_page_copy(struct page *newpage, struct page *page) -{ - folio_migrate_copy(page_folio(newpage), page_folio(page)); -} -EXPORT_SYMBOL(migrate_page_copy); #endif bool set_page_writeback(struct page *page) diff --git a/mm/migrate.c b/mm/migrate.c index 7d06515..8fb796b --- a/mm/migrate.c +++ b/mm/migrate.c @@ -614,12 +614,19 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio) } EXPORT_SYMBOL(folio_migrate_flags); -void folio_migrate_copy(struct folio *newfolio, struct folio *folio) +void migrate_page_copy(struct page *newpage, struct page *page) { - folio_copy(newfolio, folio); + struct folio *newfolio = page_folio(newpage); + struct folio *folio = page_folio(page); + + if (PageHuge(page) || PageTransHuge(page)) + folio_copy(newfolio, folio); + else + copy_highpage(newpage, page); + folio_migrate_flags(newfolio, folio); } -EXPORT_SYMBOL(folio_migrate_copy); +EXPORT_SYMBOL(migrate_page_copy); /************************************************************ * Migration functions @@ -647,7 +654,7 @@ int migrate_page(struct address_space *mapping, return rc; if (mode != MIGRATE_SYNC_NO_COPY) - folio_migrate_copy(newfolio, folio); + migrate_page_copy(newpage, page); else folio_migrate_flags(newfolio, folio); return MIGRATEPAGE_SUCCESS; -- 2.7.4