From: Alistair Popple <apopple@nvidia.com>
To: linux-mm@kvack.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Alistair Popple <apopple@nvidia.com>
Subject: [PATCH RFC 2/6] mm/migrate: Support file-backed pages with migrate_vma
Date: Sun, 16 Mar 2025 15:29:25 +1100 [thread overview]
Message-ID: <1371381f755a8f04a8228e52c36ddfde72949b57.1742099301.git-series.apopple@nvidia.com> (raw)
In-Reply-To: <cover.24b48fced909fe1414e83b58aa468d4393dd06de.1742099301.git-series.apopple@nvidia.com>
This adds support for migrating file backed pages with the migrate_vma
calls. Note that this does not support migrating file backed pages
to device private pages, only CPU addressable memory. However add the
extra refcount argument to support faulting on device privatge pages
in future.
Signed-off-by: Alistair Popple <apopple@nvidia.com>
---
Known issues with the RFC:
- Some filesystems (eg. xfs, nfs) can insert higher order compound
pages in the pagecache. Migration will fail for such pages.
---
include/linux/migrate.h | 4 ++++
mm/migrate.c | 19 +++++++++++--------
mm/migrate_device.c | 11 +++++++++--
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index 29919fa..9023d0f 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -222,6 +222,10 @@ struct migrate_vma {
struct page *fault_page;
};
+int fallback_migrate_folio(struct address_space *mapping,
+ struct folio *dst, struct folio *src, enum migrate_mode mode,
+ int extra_count);
+
int migrate_vma_setup(struct migrate_vma *args);
void migrate_vma_pages(struct migrate_vma *migrate);
void migrate_vma_finalize(struct migrate_vma *migrate);
diff --git a/mm/migrate.c b/mm/migrate.c
index fb19a18..11fca43 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -749,9 +749,10 @@ EXPORT_SYMBOL(folio_migrate_flags);
static int __migrate_folio(struct address_space *mapping, struct folio *dst,
struct folio *src, void *src_private,
- enum migrate_mode mode)
+ enum migrate_mode mode, int extra_count)
{
- int rc, expected_count = folio_expected_refs(mapping, src);
+ int rc;
+ int expected_count = folio_expected_refs(mapping, src) + extra_count;
/* Check whether src does not have extra refs before we do more work */
if (folio_ref_count(src) != expected_count)
@@ -788,7 +789,7 @@ int migrate_folio(struct address_space *mapping, struct folio *dst,
struct folio *src, enum migrate_mode mode)
{
BUG_ON(folio_test_writeback(src)); /* Writeback must be complete */
- return __migrate_folio(mapping, dst, src, NULL, mode);
+ return __migrate_folio(mapping, dst, src, NULL, mode, 0);
}
EXPORT_SYMBOL(migrate_folio);
@@ -942,7 +943,8 @@ 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)
{
- return __migrate_folio(mapping, dst, src, folio_get_private(src), mode);
+ return __migrate_folio(mapping, dst, src,
+ folio_get_private(src), mode, 0);
}
EXPORT_SYMBOL_GPL(filemap_migrate_folio);
@@ -990,8 +992,9 @@ static int writeout(struct address_space *mapping, struct folio *folio)
/*
* Default handling if a filesystem does not provide a migration function.
*/
-static int fallback_migrate_folio(struct address_space *mapping,
- struct folio *dst, struct folio *src, enum migrate_mode mode)
+int fallback_migrate_folio(struct address_space *mapping,
+ struct folio *dst, struct folio *src, enum migrate_mode mode,
+ int extra_count)
{
if (folio_test_dirty(src)) {
/* Only writeback folios in full synchronous migration */
@@ -1011,7 +1014,7 @@ static int fallback_migrate_folio(struct address_space *mapping,
if (!filemap_release_folio(src, GFP_KERNEL))
return mode == MIGRATE_SYNC ? -EAGAIN : -EBUSY;
- return migrate_folio(mapping, dst, src, mode);
+ return __migrate_folio(mapping, dst, src, NULL, mode, extra_count);
}
/*
@@ -1052,7 +1055,7 @@ static int move_to_new_folio(struct folio *dst, struct folio *src,
rc = mapping->a_ops->migrate_folio(mapping, dst, src,
mode);
else
- rc = fallback_migrate_folio(mapping, dst, src, mode);
+ rc = fallback_migrate_folio(mapping, dst, src, mode, 0);
} else {
const struct movable_operations *mops;
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index afc033b..7bcc177 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -763,11 +763,18 @@ static void __migrate_device_pages(unsigned long *src_pfns,
if (migrate && migrate->fault_page == page)
extra_cnt = 1;
- r = folio_migrate_mapping(mapping, newfolio, folio, extra_cnt);
+ if (mapping)
+ r = fallback_migrate_folio(mapping, newfolio, folio,
+ MIGRATE_SYNC, extra_cnt);
+ else
+ r = folio_migrate_mapping(mapping, newfolio, folio,
+ extra_cnt);
if (r != MIGRATEPAGE_SUCCESS)
src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
- else
+ else if (!mapping)
folio_migrate_flags(newfolio, folio);
+ else
+ folio->mapping = NULL;
}
if (notified)
--
git-series 0.9.1
next prev parent reply other threads:[~2025-03-16 4:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-16 4:29 [PATCH RFC 0/6] Allow file-backed or shared device private pages Alistair Popple
2025-03-16 4:29 ` [PATCH RFC 1/6] mm/migrate_device.c: Don't read dirty bit of non-present PTEs Alistair Popple
2025-03-16 4:29 ` Alistair Popple [this message]
2025-03-16 4:29 ` [PATCH RFC 3/6] mm: Allow device private pages to exist in page cache Alistair Popple
2025-03-16 4:29 ` [PATCH RFC 4/6] mm: Implement writeback for share device private pages Alistair Popple
2025-03-16 4:29 ` [PATCH RFC 5/6] selftests/hmm: Add file-backed migration tests Alistair Popple
2025-03-16 4:29 ` [PATCH RFC 6/6] nouveau: Add SVM support for migrating file-backed pages to the GPU Alistair Popple
2025-03-17 6:04 ` [PATCH RFC 0/6] Allow file-backed or shared device private pages Christoph Hellwig
2025-03-26 2:14 ` Matthew Wilcox
2025-03-27 14:49 ` Alistair Popple
2025-03-27 16:47 ` Matthew Wilcox
2025-04-07 9:15 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371381f755a8f04a8228e52c36ddfde72949b57.1742099301.git-series.apopple@nvidia.com \
--to=apopple@nvidia.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox