Linux-mm Archive on
 help / color / Atom feed
* [patch 134/158] mm/migrate.c: handle freed page at the first place
@ 2019-12-01  1:57 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2019-12-01  1:57 UTC (permalink / raw)
  To: akpm, linux-mm, mgorman, mhocko, mm-commits, torvalds, vbabka, yang.shi

From: Yang Shi <>
Subject: mm/migrate.c: handle freed page at the first place

When doing migration if the freed page is met, we just return without
migrating it since it is pointless to migrate a freed page.  But, the
current code allocates target page unconditionally before handling freed
page, if the page is freed, the newly allocated will be just freed.  It
doesn't make too much sense and is just a waste of time although migrating
freed page is rare.

So, handle freed page at the before that to avoid unnecessary page
allocation and free.

Signed-off-by: Yang Shi <>
Acked-by: Michal Hocko <>
Reviewed-by: Andrew Morton <>
Cc: Mel Gorman <>
Cc: Vlastimil Babka <>
Signed-off-by: Andrew Morton <>

 mm/migrate.c |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

--- a/mm/migrate.c~mm-migrate-handle-freed-page-at-the-first-place
+++ a/mm/migrate.c
@@ -1168,15 +1168,11 @@ static ICE_noinline int unmap_and_move(n
 				   enum migrate_reason reason)
-	struct page *newpage;
+	struct page *newpage = NULL;
 	if (!thp_migration_supported() && PageTransHuge(page))
 		return -ENOMEM;
-	newpage = get_new_page(page, private);
-	if (!newpage)
-		return -ENOMEM;
 	if (page_count(page) == 1) {
 		/* page was freed from under us. So we are done. */
@@ -1187,13 +1183,13 @@ static ICE_noinline int unmap_and_move(n
-		if (put_new_page)
-			put_new_page(newpage, private);
-		else
-			put_page(newpage);
 		goto out;
+	newpage = get_new_page(page, private);
+	if (!newpage)
+		return -ENOMEM;
 	rc = __unmap_and_move(page, newpage, force, mode);
 		set_page_owner_migrate_reason(newpage, reason);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-01  1:57 [patch 134/158] mm/migrate.c: handle freed page at the first place akpm

Linux-mm Archive on

Archives are clonable:
	git clone --mirror linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ \
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone