linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] mm: cleanup MIGRATE_SYNC_NO_COPY mode
@ 2024-05-24  5:28 Kefeng Wang
  2024-05-24  5:28 ` [PATCH 1/5] mm: migrate: simplify __buffer_migrate_folio() Kefeng Wang
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Kefeng Wang @ 2024-05-24  5:28 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple,
	Kefeng Wang

Commit 2916ecc0f9d4 ("mm/migrate: new migrate mode MIGRATE_SYNC_NO_COPY")
introduce a new MIGRATE_SYNC_NO_COPY mode to allow to offload the copy to
a device DMA engine, which is only used __migrate_device_pages() to decide
whether or not copy the old page, and the MIGRATE_SYNC_NO_COPY mode only
used in hmm, a easy way is just to call the folio_migrate_mapping() and
folio_migrate_flags(), which help to remove the MIGRATE_SYNC_NO_COPY
mode.

---

This is splitted from "mm: migrate: support poison recover from migrate
folio"[1] to make it easier review and hope it merged firstly since no
more comment for a long time, rebase on next-20240523 and only patch2
changed a bit due to commit e18a9faf06c2.

[1] https://lore.kernel.org/linux-mm/20240424135929.2847185-9-wangkefeng.wang@huawei.com/

Kefeng Wang (5):
  mm: migrate: simplify __buffer_migrate_folio()
  mm: migrate_device: use a newfolio in __migrate_device_pages()
  mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY
  mm: migrate: remove migrate_folio_extra()
  mm: remove MIGRATE_SYNC_NO_COPY mode

 fs/aio.c                     | 12 +--------
 fs/hugetlbfs/inode.c         |  5 +---
 include/linux/migrate.h      |  2 --
 include/linux/migrate_mode.h |  5 ----
 mm/balloon_compaction.c      |  8 ------
 mm/migrate.c                 | 51 +++++++++---------------------------
 mm/migrate_device.c          | 22 +++++++++-------
 mm/zsmalloc.c                |  8 ------
 8 files changed, 27 insertions(+), 86 deletions(-)

-- 
2.27.0



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

* [PATCH 1/5] mm: migrate: simplify __buffer_migrate_folio()
  2024-05-24  5:28 [PATCH 0/5] mm: cleanup MIGRATE_SYNC_NO_COPY mode Kefeng Wang
@ 2024-05-24  5:28 ` Kefeng Wang
  2024-05-24  5:28 ` [PATCH 2/5] mm: migrate_device: use a newfolio in __migrate_device_pages() Kefeng Wang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Kefeng Wang @ 2024-05-24  5:28 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple,
	Kefeng Wang

Use filemap_migrate_folio() helper to simplify __buffer_migrate_folio().

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/migrate.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index dd04f578c19c..159f737501e1 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -777,24 +777,16 @@ static int __buffer_migrate_folio(struct address_space *mapping,
 		}
 	}
 
-	rc = folio_migrate_mapping(mapping, dst, src, 0);
+	rc = filemap_migrate_folio(mapping, dst, src, mode);
 	if (rc != MIGRATEPAGE_SUCCESS)
 		goto unlock_buffers;
 
-	folio_attach_private(dst, folio_detach_private(src));
-
 	bh = head;
 	do {
 		folio_set_bh(bh, dst, bh_offset(bh));
 		bh = bh->b_this_page;
 	} while (bh != head);
 
-	if (mode != MIGRATE_SYNC_NO_COPY)
-		folio_migrate_copy(dst, src);
-	else
-		folio_migrate_flags(dst, src);
-
-	rc = MIGRATEPAGE_SUCCESS;
 unlock_buffers:
 	if (check_refs)
 		spin_unlock(&mapping->i_private_lock);
-- 
2.27.0



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

* [PATCH 2/5] mm: migrate_device: use a newfolio in __migrate_device_pages()
  2024-05-24  5:28 [PATCH 0/5] mm: cleanup MIGRATE_SYNC_NO_COPY mode Kefeng Wang
  2024-05-24  5:28 ` [PATCH 1/5] mm: migrate: simplify __buffer_migrate_folio() Kefeng Wang
@ 2024-05-24  5:28 ` Kefeng Wang
  2024-05-24  5:28 ` [PATCH 3/5] mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY Kefeng Wang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Kefeng Wang @ 2024-05-24  5:28 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple,
	Kefeng Wang

Use a newfolio instead of newpage and convert to more folio api in
__migrate_device_pages().

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/migrate_device.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index aecc71972a87..f5e034de718a 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -692,7 +692,7 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 		struct page *newpage = migrate_pfn_to_page(dst_pfns[i]);
 		struct page *page = migrate_pfn_to_page(src_pfns[i]);
 		struct address_space *mapping;
-		struct folio *folio;
+		struct folio *newfolio, *folio;
 		int r;
 
 		if (!newpage) {
@@ -727,11 +727,12 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 			continue;
 		}
 
+		newfolio = page_folio(newpage);
 		folio = page_folio(page);
 		mapping = folio_mapping(folio);
 
-		if (is_device_private_page(newpage) ||
-		    is_device_coherent_page(newpage)) {
+		if (folio_is_device_private(newfolio) ||
+		    folio_is_device_coherent(newfolio)) {
 			if (mapping) {
 				/*
 				 * For now only support anonymous memory migrating to
@@ -745,7 +746,7 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 					continue;
 				}
 			}
-		} else if (is_zone_device_page(newpage)) {
+		} else if (folio_is_zone_device(newfolio)) {
 			/*
 			 * Other types of ZONE_DEVICE page are not supported.
 			 */
@@ -754,11 +755,11 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 		}
 
 		if (migrate && migrate->fault_page == page)
-			r = migrate_folio_extra(mapping, page_folio(newpage),
-						folio, MIGRATE_SYNC_NO_COPY, 1);
+			r = migrate_folio_extra(mapping, newfolio, folio,
+						MIGRATE_SYNC_NO_COPY, 1);
 		else
-			r = migrate_folio(mapping, page_folio(newpage),
-					folio, MIGRATE_SYNC_NO_COPY);
+			r = migrate_folio(mapping, newfolio, folio,
+					  MIGRATE_SYNC_NO_COPY);
 		if (r != MIGRATEPAGE_SUCCESS)
 			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
 	}
-- 
2.27.0



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

* [PATCH 3/5] mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY
  2024-05-24  5:28 [PATCH 0/5] mm: cleanup MIGRATE_SYNC_NO_COPY mode Kefeng Wang
  2024-05-24  5:28 ` [PATCH 1/5] mm: migrate: simplify __buffer_migrate_folio() Kefeng Wang
  2024-05-24  5:28 ` [PATCH 2/5] mm: migrate_device: use a newfolio in __migrate_device_pages() Kefeng Wang
@ 2024-05-24  5:28 ` Kefeng Wang
  2024-06-07 20:23   ` Jane Chu
  2024-05-24  5:28 ` [PATCH 4/5] mm: migrate: remove migrate_folio_extra() Kefeng Wang
  2024-05-24  5:28 ` [PATCH 5/5] mm: remove MIGRATE_SYNC_NO_COPY mode Kefeng Wang
  4 siblings, 1 reply; 9+ messages in thread
From: Kefeng Wang @ 2024-05-24  5:28 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple,
	Kefeng Wang

The __migrate_device_pages() won't copy page so MIGRATE_SYNC_NO_COPY
passed into migrate_folio()/migrate_folio_extra(), actually a easy
way is just to call folio_migrate_mapping()/folio_migrate_flags(),
converting it to unify and simplify the migrate device pages, which
also remove the only call for MIGRATE_SYNC_NO_COPY.

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

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index f5e034de718a..051d0a3ccbee 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -693,7 +693,7 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 		struct page *page = migrate_pfn_to_page(src_pfns[i]);
 		struct address_space *mapping;
 		struct folio *newfolio, *folio;
-		int r;
+		int r, extra_cnt = 0;
 
 		if (!newpage) {
 			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
@@ -754,14 +754,15 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 			continue;
 		}
 
+		BUG_ON(folio_test_writeback(folio));
+
 		if (migrate && migrate->fault_page == page)
-			r = migrate_folio_extra(mapping, newfolio, folio,
-						MIGRATE_SYNC_NO_COPY, 1);
-		else
-			r = migrate_folio(mapping, newfolio, folio,
-					  MIGRATE_SYNC_NO_COPY);
+			extra_cnt = 1;
+		r = folio_migrate_mapping(mapping, newfolio, folio, extra_cnt);
 		if (r != MIGRATEPAGE_SUCCESS)
 			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
+		else
+			folio_migrate_flags(newfolio, folio);
 	}
 
 	if (notified)
-- 
2.27.0



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

* [PATCH 4/5] mm: migrate: remove migrate_folio_extra()
  2024-05-24  5:28 [PATCH 0/5] mm: cleanup MIGRATE_SYNC_NO_COPY mode Kefeng Wang
                   ` (2 preceding siblings ...)
  2024-05-24  5:28 ` [PATCH 3/5] mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY Kefeng Wang
@ 2024-05-24  5:28 ` Kefeng Wang
  2024-06-07 20:38   ` Jane Chu
  2024-05-24  5:28 ` [PATCH 5/5] mm: remove MIGRATE_SYNC_NO_COPY mode Kefeng Wang
  4 siblings, 1 reply; 9+ messages in thread
From: Kefeng Wang @ 2024-05-24  5:28 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple,
	Kefeng Wang

The migrate_folio_extra() only called in migrate.c now, convert it
a static function and take a new src_private argument which could
be shared by migrate_folio() and filemap_migrate_folio() to simplify
code a bit.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/migrate.h |  2 --
 mm/migrate.c            | 33 +++++++++++----------------------
 2 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index 2ce13e8a309b..517f70b70620 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -63,8 +63,6 @@ extern const char *migrate_reason_names[MR_TYPES];
 #ifdef CONFIG_MIGRATION
 
 void putback_movable_pages(struct list_head *l);
-int migrate_folio_extra(struct address_space *mapping, struct folio *dst,
-		struct folio *src, enum migrate_mode mode, int extra_count);
 int migrate_folio(struct address_space *mapping, struct folio *dst,
 		struct folio *src, enum migrate_mode mode);
 int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free,
diff --git a/mm/migrate.c b/mm/migrate.c
index 159f737501e1..1d1cb832fdb4 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -658,18 +658,19 @@ EXPORT_SYMBOL(folio_migrate_copy);
  *                    Migration functions
  ***********************************************************/
 
-int migrate_folio_extra(struct address_space *mapping, struct folio *dst,
-		struct folio *src, enum migrate_mode mode, int extra_count)
+static int __migrate_folio(struct address_space *mapping, struct folio *dst,
+			   struct folio *src, void *src_private,
+			   enum migrate_mode mode)
 {
 	int rc;
 
-	BUG_ON(folio_test_writeback(src));	/* Writeback must be complete */
-
-	rc = folio_migrate_mapping(mapping, dst, src, extra_count);
-
+	rc = folio_migrate_mapping(mapping, dst, src, 0);
 	if (rc != MIGRATEPAGE_SUCCESS)
 		return rc;
 
+	if (src_private)
+		folio_attach_private(dst, folio_detach_private(src));
+
 	if (mode != MIGRATE_SYNC_NO_COPY)
 		folio_migrate_copy(dst, src);
 	else
@@ -690,9 +691,10 @@ int migrate_folio_extra(struct address_space *mapping, struct folio *dst,
  * Folios are locked upon entry and exit.
  */
 int migrate_folio(struct address_space *mapping, struct folio *dst,
-		struct folio *src, enum migrate_mode mode)
+		  struct folio *src, enum migrate_mode mode)
 {
-	return migrate_folio_extra(mapping, dst, src, mode, 0);
+	BUG_ON(folio_test_writeback(src));	/* Writeback must be complete */
+	return __migrate_folio(mapping, dst, src, NULL, mode);
 }
 EXPORT_SYMBOL(migrate_folio);
 
@@ -846,20 +848,7 @@ EXPORT_SYMBOL_GPL(buffer_migrate_folio_norefs);
 int filemap_migrate_folio(struct address_space *mapping,
 		struct folio *dst, struct folio *src, enum migrate_mode mode)
 {
-	int ret;
-
-	ret = folio_migrate_mapping(mapping, dst, src, 0);
-	if (ret != MIGRATEPAGE_SUCCESS)
-		return ret;
-
-	if (folio_get_private(src))
-		folio_attach_private(dst, folio_detach_private(src));
-
-	if (mode != MIGRATE_SYNC_NO_COPY)
-		folio_migrate_copy(dst, src);
-	else
-		folio_migrate_flags(dst, src);
-	return MIGRATEPAGE_SUCCESS;
+	return __migrate_folio(mapping, dst, src, folio_get_private(src), mode);
 }
 EXPORT_SYMBOL_GPL(filemap_migrate_folio);
 
-- 
2.27.0



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

* [PATCH 5/5] mm: remove MIGRATE_SYNC_NO_COPY mode
  2024-05-24  5:28 [PATCH 0/5] mm: cleanup MIGRATE_SYNC_NO_COPY mode Kefeng Wang
                   ` (3 preceding siblings ...)
  2024-05-24  5:28 ` [PATCH 4/5] mm: migrate: remove migrate_folio_extra() Kefeng Wang
@ 2024-05-24  5:28 ` Kefeng Wang
  2024-06-07 21:27   ` Jane Chu
  4 siblings, 1 reply; 9+ messages in thread
From: Kefeng Wang @ 2024-05-24  5:28 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple,
	Kefeng Wang

Commit 2916ecc0f9d4 ("mm/migrate: new migrate mode MIGRATE_SYNC_NO_COPY")
introduce a new MIGRATE_SYNC_NO_COPY mode to allow to offload the copy to
a device DMA engine, which is only used __migrate_device_pages() to decide
whether or not copy the old page, and the MIGRATE_SYNC_NO_COPY mode only
set in hmm, as the MIGRATE_SYNC_NO_COPY set is removed by previous cleanup,
it seems that we could remove the unnecessary MIGRATE_SYNC_NO_COPY.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 fs/aio.c                     | 12 +-----------
 fs/hugetlbfs/inode.c         |  5 +----
 include/linux/migrate_mode.h |  5 -----
 mm/balloon_compaction.c      |  8 --------
 mm/migrate.c                 |  8 +-------
 mm/zsmalloc.c                |  8 --------
 6 files changed, 3 insertions(+), 43 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 57c9f7c077e6..07ff8bbdcd2a 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -410,17 +410,7 @@ static int aio_migrate_folio(struct address_space *mapping, struct folio *dst,
 	struct kioctx *ctx;
 	unsigned long flags;
 	pgoff_t idx;
-	int rc;
-
-	/*
-	 * We cannot support the _NO_COPY case here, because copy needs to
-	 * happen under the ctx->completion_lock. That does not work with the
-	 * migration workflow of MIGRATE_SYNC_NO_COPY.
-	 */
-	if (mode == MIGRATE_SYNC_NO_COPY)
-		return -EINVAL;
-
-	rc = 0;
+	int rc = 0;
 
 	/* mapping->i_private_lock here protects against the kioctx teardown.  */
 	spin_lock(&mapping->i_private_lock);
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 412f295acebe..6df794ed4066 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1128,10 +1128,7 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping,
 		hugetlb_set_folio_subpool(src, NULL);
 	}
 
-	if (mode != MIGRATE_SYNC_NO_COPY)
-		folio_migrate_copy(dst, src);
-	else
-		folio_migrate_flags(dst, src);
+	folio_migrate_copy(dst, src);
 
 	return MIGRATEPAGE_SUCCESS;
 }
diff --git a/include/linux/migrate_mode.h b/include/linux/migrate_mode.h
index f37cc03f9369..9fb482bb7323 100644
--- a/include/linux/migrate_mode.h
+++ b/include/linux/migrate_mode.h
@@ -7,16 +7,11 @@
  *	on most operations but not ->writepage as the potential stall time
  *	is too significant
  * MIGRATE_SYNC will block when migrating pages
- * MIGRATE_SYNC_NO_COPY will block when migrating pages but will not copy pages
- *	with the CPU. Instead, page copy happens outside the migratepage()
- *	callback and is likely using a DMA engine. See migrate_vma() and HMM
- *	(mm/hmm.c) for users of this mode.
  */
 enum migrate_mode {
 	MIGRATE_ASYNC,
 	MIGRATE_SYNC_LIGHT,
 	MIGRATE_SYNC,
-	MIGRATE_SYNC_NO_COPY,
 };
 
 enum migrate_reason {
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 22c96fed70b5..6597ebea8ae2 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -234,14 +234,6 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
 {
 	struct balloon_dev_info *balloon = balloon_page_device(page);
 
-	/*
-	 * We can not easily support the no copy case here so ignore it as it
-	 * is unlikely to be used with balloon pages. See include/linux/hmm.h
-	 * for a user of the MIGRATE_SYNC_NO_COPY mode.
-	 */
-	if (mode == MIGRATE_SYNC_NO_COPY)
-		return -EINVAL;
-
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
 
diff --git a/mm/migrate.c b/mm/migrate.c
index 1d1cb832fdb4..e04b451c4289 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -671,10 +671,7 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst,
 	if (src_private)
 		folio_attach_private(dst, folio_detach_private(src));
 
-	if (mode != MIGRATE_SYNC_NO_COPY)
-		folio_migrate_copy(dst, src);
-	else
-		folio_migrate_flags(dst, src);
+	folio_migrate_copy(dst, src);
 	return MIGRATEPAGE_SUCCESS;
 }
 
@@ -903,7 +900,6 @@ static int fallback_migrate_folio(struct address_space *mapping,
 		/* Only writeback folios in full synchronous migration */
 		switch (mode) {
 		case MIGRATE_SYNC:
-		case MIGRATE_SYNC_NO_COPY:
 			break;
 		default:
 			return -EBUSY;
@@ -1161,7 +1157,6 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
 		 */
 		switch (mode) {
 		case MIGRATE_SYNC:
-		case MIGRATE_SYNC_NO_COPY:
 			break;
 		default:
 			rc = -EBUSY;
@@ -1372,7 +1367,6 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio,
 			goto out;
 		switch (mode) {
 		case MIGRATE_SYNC:
-		case MIGRATE_SYNC_NO_COPY:
 			break;
 		default:
 			goto out;
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index b42d3545ca85..6e7967853477 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1752,14 +1752,6 @@ static int zs_page_migrate(struct page *newpage, struct page *page,
 	unsigned long old_obj, new_obj;
 	unsigned int obj_idx;
 
-	/*
-	 * We cannot support the _NO_COPY case here, because copy needs to
-	 * happen under the zs lock, which does not work with
-	 * MIGRATE_SYNC_NO_COPY workflow.
-	 */
-	if (mode == MIGRATE_SYNC_NO_COPY)
-		return -EINVAL;
-
 	VM_BUG_ON_PAGE(!PageIsolated(page), page);
 
 	/* The page is locked, so this pointer must remain valid */
-- 
2.27.0



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

* Re: [PATCH 3/5] mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY
  2024-05-24  5:28 ` [PATCH 3/5] mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY Kefeng Wang
@ 2024-06-07 20:23   ` Jane Chu
  0 siblings, 0 replies; 9+ messages in thread
From: Jane Chu @ 2024-06-07 20:23 UTC (permalink / raw)
  To: Kefeng Wang, akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple

On 5/23/2024 10:28 PM, Kefeng Wang wrote:

> The __migrate_device_pages() won't copy page so MIGRATE_SYNC_NO_COPY
> passed into migrate_folio()/migrate_folio_extra(), actually a easy
> way is just to call folio_migrate_mapping()/folio_migrate_flags(),
> converting it to unify and simplify the migrate device pages, which
> also remove the only call for MIGRATE_SYNC_NO_COPY.
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>   mm/migrate_device.c | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index f5e034de718a..051d0a3ccbee 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -693,7 +693,7 @@ static void __migrate_device_pages(unsigned long *src_pfns,
>   		struct page *page = migrate_pfn_to_page(src_pfns[i]);
>   		struct address_space *mapping;
>   		struct folio *newfolio, *folio;
> -		int r;
> +		int r, extra_cnt = 0;
>   
>   		if (!newpage) {
>   			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
> @@ -754,14 +754,15 @@ static void __migrate_device_pages(unsigned long *src_pfns,
>   			continue;
>   		}
>   
> +		BUG_ON(folio_test_writeback(folio));
> +
>   		if (migrate && migrate->fault_page == page)
> -			r = migrate_folio_extra(mapping, newfolio, folio,
> -						MIGRATE_SYNC_NO_COPY, 1);
> -		else
> -			r = migrate_folio(mapping, newfolio, folio,
> -					  MIGRATE_SYNC_NO_COPY);
> +			extra_cnt = 1;
> +		r = folio_migrate_mapping(mapping, newfolio, folio, extra_cnt);
>   		if (r != MIGRATEPAGE_SUCCESS)
>   			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
> +		else
> +			folio_migrate_flags(newfolio, folio);
>   	}
>   
>   	if (notified)

No functionality change, looks good.

Reviewed-by:  Jane Chu <jane.chu@oracle.com>

-jane



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

* Re: [PATCH 4/5] mm: migrate: remove migrate_folio_extra()
  2024-05-24  5:28 ` [PATCH 4/5] mm: migrate: remove migrate_folio_extra() Kefeng Wang
@ 2024-06-07 20:38   ` Jane Chu
  0 siblings, 0 replies; 9+ messages in thread
From: Jane Chu @ 2024-06-07 20:38 UTC (permalink / raw)
  To: Kefeng Wang, akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple

On 5/23/2024 10:28 PM, Kefeng Wang wrote:

> The migrate_folio_extra() only called in migrate.c now, convert it
> a static function and take a new src_private argument which could
> be shared by migrate_folio() and filemap_migrate_folio() to simplify
> code a bit.
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>   include/linux/migrate.h |  2 --
>   mm/migrate.c            | 33 +++++++++++----------------------
>   2 files changed, 11 insertions(+), 24 deletions(-)
>
> diff --git a/include/linux/migrate.h b/include/linux/migrate.h
> index 2ce13e8a309b..517f70b70620 100644
> --- a/include/linux/migrate.h
> +++ b/include/linux/migrate.h
> @@ -63,8 +63,6 @@ extern const char *migrate_reason_names[MR_TYPES];
>   #ifdef CONFIG_MIGRATION
>   
>   void putback_movable_pages(struct list_head *l);
> -int migrate_folio_extra(struct address_space *mapping, struct folio *dst,
> -		struct folio *src, enum migrate_mode mode, int extra_count);
>   int migrate_folio(struct address_space *mapping, struct folio *dst,
>   		struct folio *src, enum migrate_mode mode);
>   int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free,
> diff --git a/mm/migrate.c b/mm/migrate.c
> index 159f737501e1..1d1cb832fdb4 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -658,18 +658,19 @@ EXPORT_SYMBOL(folio_migrate_copy);
>    *                    Migration functions
>    ***********************************************************/
>   
> -int migrate_folio_extra(struct address_space *mapping, struct folio *dst,
> -		struct folio *src, enum migrate_mode mode, int extra_count)
> +static int __migrate_folio(struct address_space *mapping, struct folio *dst,
> +			   struct folio *src, void *src_private,
> +			   enum migrate_mode mode)
>   {
>   	int rc;
>   
> -	BUG_ON(folio_test_writeback(src));	/* Writeback must be complete */
> -
> -	rc = folio_migrate_mapping(mapping, dst, src, extra_count);
> -
> +	rc = folio_migrate_mapping(mapping, dst, src, 0);
>   	if (rc != MIGRATEPAGE_SUCCESS)
>   		return rc;
>   
> +	if (src_private)
> +		folio_attach_private(dst, folio_detach_private(src));
> +
>   	if (mode != MIGRATE_SYNC_NO_COPY)
>   		folio_migrate_copy(dst, src);
>   	else
> @@ -690,9 +691,10 @@ int migrate_folio_extra(struct address_space *mapping, struct folio *dst,
>    * Folios are locked upon entry and exit.
>    */
>   int migrate_folio(struct address_space *mapping, struct folio *dst,
> -		struct folio *src, enum migrate_mode mode)
> +		  struct folio *src, enum migrate_mode mode)
>   {
> -	return migrate_folio_extra(mapping, dst, src, mode, 0);
> +	BUG_ON(folio_test_writeback(src));	/* Writeback must be complete */
> +	return __migrate_folio(mapping, dst, src, NULL, mode);
>   }
>   EXPORT_SYMBOL(migrate_folio);
>   
> @@ -846,20 +848,7 @@ EXPORT_SYMBOL_GPL(buffer_migrate_folio_norefs);
>   int filemap_migrate_folio(struct address_space *mapping,
>   		struct folio *dst, struct folio *src, enum migrate_mode mode)
>   {
> -	int ret;
> -
> -	ret = folio_migrate_mapping(mapping, dst, src, 0);
> -	if (ret != MIGRATEPAGE_SUCCESS)
> -		return ret;
> -
> -	if (folio_get_private(src))
> -		folio_attach_private(dst, folio_detach_private(src));
> -
> -	if (mode != MIGRATE_SYNC_NO_COPY)
> -		folio_migrate_copy(dst, src);
> -	else
> -		folio_migrate_flags(dst, src);
> -	return MIGRATEPAGE_SUCCESS;
> +	return __migrate_folio(mapping, dst, src, folio_get_private(src), mode);
>   }
>   EXPORT_SYMBOL_GPL(filemap_migrate_folio);
>   

Looks good.

Reviewed-by: Jane Chu <jane.chu@oracle.com>

-jane




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

* Re: [PATCH 5/5] mm: remove MIGRATE_SYNC_NO_COPY mode
  2024-05-24  5:28 ` [PATCH 5/5] mm: remove MIGRATE_SYNC_NO_COPY mode Kefeng Wang
@ 2024-06-07 21:27   ` Jane Chu
  0 siblings, 0 replies; 9+ messages in thread
From: Jane Chu @ 2024-06-07 21:27 UTC (permalink / raw)
  To: Kefeng Wang, akpm, linux-mm
  Cc: Tony Luck, Miaohe Lin, nao.horiguchi, Matthew Wilcox,
	David Hildenbrand, Muchun Song, Benjamin LaHaise, jglisse,
	Zi Yan, Jiaqi Yan, Hugh Dickins, Vishal Moola, Alistair Popple

On 5/23/2024 10:28 PM, Kefeng Wang wrote:

> Commit 2916ecc0f9d4 ("mm/migrate: new migrate mode MIGRATE_SYNC_NO_COPY")
> introduce a new MIGRATE_SYNC_NO_COPY mode to allow to offload the copy to
> a device DMA engine, which is only used __migrate_device_pages() to decide
nit:  s/only used/only used in/
> whether or not copy the old page, and the MIGRATE_SYNC_NO_COPY mode only
s/copy/to copy/,  s/mode only set/mode is only set/
> set in hmm, as the MIGRATE_SYNC_NO_COPY set is removed by previous cleanup,
> it seems that we could remove the unnecessary MIGRATE_SYNC_NO_COPY.
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>   fs/aio.c                     | 12 +-----------
>   fs/hugetlbfs/inode.c         |  5 +----
>   include/linux/migrate_mode.h |  5 -----
>   mm/balloon_compaction.c      |  8 --------
>   mm/migrate.c                 |  8 +-------
>   mm/zsmalloc.c                |  8 --------
>   6 files changed, 3 insertions(+), 43 deletions(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 57c9f7c077e6..07ff8bbdcd2a 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -410,17 +410,7 @@ static int aio_migrate_folio(struct address_space *mapping, struct folio *dst,
>   	struct kioctx *ctx;
>   	unsigned long flags;
>   	pgoff_t idx;
> -	int rc;
> -
> -	/*
> -	 * We cannot support the _NO_COPY case here, because copy needs to
> -	 * happen under the ctx->completion_lock. That does not work with the
> -	 * migration workflow of MIGRATE_SYNC_NO_COPY.
> -	 */
> -	if (mode == MIGRATE_SYNC_NO_COPY)
> -		return -EINVAL;
> -
> -	rc = 0;
> +	int rc = 0;
>   
>   	/* mapping->i_private_lock here protects against the kioctx teardown.  */
>   	spin_lock(&mapping->i_private_lock);
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 412f295acebe..6df794ed4066 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -1128,10 +1128,7 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping,
>   		hugetlb_set_folio_subpool(src, NULL);
>   	}
>   
> -	if (mode != MIGRATE_SYNC_NO_COPY)
> -		folio_migrate_copy(dst, src);
> -	else
> -		folio_migrate_flags(dst, src);
> +	folio_migrate_copy(dst, src);
>   
>   	return MIGRATEPAGE_SUCCESS;
>   }
> diff --git a/include/linux/migrate_mode.h b/include/linux/migrate_mode.h
> index f37cc03f9369..9fb482bb7323 100644
> --- a/include/linux/migrate_mode.h
> +++ b/include/linux/migrate_mode.h
> @@ -7,16 +7,11 @@
>    *	on most operations but not ->writepage as the potential stall time
>    *	is too significant
>    * MIGRATE_SYNC will block when migrating pages
> - * MIGRATE_SYNC_NO_COPY will block when migrating pages but will not copy pages
> - *	with the CPU. Instead, page copy happens outside the migratepage()
> - *	callback and is likely using a DMA engine. See migrate_vma() and HMM
> - *	(mm/hmm.c) for users of this mode.
>    */
>   enum migrate_mode {
>   	MIGRATE_ASYNC,
>   	MIGRATE_SYNC_LIGHT,
>   	MIGRATE_SYNC,
> -	MIGRATE_SYNC_NO_COPY,
>   };
>   
>   enum migrate_reason {
> diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
> index 22c96fed70b5..6597ebea8ae2 100644
> --- a/mm/balloon_compaction.c
> +++ b/mm/balloon_compaction.c
> @@ -234,14 +234,6 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
>   {
>   	struct balloon_dev_info *balloon = balloon_page_device(page);
>   
> -	/*
> -	 * We can not easily support the no copy case here so ignore it as it
> -	 * is unlikely to be used with balloon pages. See include/linux/hmm.h
> -	 * for a user of the MIGRATE_SYNC_NO_COPY mode.
> -	 */
> -	if (mode == MIGRATE_SYNC_NO_COPY)
> -		return -EINVAL;
> -
>   	VM_BUG_ON_PAGE(!PageLocked(page), page);
>   	VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
>   
> diff --git a/mm/migrate.c b/mm/migrate.c
> index 1d1cb832fdb4..e04b451c4289 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -671,10 +671,7 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst,
>   	if (src_private)
>   		folio_attach_private(dst, folio_detach_private(src));
>   
> -	if (mode != MIGRATE_SYNC_NO_COPY)
> -		folio_migrate_copy(dst, src);
> -	else
> -		folio_migrate_flags(dst, src);
> +	folio_migrate_copy(dst, src);
>   	return MIGRATEPAGE_SUCCESS;
>   }
>   
> @@ -903,7 +900,6 @@ static int fallback_migrate_folio(struct address_space *mapping,
>   		/* Only writeback folios in full synchronous migration */
>   		switch (mode) {
>   		case MIGRATE_SYNC:
> -		case MIGRATE_SYNC_NO_COPY:
>   			break;
>   		default:
>   			return -EBUSY;
> @@ -1161,7 +1157,6 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
>   		 */
>   		switch (mode) {
>   		case MIGRATE_SYNC:
> -		case MIGRATE_SYNC_NO_COPY:
>   			break;
>   		default:
>   			rc = -EBUSY;
> @@ -1372,7 +1367,6 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio,
>   			goto out;
>   		switch (mode) {
>   		case MIGRATE_SYNC:
> -		case MIGRATE_SYNC_NO_COPY:
>   			break;
>   		default:
>   			goto out;
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index b42d3545ca85..6e7967853477 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -1752,14 +1752,6 @@ static int zs_page_migrate(struct page *newpage, struct page *page,
>   	unsigned long old_obj, new_obj;
>   	unsigned int obj_idx;
>   
> -	/*
> -	 * We cannot support the _NO_COPY case here, because copy needs to
> -	 * happen under the zs lock, which does not work with
> -	 * MIGRATE_SYNC_NO_COPY workflow.
> -	 */
> -	if (mode == MIGRATE_SYNC_NO_COPY)
> -		return -EINVAL;
> -
>   	VM_BUG_ON_PAGE(!PageIsolated(page), page);
>   
>   	/* The page is locked, so this pointer must remain valid */

Except the nits above, patch looks good to me.

Reviewed-by: Jane Chu <jane.chu@oracle.com>

-jane




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

end of thread, other threads:[~2024-06-07 21:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-24  5:28 [PATCH 0/5] mm: cleanup MIGRATE_SYNC_NO_COPY mode Kefeng Wang
2024-05-24  5:28 ` [PATCH 1/5] mm: migrate: simplify __buffer_migrate_folio() Kefeng Wang
2024-05-24  5:28 ` [PATCH 2/5] mm: migrate_device: use a newfolio in __migrate_device_pages() Kefeng Wang
2024-05-24  5:28 ` [PATCH 3/5] mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY Kefeng Wang
2024-06-07 20:23   ` Jane Chu
2024-05-24  5:28 ` [PATCH 4/5] mm: migrate: remove migrate_folio_extra() Kefeng Wang
2024-06-07 20:38   ` Jane Chu
2024-05-24  5:28 ` [PATCH 5/5] mm: remove MIGRATE_SYNC_NO_COPY mode Kefeng Wang
2024-06-07 21:27   ` Jane Chu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox