[PATCH v2 1/2] mm: gup: clean up stale logic in migrate_longterm_unpinnable_folio()

Hyesoo Yu posted 2 patches 6 months, 2 weeks ago
[PATCH v2 1/2] mm: gup: clean up stale logic in migrate_longterm_unpinnable_folio()
Posted by Hyesoo Yu 6 months, 2 weeks ago
migrate_longterm_unpinnable_folio() always receives a non-empty
movable_folio_list. Thus, list_empty() check can be safely removed.

Also, pofs entries are fully unpinned before migration is attempted.
The err label contained unnecessary unpinning logic for pofs, which
is now removed.

No functional change intended.

Signed-off-by: Hyesoo Yu <hyesoo.yu@samsung.com>
---
 mm/gup.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index e065a49842a8..68d91b000199 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2353,7 +2353,12 @@ static int
 migrate_longterm_unpinnable_folios(struct list_head *movable_folio_list,
 				   struct pages_or_folios *pofs)
 {
-	int ret;
+	struct migration_target_control mtc = {
+		.gfp_mask = GFP_USER | __GFP_NOWARN,
+		.reason = MR_LONGTERM_PIN,
+		.nid = NUMA_NO_NODE,
+	};
+	int ret = -EAGAIN;
 	unsigned long i;
 
 	for (i = 0; i < pofs->nr_entries; i++) {
@@ -2370,6 +2375,7 @@ migrate_longterm_unpinnable_folios(struct list_head *movable_folio_list,
 			gup_put_folio(folio, 1, FOLL_PIN);
 
 			if (migrate_device_coherent_folio(folio)) {
+				pofs_unpin(pofs);
 				ret = -EBUSY;
 				goto err;
 			}
@@ -2388,27 +2394,11 @@ migrate_longterm_unpinnable_folios(struct list_head *movable_folio_list,
 		pofs_clear_entry(pofs, i);
 	}
 
-	if (!list_empty(movable_folio_list)) {
-		struct migration_target_control mtc = {
-			.nid = NUMA_NO_NODE,
-			.gfp_mask = GFP_USER | __GFP_NOWARN,
-			.reason = MR_LONGTERM_PIN,
-		};
-
-		if (migrate_pages(movable_folio_list, alloc_migration_target,
-				  NULL, (unsigned long)&mtc, MIGRATE_SYNC,
-				  MR_LONGTERM_PIN, NULL)) {
-			ret = -ENOMEM;
-			goto err;
-		}
-	}
-
-	putback_movable_pages(movable_folio_list);
-
-	return -EAGAIN;
+	if (migrate_pages(movable_folio_list, alloc_migration_target, NULL,
+			  (unsigned long)&mtc, MIGRATE_SYNC, MR_LONGTERM_PIN, NULL))
+		ret = -ENOMEM;
 
 err:
-	pofs_unpin(pofs);
 	putback_movable_pages(movable_folio_list);
 
 	return ret;
-- 
2.49.0