diff mbox series

[v2,2/6] mm/migrate_device: further convert migrate_device_unmap() to folios

Message ID 20240216211320.222431-2-sidhartha.kumar@oracle.com (mailing list archive)
State New
Headers show
Series [v2,1/6] mm/migrate: introduce migrate_pfn_to_folio() | expand

Commit Message

Sidhartha Kumar Feb. 16, 2024, 9:13 p.m. UTC
migrate_device_unmap() already has a folio, we can use the folio
versions of is_zone_device_page() and putback_lru_page.

Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---

	v1 -> v2:
		use migrate_pfn_to_folio() to directly work with a folio
		per Alistair Popple.

 mm/migrate_device.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

Comments

Matthew Wilcox Feb. 16, 2024, 9:51 p.m. UTC | #1
On Fri, Feb 16, 2024 at 01:13:16PM -0800, Sidhartha Kumar wrote:
> migrate_device_unmap() already has a folio, we can use the folio
> versions of is_zone_device_page() and putback_lru_page.
> -		if (page_mapped(page) ||
> -		    !migrate_vma_check_page(page, fault_page)) {
> -			if (!is_zone_device_page(page)) {
> -				get_page(page);
> -				putback_lru_page(page);
> +		if (folio_mapped(folio) ||
> +		    !migrate_vma_check_page(&folio->page, fault_page)) {
> +			if (!folio_is_zone_device(folio)) {
> +				folio_get(folio);
> +				folio_putback_lru(folio);

page_mapped() is not the same thing as folio_mapped(page_folio(page)).
please include some argumentation about why this is a correct
transformation to make.
diff mbox series

Patch

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index b6c27c76e1a0b..3d3c2593b5b64 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -368,42 +368,40 @@  static unsigned long migrate_device_unmap(unsigned long *src_pfns,
 	lru_add_drain();
 
 	for (i = 0; i < npages; i++) {
-		struct page *page = migrate_pfn_to_page(src_pfns[i]);
-		struct folio *folio;
+		struct folio *folio = migrate_pfn_to_folio(src_pfns[i]);
 
-		if (!page) {
+		if (!folio) {
 			if (src_pfns[i] & MIGRATE_PFN_MIGRATE)
 				unmapped++;
 			continue;
 		}
 
 		/* ZONE_DEVICE pages are not on LRU */
-		if (!is_zone_device_page(page)) {
-			if (!PageLRU(page) && allow_drain) {
+		if (!folio_is_zone_device(folio)) {
+			if (!folio_test_lru(folio) && allow_drain) {
 				/* Drain CPU's lru cache */
 				lru_add_drain_all();
 				allow_drain = false;
 			}
 
-			if (!isolate_lru_page(page)) {
+			if (!folio_isolate_lru(folio)) {
 				src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
 				restore++;
 				continue;
 			}
 
 			/* Drop the reference we took in collect */
-			put_page(page);
+			folio_put(folio);
 		}
 
-		folio = page_folio(page);
 		if (folio_mapped(folio))
 			try_to_migrate(folio, 0);
 
-		if (page_mapped(page) ||
-		    !migrate_vma_check_page(page, fault_page)) {
-			if (!is_zone_device_page(page)) {
-				get_page(page);
-				putback_lru_page(page);
+		if (folio_mapped(folio) ||
+		    !migrate_vma_check_page(&folio->page, fault_page)) {
+			if (!folio_is_zone_device(folio)) {
+				folio_get(folio);
+				folio_putback_lru(folio);
 			}
 
 			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
@@ -415,13 +413,11 @@  static unsigned long migrate_device_unmap(unsigned long *src_pfns,
 	}
 
 	for (i = 0; i < npages && restore; i++) {
-		struct page *page = migrate_pfn_to_page(src_pfns[i]);
-		struct folio *folio;
+		struct folio *folio = migrate_pfn_to_folio(src_pfns[i]);
 
-		if (!page || (src_pfns[i] & MIGRATE_PFN_MIGRATE))
+		if (!folio || (src_pfns[i] & MIGRATE_PFN_MIGRATE))
 			continue;
 
-		folio = page_folio(page);
 		remove_migration_ptes(folio, folio, false);
 
 		src_pfns[i] = 0;