archive mirror
 help / color / mirror / Atom feed
From: Wang Qing <>
To: Andrew Morton <>,,
Cc: Wang Qing <>
Subject: [PATCH] mm: folio: use copy_highpage() instead of folio_migrate_copy() when copy once
Date: Tue, 27 Jul 2021 11:32:54 +0800	[thread overview]
Message-ID: <> (raw)

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
Signed-off-by: Wang Qing <>
 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));
-void migrate_page_copy(struct page *newpage, struct page *page)
-	folio_migrate_copy(page_folio(newpage), page_folio(page));
 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)
-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);
  *                    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);
 		folio_migrate_flags(newfolio, folio);

             reply	other threads:[~2021-07-27  3:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27  3:32 Wang Qing [this message]
2021-07-27 11:46 ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \
    --subject='Re: [PATCH] mm: folio: use copy_highpage() instead of folio_migrate_copy() when copy once' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).