linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] mm: finish isolate/putback_lru_page()
@ 2024-08-26  6:58 Kefeng Wang
  2024-08-26  6:58 ` [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Kefeng Wang
                   ` (5 more replies)
  0 siblings, 6 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26  6:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

Convert to use more folios in migrate_device.c, then we could
remove isolate_lru_page() and putback_lru_page().  

Based on next-20240823.

Kefeng Wang (6):
  mm: migrate_device: convert to migrate_device_coherent_folio()
  mm: migrate_device: use a folio in migrate_device_range()
  mm: migrate_device: use more folio in migrate_device_unmap()
  mm: migrate_device: use more folio in migrate_device_finalize()
  mm: remove isolate_lru_page()
  mm: remove putback_lru_page()

 Documentation/mm/page_migration.rst           |   6 +-
 Documentation/mm/unevictable-lru.rst          |   2 +-
 .../translations/zh_CN/mm/page_migration.rst  |   6 +-
 mm/filemap.c                                  |   2 +-
 mm/folio-compat.c                             |  12 ---
 mm/gup.c                                      |   2 +-
 mm/internal.h                                 |   4 +-
 mm/khugepaged.c                               |   6 +-
 mm/migrate_device.c                           | 102 +++++++++---------
 mm/swap.c                                     |   2 +-
 10 files changed, 67 insertions(+), 77 deletions(-)

-- 
2.27.0



^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio()
  2024-08-26  6:58 [PATCH 0/6] mm: finish isolate/putback_lru_page() Kefeng Wang
@ 2024-08-26  6:58 ` Kefeng Wang
  2024-08-26 15:04   ` David Hildenbrand
                     ` (2 more replies)
  2024-08-26  6:58 ` [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range() Kefeng Wang
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26  6:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

Save few calls to compound_head() and use folio throughout.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/gup.c            |  2 +-
 mm/internal.h       |  2 +-
 mm/migrate_device.c | 30 +++++++++++++++---------------
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index d19884e097fd..5defd5e6d8f8 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2335,7 +2335,7 @@ static int migrate_longterm_unpinnable_folios(
 			folio_get(folio);
 			gup_put_folio(folio, 1, FOLL_PIN);
 
-			if (migrate_device_coherent_page(&folio->page)) {
+			if (migrate_device_coherent_folio(folio)) {
 				ret = -EBUSY;
 				goto err;
 			}
diff --git a/mm/internal.h b/mm/internal.h
index e1e139e412d1..0f4750f77f59 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1209,7 +1209,7 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf,
 		      int *last_cpupid);
 
 void free_zone_device_folio(struct folio *folio);
-int migrate_device_coherent_page(struct page *page);
+int migrate_device_coherent_folio(struct folio *folio);
 
 /*
  * mm/gup.c
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 6d66dc1c6ffa..82d75205dda8 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -708,7 +708,7 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 
 			/*
 			 * The only time there is no vma is when called from
-			 * migrate_device_coherent_page(). However this isn't
+			 * migrate_device_coherent_folio(). However this isn't
 			 * called if the page could not be unmapped.
 			 */
 			VM_BUG_ON(!migrate);
@@ -921,38 +921,38 @@ int migrate_device_range(unsigned long *src_pfns, unsigned long start,
 EXPORT_SYMBOL(migrate_device_range);
 
 /*
- * Migrate a device coherent page back to normal memory. The caller should have
- * a reference on page which will be copied to the new page if migration is
+ * Migrate a device coherent folio back to normal memory. The caller should have
+ * a reference on folio which will be copied to the new folio if migration is
  * successful or dropped on failure.
  */
-int migrate_device_coherent_page(struct page *page)
+int migrate_device_coherent_folio(struct folio *folio)
 {
 	unsigned long src_pfn, dst_pfn = 0;
-	struct page *dpage;
+	struct folio *dfolio;
 
-	WARN_ON_ONCE(PageCompound(page));
+	WARN_ON_ONCE(folio_test_large(folio));
 
-	lock_page(page);
-	src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE;
+	folio_lock(folio);
+	src_pfn = migrate_pfn(folio_pfn(folio)) | MIGRATE_PFN_MIGRATE;
 
 	/*
 	 * We don't have a VMA and don't need to walk the page tables to find
-	 * the source page. So call migrate_vma_unmap() directly to unmap the
-	 * page as migrate_vma_setup() will fail if args.vma == NULL.
+	 * the source folio. So call migrate_vma_unmap() directly to unmap the
+	 * folio as migrate_vma_setup() will fail if args.vma == NULL.
 	 */
 	migrate_device_unmap(&src_pfn, 1, NULL);
 	if (!(src_pfn & MIGRATE_PFN_MIGRATE))
 		return -EBUSY;
 
-	dpage = alloc_page(GFP_USER | __GFP_NOWARN);
-	if (dpage) {
-		lock_page(dpage);
-		dst_pfn = migrate_pfn(page_to_pfn(dpage));
+	dfolio = folio_alloc(GFP_USER | __GFP_NOWARN, 0);
+	if (dfolio) {
+		folio_lock(dfolio);
+		dst_pfn = migrate_pfn(folio_pfn(dfolio));
 	}
 
 	migrate_device_pages(&src_pfn, &dst_pfn, 1);
 	if (src_pfn & MIGRATE_PFN_MIGRATE)
-		copy_highpage(dpage, page);
+		folio_copy(dfolio, folio);
 	migrate_device_finalize(&src_pfn, &dst_pfn, 1);
 
 	if (src_pfn & MIGRATE_PFN_MIGRATE)
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range()
  2024-08-26  6:58 [PATCH 0/6] mm: finish isolate/putback_lru_page() Kefeng Wang
  2024-08-26  6:58 ` [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Kefeng Wang
@ 2024-08-26  6:58 ` Kefeng Wang
  2024-08-26 15:05   ` David Hildenbrand
                     ` (2 more replies)
  2024-08-26  6:58 ` [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap() Kefeng Wang
                   ` (3 subsequent siblings)
  5 siblings, 3 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26  6:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

Save two calls to compound_head() and use folio throughout.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/migrate_device.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 82d75205dda8..66db28b89f9b 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -898,16 +898,17 @@ int migrate_device_range(unsigned long *src_pfns, unsigned long start,
 	unsigned long i, pfn;
 
 	for (pfn = start, i = 0; i < npages; pfn++, i++) {
-		struct page *page = pfn_to_page(pfn);
+		struct folio *folio;
 
-		if (!get_page_unless_zero(page)) {
+		folio = folio_get_nontail_page(pfn_to_page(pfn));
+		if (!folio) {
 			src_pfns[i] = 0;
 			continue;
 		}
 
-		if (!trylock_page(page)) {
+		if (!folio_trylock(folio)) {
 			src_pfns[i] = 0;
-			put_page(page);
+			folio_put(folio);
 			continue;
 		}
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap()
  2024-08-26  6:58 [PATCH 0/6] mm: finish isolate/putback_lru_page() Kefeng Wang
  2024-08-26  6:58 ` [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Kefeng Wang
  2024-08-26  6:58 ` [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range() Kefeng Wang
@ 2024-08-26  6:58 ` Kefeng Wang
  2024-08-26 15:06   ` David Hildenbrand
                     ` (2 more replies)
  2024-08-26  6:58 ` [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize() Kefeng Wang
                   ` (2 subsequent siblings)
  5 siblings, 3 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26  6:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

The page for migrate_device_unmap() already has a reference, so it is
safe to convert the page to folio to save a few calls to compound_head(),
which removes the last isolate_lru_page() call.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/migrate_device.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 66db28b89f9b..b49f4956617a 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -379,33 +379,33 @@ static unsigned long migrate_device_unmap(unsigned long *src_pfns,
 			continue;
 		}
 
-		/* ZONE_DEVICE pages are not on LRU */
-		if (!is_zone_device_page(page)) {
-			if (!PageLRU(page) && allow_drain) {
+		folio =	page_folio(page);
+		/* ZONE_DEVICE folios are not on LRU */
+		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) ||
+		if (folio_mapped(folio) ||
 		    !migrate_vma_check_page(page, fault_page)) {
-			if (!is_zone_device_page(page)) {
-				get_page(page);
-				putback_lru_page(page);
+			if (!folio_is_zone_device(folio)) {
+				folio_get(folio);
+				folio_putback_lru(folio);
 			}
 
 			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize()
  2024-08-26  6:58 [PATCH 0/6] mm: finish isolate/putback_lru_page() Kefeng Wang
                   ` (2 preceding siblings ...)
  2024-08-26  6:58 ` [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap() Kefeng Wang
@ 2024-08-26  6:58 ` Kefeng Wang
  2024-08-26 17:53   ` Vishal Moola
  2024-08-27  5:48   ` Alistair Popple
  2024-08-26  6:58 ` [PATCH 5/6] mm: remove isolate_lru_page() Kefeng Wang
  2024-08-26  6:58 ` [PATCH 6/6] mm: remove putback_lru_page() Kefeng Wang
  5 siblings, 2 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26  6:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

Saves a couple of calls to compound_head() and remove last two callers
of putback_lru_page().

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/migrate_device.c | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index b49f4956617a..6ea3d055f520 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -815,42 +815,45 @@ void migrate_device_finalize(unsigned long *src_pfns,
 	unsigned long i;
 
 	for (i = 0; i < npages; i++) {
-		struct folio *dst, *src;
+		struct folio *dst = NULL, *src = NULL;
 		struct page *newpage = migrate_pfn_to_page(dst_pfns[i]);
 		struct page *page = migrate_pfn_to_page(src_pfns[i]);
 
+		if (newpage)
+			dst = page_folio(newpage);
+
 		if (!page) {
-			if (newpage) {
-				unlock_page(newpage);
-				put_page(newpage);
+			if (dst) {
+				folio_unlock(dst);
+				folio_put(dst);
 			}
 			continue;
 		}
 
-		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !newpage) {
-			if (newpage) {
-				unlock_page(newpage);
-				put_page(newpage);
+		src = page_folio(page);
+
+		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !dst) {
+			if (dst) {
+				folio_unlock(dst);
+				folio_put(dst);
 			}
-			newpage = page;
+			dst = src;
 		}
 
-		src = page_folio(page);
-		dst = page_folio(newpage);
 		remove_migration_ptes(src, dst, false);
 		folio_unlock(src);
 
-		if (is_zone_device_page(page))
-			put_page(page);
+		if (folio_is_zone_device(src))
+			folio_put(src);
 		else
-			putback_lru_page(page);
+			folio_putback_lru(src);
 
-		if (newpage != page) {
-			unlock_page(newpage);
-			if (is_zone_device_page(newpage))
-				put_page(newpage);
+		if (dst != src) {
+			folio_unlock(dst);
+			if (folio_is_zone_device(dst))
+				folio_put(dst);
 			else
-				putback_lru_page(newpage);
+				folio_putback_lru(dst);
 		}
 	}
 }
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 5/6] mm: remove isolate_lru_page()
  2024-08-26  6:58 [PATCH 0/6] mm: finish isolate/putback_lru_page() Kefeng Wang
                   ` (3 preceding siblings ...)
  2024-08-26  6:58 ` [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize() Kefeng Wang
@ 2024-08-26  6:58 ` Kefeng Wang
  2024-08-26 13:05   ` Matthew Wilcox
  2024-08-26 14:41   ` [PATCH 5-fix/6] mm: remove isolate_lru_page() fix Kefeng Wang
  2024-08-26  6:58 ` [PATCH 6/6] mm: remove putback_lru_page() Kefeng Wang
  5 siblings, 2 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26  6:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

There are no more callers of isolate_lru_page(), remove it.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 Documentation/mm/page_migration.rst                    | 6 +++---
 Documentation/mm/unevictable-lru.rst                   | 2 +-
 Documentation/translations/zh_CN/mm/page_migration.rst | 6 +++---
 mm/filemap.c                                           | 2 +-
 mm/folio-compat.c                                      | 7 -------
 mm/internal.h                                          | 1 -
 mm/khugepaged.c                                        | 6 +++---
 mm/migrate_device.c                                    | 2 +-
 mm/swap.c                                              | 2 +-
 9 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/Documentation/mm/page_migration.rst b/Documentation/mm/page_migration.rst
index f1ce67a26615..0046bbbdc65d 100644
--- a/Documentation/mm/page_migration.rst
+++ b/Documentation/mm/page_migration.rst
@@ -67,8 +67,8 @@ In kernel use of migrate_pages()
 
    Lists of pages to be migrated are generated by scanning over
    pages and moving them into lists. This is done by
-   calling isolate_lru_page().
-   Calling isolate_lru_page() increases the references to the page
+   calling folio_isolate_lru().
+   Calling folio_isolate_lru() increases the references to the page
    so that it cannot vanish while the page migration occurs.
    It also prevents the swapper or other scans from encountering
    the page.
@@ -86,7 +86,7 @@ How migrate_pages() works
 
 migrate_pages() does several passes over its list of pages. A page is moved
 if all references to a page are removable at the time. The page has
-already been removed from the LRU via isolate_lru_page() and the refcount
+already been removed from the LRU via folio_isolate_lru() and the refcount
 is increased so that the page cannot be freed while page migration occurs.
 
 Steps:
diff --git a/Documentation/mm/unevictable-lru.rst b/Documentation/mm/unevictable-lru.rst
index 255ef12a432b..04113c2a2f9e 100644
--- a/Documentation/mm/unevictable-lru.rst
+++ b/Documentation/mm/unevictable-lru.rst
@@ -230,7 +230,7 @@ In Nick's patch, he used one of the struct page LRU list link fields as a count
 of VM_LOCKED VMAs that map the page (Rik van Riel had the same idea three years
 earlier).  But this use of the link field for a count prevented the management
 of the pages on an LRU list, and thus mlocked pages were not migratable as
-isolate_lru_page() could not detect them, and the LRU list link field was not
+folio_isolate_lru() could not detect them, and the LRU list link field was not
 available to the migration subsystem.
 
 Nick resolved this by putting mlocked pages back on the LRU list before
diff --git a/Documentation/translations/zh_CN/mm/page_migration.rst b/Documentation/translations/zh_CN/mm/page_migration.rst
index f95063826a15..8c8461c6cb9f 100644
--- a/Documentation/translations/zh_CN/mm/page_migration.rst
+++ b/Documentation/translations/zh_CN/mm/page_migration.rst
@@ -50,8 +50,8 @@ mbind()设置一个新的内存策略。一个进程的页面也可以通过sys_
 
 1. 从LRU中移除页面。
 
-   要迁移的页面列表是通过扫描页面并把它们移到列表中来生成的。这是通过调用 isolate_lru_page()
-   来完成的。调用isolate_lru_page()增加了对该页的引用,这样在页面迁移发生时它就不会
+   要迁移的页面列表是通过扫描页面并把它们移到列表中来生成的。这是通过调用 folio_isolate_lru()
+   来完成的。调用folio_isolate_lru()增加了对该页的引用,这样在页面迁移发生时它就不会
    消失。它还可以防止交换器或其他扫描器遇到该页。
 
 
@@ -65,7 +65,7 @@ migrate_pages()如何工作
 =======================
 
 migrate_pages()对它的页面列表进行了多次处理。如果当时对一个页面的所有引用都可以被移除,
-那么这个页面就会被移动。该页已经通过isolate_lru_page()从LRU中移除,并且refcount被
+那么这个页面就会被移动。该页已经通过folio_isolate_lru()从LRU中移除,并且refcount被
 增加,以便在页面迁移发生时不释放该页。
 
 步骤:
diff --git a/mm/filemap.c b/mm/filemap.c
index 0f13126b43b0..0a5a04ad6c21 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -114,7 +114,7 @@
  *    ->private_lock		(try_to_unmap_one)
  *    ->i_pages lock		(try_to_unmap_one)
  *    ->lruvec->lru_lock	(follow_page_mask->mark_page_accessed)
- *    ->lruvec->lru_lock	(check_pte_range->isolate_lru_page)
+ *    ->lruvec->lru_lock	(check_pte_range->folio_isolate_lru)
  *    ->private_lock		(folio_remove_rmap_pte->set_page_dirty)
  *    ->i_pages lock		(folio_remove_rmap_pte->set_page_dirty)
  *    bdi.wb->list_lock		(folio_remove_rmap_pte->set_page_dirty)
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index f05906006b3c..47b8cc245aa4 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -93,13 +93,6 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping,
 }
 EXPORT_SYMBOL(grab_cache_page_write_begin);
 
-bool isolate_lru_page(struct page *page)
-{
-	if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page"))
-		return false;
-	return folio_isolate_lru((struct folio *)page);
-}
-
 void putback_lru_page(struct page *page)
 {
 	folio_putback_lru(page_folio(page));
diff --git a/mm/internal.h b/mm/internal.h
index 0f4750f77f59..3ee5810f5231 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -416,7 +416,6 @@ extern unsigned long highest_memmap_pfn;
 /*
  * in mm/vmscan.c:
  */
-bool isolate_lru_page(struct page *page);
 bool folio_isolate_lru(struct folio *folio);
 void putback_lru_page(struct page *page);
 void folio_putback_lru(struct folio *folio);
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 4a83c40d9053..b87eacfac5a7 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -627,7 +627,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
 		}
 
 		/*
-		 * We can do it before isolate_lru_page because the
+		 * We can do it before folio_isolate_lru because the
 		 * page can't be freed from under us. NOTE: PG_lock
 		 * is needed to serialize against split_huge_page
 		 * when invoked from the VM.
@@ -1874,7 +1874,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 					result = SCAN_FAIL;
 					goto xa_unlocked;
 				}
-				/* drain lru cache to help isolate_lru_page() */
+				/* drain lru cache to help folio_isolate_lru() */
 				lru_add_drain();
 			} else if (folio_trylock(folio)) {
 				folio_get(folio);
@@ -1889,7 +1889,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 				page_cache_sync_readahead(mapping, &file->f_ra,
 							  file, index,
 							  end - index);
-				/* drain lru cache to help isolate_lru_page() */
+				/* drain lru cache to help folio_isolate_lru() */
 				lru_add_drain();
 				folio = filemap_lock_folio(mapping, index);
 				if (IS_ERR(folio)) {
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 6ea3d055f520..f1faff058491 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -328,7 +328,7 @@ static bool migrate_vma_check_page(struct page *page, struct page *fault_page)
 
 	/*
 	 * One extra ref because caller holds an extra reference, either from
-	 * isolate_lru_page() for a regular page, or migrate_vma_collect() for
+	 * folio_isolate_lru() for a regular page, or migrate_vma_collect() for
 	 * a device page.
 	 */
 	int extra = 1 + (page == fault_page);
diff --git a/mm/swap.c b/mm/swap.c
index e0dbfc98318e..634fde80cd44 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -906,7 +906,7 @@ atomic_t lru_disable_count = ATOMIC_INIT(0);
 
 /*
  * lru_cache_disable() needs to be called before we start compiling
- * a list of pages to be migrated using isolate_lru_page().
+ * a list of pages to be migrated using folio_isolate_lru().
  * It drains pages on LRU cache and then disable on all cpus until
  * lru_cache_enable is called.
  *
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 6/6] mm: remove putback_lru_page()
  2024-08-26  6:58 [PATCH 0/6] mm: finish isolate/putback_lru_page() Kefeng Wang
                   ` (4 preceding siblings ...)
  2024-08-26  6:58 ` [PATCH 5/6] mm: remove isolate_lru_page() Kefeng Wang
@ 2024-08-26  6:58 ` Kefeng Wang
  2024-08-26 15:08   ` David Hildenbrand
  2024-08-26 17:54   ` Vishal Moola
  5 siblings, 2 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26  6:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

There are no more callers of isolate_lru_page(), remove it.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/folio-compat.c | 5 -----
 mm/internal.h     | 1 -
 2 files changed, 6 deletions(-)

diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index 47b8cc245aa4..80746182e9e8 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -92,8 +92,3 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping,
 			mapping_gfp_mask(mapping));
 }
 EXPORT_SYMBOL(grab_cache_page_write_begin);
-
-void putback_lru_page(struct page *page)
-{
-	folio_putback_lru(page_folio(page));
-}
diff --git a/mm/internal.h b/mm/internal.h
index 3ee5810f5231..f1fee5f235c5 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -417,7 +417,6 @@ extern unsigned long highest_memmap_pfn;
  * in mm/vmscan.c:
  */
 bool folio_isolate_lru(struct folio *folio);
-void putback_lru_page(struct page *page);
 void folio_putback_lru(struct folio *folio);
 extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason);
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/6] mm: remove isolate_lru_page()
  2024-08-26  6:58 ` [PATCH 5/6] mm: remove isolate_lru_page() Kefeng Wang
@ 2024-08-26 13:05   ` Matthew Wilcox
  2024-08-26 13:52     ` Kefeng Wang
  2024-08-26 14:41   ` [PATCH 5-fix/6] mm: remove isolate_lru_page() fix Kefeng Wang
  1 sibling, 1 reply; 24+ messages in thread
From: Matthew Wilcox @ 2024-08-26 13:05 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm

On Mon, Aug 26, 2024 at 02:58:13PM +0800, Kefeng Wang wrote:
> +++ b/Documentation/mm/page_migration.rst
> @@ -67,8 +67,8 @@ In kernel use of migrate_pages()
>  
>     Lists of pages to be migrated are generated by scanning over
>     pages and moving them into lists. This is done by
> -   calling isolate_lru_page().
> -   Calling isolate_lru_page() increases the references to the page
> +   calling folio_isolate_lru().
> +   Calling folio_isolate_lru() increases the references to the page

s/page/folio/

> @@ -86,7 +86,7 @@ How migrate_pages() works
>  
>  migrate_pages() does several passes over its list of pages. A page is moved

list of folios.  A folio is moved ...

(etc)

> +++ b/mm/swap.c
> @@ -906,7 +906,7 @@ atomic_t lru_disable_count = ATOMIC_INIT(0);
>  
>  /*
>   * lru_cache_disable() needs to be called before we start compiling
> - * a list of pages to be migrated using isolate_lru_page().
> + * a list of pages to be migrated using folio_isolate_lru().

a list of folios

>   * It drains pages on LRU cache and then disable on all cpus until

drains folios

>   * lru_cache_enable is called.
>   *
> -- 
> 2.27.0
> 


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/6] mm: remove isolate_lru_page()
  2024-08-26 13:05   ` Matthew Wilcox
@ 2024-08-26 13:52     ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26 13:52 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Andrew Morton, David Hildenbrand, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm



On 2024/8/26 21:05, Matthew Wilcox wrote:
> On Mon, Aug 26, 2024 at 02:58:13PM +0800, Kefeng Wang wrote:
>> +++ b/Documentation/mm/page_migration.rst
>> @@ -67,8 +67,8 @@ In kernel use of migrate_pages()
>>   
>>      Lists of pages to be migrated are generated by scanning over
>>      pages and moving them into lists. This is done by
>> -   calling isolate_lru_page().
>> -   Calling isolate_lru_page() increases the references to the page
>> +   calling folio_isolate_lru().
>> +   Calling folio_isolate_lru() increases the references to the page
> 
> s/page/folio/
> 
>> @@ -86,7 +86,7 @@ How migrate_pages() works
>>   
>>   migrate_pages() does several passes over its list of pages. A page is moved
> 
> list of folios.  A folio is moved ...
> 
> (etc)
> 
>> +++ b/mm/swap.c
>> @@ -906,7 +906,7 @@ atomic_t lru_disable_count = ATOMIC_INIT(0);
>>   
>>   /*
>>    * lru_cache_disable() needs to be called before we start compiling
>> - * a list of pages to be migrated using isolate_lru_page().
>> + * a list of pages to be migrated using folio_isolate_lru().
> 
> a list of folios
> 
>>    * It drains pages on LRU cache and then disable on all cpus until
> 
> drains folios


OK, just use sed to replace then isolate_lru_page(), will re-check the
changes and update other page to folio, thanks.

> 
>>    * lru_cache_enable is called.
>>    *
>> -- 
>> 2.27.0
>>
> 


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 5-fix/6] mm: remove isolate_lru_page() fix
  2024-08-26  6:58 ` [PATCH 5/6] mm: remove isolate_lru_page() Kefeng Wang
  2024-08-26 13:05   ` Matthew Wilcox
@ 2024-08-26 14:41   ` Kefeng Wang
  2024-08-26 17:54     ` Vishal Moola
  1 sibling, 1 reply; 24+ messages in thread
From: Kefeng Wang @ 2024-08-26 14:41 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Matthew Wilcox, Baolin Wang, Zi Yan,
	Alistair Popple, Jonathan Corbet, linux-mm, Kefeng Wang

Convert page to folio in comment and document, per Matthew.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---

Andrew,
Please help to squash this fix into [PATCH 5/6] mm: remove isolate_lru_page().

 Documentation/mm/page_migration.rst  | 18 +++++++++---------
 Documentation/mm/unevictable-lru.rst |  2 +-
 mm/khugepaged.c                      |  2 +-
 mm/migrate_device.c                  |  4 ++--
 mm/swap.c                            |  4 ++--
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/Documentation/mm/page_migration.rst b/Documentation/mm/page_migration.rst
index 0046bbbdc65d..519b35a4caf5 100644
--- a/Documentation/mm/page_migration.rst
+++ b/Documentation/mm/page_migration.rst
@@ -63,15 +63,15 @@ and then a low level description of how the low level details work.
 In kernel use of migrate_pages()
 ================================
 
-1. Remove pages from the LRU.
+1. Remove folios from the LRU.
 
-   Lists of pages to be migrated are generated by scanning over
-   pages and moving them into lists. This is done by
+   Lists of folios to be migrated are generated by scanning over
+   folios and moving them into lists. This is done by
    calling folio_isolate_lru().
-   Calling folio_isolate_lru() increases the references to the page
-   so that it cannot vanish while the page migration occurs.
+   Calling folio_isolate_lru() increases the references to the folio
+   so that it cannot vanish while the folio migration occurs.
    It also prevents the swapper or other scans from encountering
-   the page.
+   the folio.
 
 2. We need to have a function of type new_folio_t that can be
    passed to migrate_pages(). This function should figure out
@@ -84,10 +84,10 @@ In kernel use of migrate_pages()
 How migrate_pages() works
 =========================
 
-migrate_pages() does several passes over its list of pages. A page is moved
-if all references to a page are removable at the time. The page has
+migrate_pages() does several passes over its list of folios. A folio is moved
+if all references to a folio are removable at the time. The folio has
 already been removed from the LRU via folio_isolate_lru() and the refcount
-is increased so that the page cannot be freed while page migration occurs.
+is increased so that the folio cannot be freed while folio migration occurs.
 
 Steps:
 
diff --git a/Documentation/mm/unevictable-lru.rst b/Documentation/mm/unevictable-lru.rst
index 04113c2a2f9e..8d11fe6a0854 100644
--- a/Documentation/mm/unevictable-lru.rst
+++ b/Documentation/mm/unevictable-lru.rst
@@ -80,7 +80,7 @@ on an additional LRU list for a few reasons:
  (2) We want to be able to migrate unevictable folios between nodes for memory
      defragmentation, workload management and memory hotplug.  The Linux kernel
      can only migrate folios that it can successfully isolate from the LRU
-     lists (or "Movable" pages: outside of consideration here).  If we were to
+     lists (or "Movable" folios: outside of consideration here).  If we were to
      maintain folios elsewhere than on an LRU-like list, where they can be
      detected by folio_isolate_lru(), we would prevent their migration.
 
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b87eacfac5a7..ab646018ce25 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -628,7 +628,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
 
 		/*
 		 * We can do it before folio_isolate_lru because the
-		 * page can't be freed from under us. NOTE: PG_lock
+		 * folio can't be freed from under us. NOTE: PG_lock
 		 * is needed to serialize against split_huge_page
 		 * when invoked from the VM.
 		 */
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index f1faff058491..8d687de88a03 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -328,8 +328,8 @@ static bool migrate_vma_check_page(struct page *page, struct page *fault_page)
 
 	/*
 	 * One extra ref because caller holds an extra reference, either from
-	 * folio_isolate_lru() for a regular page, or migrate_vma_collect() for
-	 * a device page.
+	 * folio_isolate_lru() for a regular folio, or migrate_vma_collect() for
+	 * a device folio.
 	 */
 	int extra = 1 + (page == fault_page);
 
diff --git a/mm/swap.c b/mm/swap.c
index 634fde80cd44..510573d7e82e 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -906,8 +906,8 @@ atomic_t lru_disable_count = ATOMIC_INIT(0);
 
 /*
  * lru_cache_disable() needs to be called before we start compiling
- * a list of pages to be migrated using folio_isolate_lru().
- * It drains pages on LRU cache and then disable on all cpus until
+ * a list of folios to be migrated using folio_isolate_lru().
+ * It drains folios on LRU cache and then disable on all cpus until
  * lru_cache_enable is called.
  *
  * Must be paired with a call to lru_cache_enable().
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio()
  2024-08-26  6:58 ` [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Kefeng Wang
@ 2024-08-26 15:04   ` David Hildenbrand
  2024-08-26 17:52   ` Vishal Moola
  2024-08-27  5:42   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: David Hildenbrand @ 2024-08-26 15:04 UTC (permalink / raw)
  To: Kefeng Wang, Andrew Morton
  Cc: Matthew Wilcox, Baolin Wang, Zi Yan, Alistair Popple,
	Jonathan Corbet, linux-mm

On 26.08.24 08:58, Kefeng Wang wrote:
> Save few calls to compound_head() and use folio throughout.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range()
  2024-08-26  6:58 ` [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range() Kefeng Wang
@ 2024-08-26 15:05   ` David Hildenbrand
  2024-08-26 17:53   ` Vishal Moola
  2024-08-27  5:46   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: David Hildenbrand @ 2024-08-26 15:05 UTC (permalink / raw)
  To: Kefeng Wang, Andrew Morton
  Cc: Matthew Wilcox, Baolin Wang, Zi Yan, Alistair Popple,
	Jonathan Corbet, linux-mm

On 26.08.24 08:58, Kefeng Wang wrote:
> Save two calls to compound_head() and use folio throughout.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap()
  2024-08-26  6:58 ` [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap() Kefeng Wang
@ 2024-08-26 15:06   ` David Hildenbrand
  2024-08-26 17:53   ` Vishal Moola
  2024-08-27  5:47   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: David Hildenbrand @ 2024-08-26 15:06 UTC (permalink / raw)
  To: Kefeng Wang, Andrew Morton
  Cc: Matthew Wilcox, Baolin Wang, Zi Yan, Alistair Popple,
	Jonathan Corbet, linux-mm

On 26.08.24 08:58, Kefeng Wang wrote:
> The page for migrate_device_unmap() already has a reference, so it is
> safe to convert the page to folio to save a few calls to compound_head(),
> which removes the last isolate_lru_page() call.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 6/6] mm: remove putback_lru_page()
  2024-08-26  6:58 ` [PATCH 6/6] mm: remove putback_lru_page() Kefeng Wang
@ 2024-08-26 15:08   ` David Hildenbrand
  2024-08-26 17:54   ` Vishal Moola
  1 sibling, 0 replies; 24+ messages in thread
From: David Hildenbrand @ 2024-08-26 15:08 UTC (permalink / raw)
  To: Kefeng Wang, Andrew Morton
  Cc: Matthew Wilcox, Baolin Wang, Zi Yan, Alistair Popple,
	Jonathan Corbet, linux-mm

On 26.08.24 08:58, Kefeng Wang wrote:
> There are no more callers of isolate_lru_page(), remove it.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio()
  2024-08-26  6:58 ` [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Kefeng Wang
  2024-08-26 15:04   ` David Hildenbrand
@ 2024-08-26 17:52   ` Vishal Moola
  2024-08-27  5:42   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: Vishal Moola @ 2024-08-26 17:52 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Alistair Popple, Jonathan Corbet, linux-mm

On Mon, Aug 26, 2024 at 02:58:09PM +0800, Kefeng Wang wrote:
> Save few calls to compound_head() and use folio throughout.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range()
  2024-08-26  6:58 ` [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range() Kefeng Wang
  2024-08-26 15:05   ` David Hildenbrand
@ 2024-08-26 17:53   ` Vishal Moola
  2024-08-27  5:46   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: Vishal Moola @ 2024-08-26 17:53 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Alistair Popple, Jonathan Corbet, linux-mm

On Mon, Aug 26, 2024 at 02:58:10PM +0800, Kefeng Wang wrote:
> Save two calls to compound_head() and use folio throughout.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap()
  2024-08-26  6:58 ` [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap() Kefeng Wang
  2024-08-26 15:06   ` David Hildenbrand
@ 2024-08-26 17:53   ` Vishal Moola
  2024-08-27  5:47   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: Vishal Moola @ 2024-08-26 17:53 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Alistair Popple, Jonathan Corbet, linux-mm

On Mon, Aug 26, 2024 at 02:58:11PM +0800, Kefeng Wang wrote:
> The page for migrate_device_unmap() already has a reference, so it is
> safe to convert the page to folio to save a few calls to compound_head(),
> which removes the last isolate_lru_page() call.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize()
  2024-08-26  6:58 ` [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize() Kefeng Wang
@ 2024-08-26 17:53   ` Vishal Moola
  2024-08-27  5:48   ` Alistair Popple
  1 sibling, 0 replies; 24+ messages in thread
From: Vishal Moola @ 2024-08-26 17:53 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Alistair Popple, Jonathan Corbet, linux-mm

On Mon, Aug 26, 2024 at 02:58:12PM +0800, Kefeng Wang wrote:
> Saves a couple of calls to compound_head() and remove last two callers
> of putback_lru_page().
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 6/6] mm: remove putback_lru_page()
  2024-08-26  6:58 ` [PATCH 6/6] mm: remove putback_lru_page() Kefeng Wang
  2024-08-26 15:08   ` David Hildenbrand
@ 2024-08-26 17:54   ` Vishal Moola
  1 sibling, 0 replies; 24+ messages in thread
From: Vishal Moola @ 2024-08-26 17:54 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Alistair Popple, Jonathan Corbet, linux-mm

On Mon, Aug 26, 2024 at 02:58:14PM +0800, Kefeng Wang wrote:
> There are no more callers of isolate_lru_page(), remove it.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5-fix/6] mm: remove isolate_lru_page() fix
  2024-08-26 14:41   ` [PATCH 5-fix/6] mm: remove isolate_lru_page() fix Kefeng Wang
@ 2024-08-26 17:54     ` Vishal Moola
  0 siblings, 0 replies; 24+ messages in thread
From: Vishal Moola @ 2024-08-26 17:54 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Alistair Popple, Jonathan Corbet, linux-mm

On Mon, Aug 26, 2024 at 10:41:14PM +0800, Kefeng Wang wrote:
> Convert page to folio in comment and document, per Matthew.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio()
  2024-08-26  6:58 ` [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Kefeng Wang
  2024-08-26 15:04   ` David Hildenbrand
  2024-08-26 17:52   ` Vishal Moola
@ 2024-08-27  5:42   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: Alistair Popple @ 2024-08-27  5:42 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Jonathan Corbet, linux-mm


Kefeng Wang <wangkefeng.wang@huawei.com> writes:

> -	WARN_ON_ONCE(PageCompound(page));
> +	WARN_ON_ONCE(folio_test_large(folio));

Note this isn't _quite_ the same as checking PageCompound() which also
checks page->compound_head & 1, but I'm guessing that should never
happen and certainly not for ZONE_DEVICE pages which can't (yet) be
compound anyway so:

Reviewed-by: Alistair Popple <apopple@nvidia.com>

>  
> -	lock_page(page);
> -	src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE;
> +	folio_lock(folio);
> +	src_pfn = migrate_pfn(folio_pfn(folio)) | MIGRATE_PFN_MIGRATE;
>  
>  	/*
>  	 * We don't have a VMA and don't need to walk the page tables to find
> -	 * the source page. So call migrate_vma_unmap() directly to unmap the
> -	 * page as migrate_vma_setup() will fail if args.vma == NULL.
> +	 * the source folio. So call migrate_vma_unmap() directly to unmap the
> +	 * folio as migrate_vma_setup() will fail if args.vma == NULL.
>  	 */
>  	migrate_device_unmap(&src_pfn, 1, NULL);
>  	if (!(src_pfn & MIGRATE_PFN_MIGRATE))
>  		return -EBUSY;
>  
> -	dpage = alloc_page(GFP_USER | __GFP_NOWARN);
> -	if (dpage) {
> -		lock_page(dpage);
> -		dst_pfn = migrate_pfn(page_to_pfn(dpage));
> +	dfolio = folio_alloc(GFP_USER | __GFP_NOWARN, 0);
> +	if (dfolio) {
> +		folio_lock(dfolio);
> +		dst_pfn = migrate_pfn(folio_pfn(dfolio));
>  	}
>  
>  	migrate_device_pages(&src_pfn, &dst_pfn, 1);
>  	if (src_pfn & MIGRATE_PFN_MIGRATE)
> -		copy_highpage(dpage, page);
> +		folio_copy(dfolio, folio);
>  	migrate_device_finalize(&src_pfn, &dst_pfn, 1);
>  
>  	if (src_pfn & MIGRATE_PFN_MIGRATE)



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range()
  2024-08-26  6:58 ` [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range() Kefeng Wang
  2024-08-26 15:05   ` David Hildenbrand
  2024-08-26 17:53   ` Vishal Moola
@ 2024-08-27  5:46   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: Alistair Popple @ 2024-08-27  5:46 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Jonathan Corbet, linux-mm


Kefeng Wang <wangkefeng.wang@huawei.com> writes:

> Save two calls to compound_head() and use folio throughout.
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Alistair Popple <apopple@nvidia.com>

> ---
>  mm/migrate_device.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 82d75205dda8..66db28b89f9b 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -898,16 +898,17 @@ int migrate_device_range(unsigned long *src_pfns, unsigned long start,
>  	unsigned long i, pfn;
>  
>  	for (pfn = start, i = 0; i < npages; pfn++, i++) {
> -		struct page *page = pfn_to_page(pfn);
> +		struct folio *folio;
>  
> -		if (!get_page_unless_zero(page)) {
> +		folio = folio_get_nontail_page(pfn_to_page(pfn));
> +		if (!folio) {
>  			src_pfns[i] = 0;
>  			continue;
>  		}
>  
> -		if (!trylock_page(page)) {
> +		if (!folio_trylock(folio)) {
>  			src_pfns[i] = 0;
> -			put_page(page);
> +			folio_put(folio);
>  			continue;
>  		}



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap()
  2024-08-26  6:58 ` [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap() Kefeng Wang
  2024-08-26 15:06   ` David Hildenbrand
  2024-08-26 17:53   ` Vishal Moola
@ 2024-08-27  5:47   ` Alistair Popple
  2 siblings, 0 replies; 24+ messages in thread
From: Alistair Popple @ 2024-08-27  5:47 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Jonathan Corbet, linux-mm


Kefeng Wang <wangkefeng.wang@huawei.com> writes:

> The page for migrate_device_unmap() already has a reference, so it is
> safe to convert the page to folio to save a few calls to compound_head(),
> which removes the last isolate_lru_page() call.
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Alistair Popple <apopple@nvidia.com>

> ---
>  mm/migrate_device.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 66db28b89f9b..b49f4956617a 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -379,33 +379,33 @@ static unsigned long migrate_device_unmap(unsigned long *src_pfns,
>  			continue;
>  		}
>  
> -		/* ZONE_DEVICE pages are not on LRU */
> -		if (!is_zone_device_page(page)) {
> -			if (!PageLRU(page) && allow_drain) {
> +		folio =	page_folio(page);
> +		/* ZONE_DEVICE folios are not on LRU */
> +		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) ||
> +		if (folio_mapped(folio) ||
>  		    !migrate_vma_check_page(page, fault_page)) {
> -			if (!is_zone_device_page(page)) {
> -				get_page(page);
> -				putback_lru_page(page);
> +			if (!folio_is_zone_device(folio)) {
> +				folio_get(folio);
> +				folio_putback_lru(folio);
>  			}
>  
>  			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize()
  2024-08-26  6:58 ` [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize() Kefeng Wang
  2024-08-26 17:53   ` Vishal Moola
@ 2024-08-27  5:48   ` Alistair Popple
  1 sibling, 0 replies; 24+ messages in thread
From: Alistair Popple @ 2024-08-27  5:48 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Baolin Wang,
	Zi Yan, Jonathan Corbet, linux-mm


Kefeng Wang <wangkefeng.wang@huawei.com> writes:

> Saves a couple of calls to compound_head() and remove last two callers
> of putback_lru_page().
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>  mm/migrate_device.c | 41 ++++++++++++++++++++++-------------------
>  1 file changed, 22 insertions(+), 19 deletions(-)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index b49f4956617a..6ea3d055f520 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -815,42 +815,45 @@ void migrate_device_finalize(unsigned long *src_pfns,
>  	unsigned long i;
>  
>  	for (i = 0; i < npages; i++) {
> -		struct folio *dst, *src;
> +		struct folio *dst = NULL, *src = NULL;
>  		struct page *newpage = migrate_pfn_to_page(dst_pfns[i]);
>  		struct page *page = migrate_pfn_to_page(src_pfns[i]);

We could probably simplify this even further with a
migrate_pfn_to_folio() function. I'm still working on extending
ZONE_DEVICE to support higher order folios though (held up fixing
refcounts) so this can wait until then.

Reviewed-by: Alistair Popple <apopple@nvidia.com>

>  
> +		if (newpage)
> +			dst = page_folio(newpage);
> +
>  		if (!page) {
> -			if (newpage) {
> -				unlock_page(newpage);
> -				put_page(newpage);
> +			if (dst) {
> +				folio_unlock(dst);
> +				folio_put(dst);
>  			}
>  			continue;
>  		}
>  
> -		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !newpage) {
> -			if (newpage) {
> -				unlock_page(newpage);
> -				put_page(newpage);
> +		src = page_folio(page);
> +
> +		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !dst) {
> +			if (dst) {
> +				folio_unlock(dst);
> +				folio_put(dst);
>  			}
> -			newpage = page;
> +			dst = src;
>  		}
>  
> -		src = page_folio(page);
> -		dst = page_folio(newpage);
>  		remove_migration_ptes(src, dst, false);
>  		folio_unlock(src);
>  
> -		if (is_zone_device_page(page))
> -			put_page(page);
> +		if (folio_is_zone_device(src))
> +			folio_put(src);
>  		else
> -			putback_lru_page(page);
> +			folio_putback_lru(src);
>  
> -		if (newpage != page) {
> -			unlock_page(newpage);
> -			if (is_zone_device_page(newpage))
> -				put_page(newpage);
> +		if (dst != src) {
> +			folio_unlock(dst);
> +			if (folio_is_zone_device(dst))
> +				folio_put(dst);
>  			else
> -				putback_lru_page(newpage);
> +				folio_putback_lru(dst);
>  		}
>  	}
>  }



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2024-08-27  5:52 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-26  6:58 [PATCH 0/6] mm: finish isolate/putback_lru_page() Kefeng Wang
2024-08-26  6:58 ` [PATCH 1/6] mm: migrate_device: convert to migrate_device_coherent_folio() Kefeng Wang
2024-08-26 15:04   ` David Hildenbrand
2024-08-26 17:52   ` Vishal Moola
2024-08-27  5:42   ` Alistair Popple
2024-08-26  6:58 ` [PATCH 2/6] mm: migrate_device: use a folio in migrate_device_range() Kefeng Wang
2024-08-26 15:05   ` David Hildenbrand
2024-08-26 17:53   ` Vishal Moola
2024-08-27  5:46   ` Alistair Popple
2024-08-26  6:58 ` [PATCH 3/6] mm: migrate_device: use more folio in migrate_device_unmap() Kefeng Wang
2024-08-26 15:06   ` David Hildenbrand
2024-08-26 17:53   ` Vishal Moola
2024-08-27  5:47   ` Alistair Popple
2024-08-26  6:58 ` [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize() Kefeng Wang
2024-08-26 17:53   ` Vishal Moola
2024-08-27  5:48   ` Alistair Popple
2024-08-26  6:58 ` [PATCH 5/6] mm: remove isolate_lru_page() Kefeng Wang
2024-08-26 13:05   ` Matthew Wilcox
2024-08-26 13:52     ` Kefeng Wang
2024-08-26 14:41   ` [PATCH 5-fix/6] mm: remove isolate_lru_page() fix Kefeng Wang
2024-08-26 17:54     ` Vishal Moola
2024-08-26  6:58 ` [PATCH 6/6] mm: remove putback_lru_page() Kefeng Wang
2024-08-26 15:08   ` David Hildenbrand
2024-08-26 17:54   ` Vishal Moola

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