linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wang Qing <wangqing@vivo.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Wang Qing <wangqing@vivo.com>
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: <1627356775-28742-1-git-send-email-wangqing@vivo.com> (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
 
Reported-by: syzbot+bb4c69145b4a52b40b27@syzkaller.appspotmail.com
Signed-off-by: Wang Qing <wangqing@vivo.com>
---
 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



             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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=1627356775-28742-1-git-send-email-wangqing@vivo.com \
    --to=wangqing@vivo.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --subject='Re: [PATCH] mm: folio: use copy_highpage() instead of folio_migrate_copy() when copy once' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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).