From: Wandun Chen <chenwandun1@gmail.com>
To: david@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: ljs@kernel.org, liam@infradead.org, vbabka@kernel.org,
rppt@kernel.org, surenb@google.com, mhocko@suse.com,
ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com,
byungchul@sk.com, gourry@gourry.net,
ying.huang@linux.alibaba.com, apopple@nvidia.com
Subject: [PATCH 3/3] mm/migrate: batch PTE restoration for device-private folios
Date: Fri, 20 Nov 2026 11:29:49 +0800 [thread overview]
Message-ID: <20261120032949.2036731-4-chenwandun1@gmail.com> (raw)
In-Reply-To: <20261120032949.2036731-1-chenwandun1@gmail.com>
From: Wandun Chen <chenwandun@lixiang.com>
Device-private PTEs encode PFN as softleaf offset. set_ptes() does not
handle this encoding when constructing subsequent PTEs, such as on
arm64 with a 16KB page granule, leaving device-private destinations
folio unbatched.
Add set_device_private_ptes() to construct subsequent entries with
pte_next_swp_offset(). This enables remove_migration_pte() to batch
PTE restoration for device-private folios.
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
---
mm/migrate.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index e000ef77ea87..3d3d91fd61c7 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -345,6 +345,19 @@ struct rmap_walk_arg {
bool map_unused_to_zeropage;
};
+static void set_device_private_ptes(struct mm_struct *mm, unsigned long addr,
+ pte_t *ptep, pte_t pte, unsigned int nr)
+{
+ for (;;) {
+ set_pte_at(mm, addr, ptep, pte);
+ if (--nr == 0)
+ break;
+ addr += PAGE_SIZE;
+ ptep++;
+ pte = pte_next_swp_offset(pte);
+ }
+}
+
/*
* Restore a potential migration pte to a working pte entry
*/
@@ -442,8 +455,7 @@ static bool remove_migration_pte(struct folio *folio,
} else
#endif
{
- if (folio_test_large(rmap_walk_arg->folio) &&
- !is_device_private_page(new)) {
+ if (folio_test_large(rmap_walk_arg->folio)) {
unsigned long end_addr = pmd_addr_end(pvmw.address, vma->vm_end);
unsigned long max_nr = (end_addr - pvmw.address) >> PAGE_SHIFT;
@@ -463,7 +475,11 @@ static bool remove_migration_pte(struct folio *folio,
pvmw.address, rmap_flags);
else
folio_add_file_rmap_ptes(folio, new, nr, vma);
- set_ptes(vma->vm_mm, pvmw.address, pvmw.pte, pte, nr);
+ if (unlikely(is_device_private_page(new)))
+ set_device_private_ptes(vma->vm_mm, pvmw.address,
+ pvmw.pte, pte, nr);
+ else
+ set_ptes(vma->vm_mm, pvmw.address, pvmw.pte, pte, nr);
ptes += nr;
}
--
2.43.0
prev parent reply other threads:[~2026-11-20 3:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 3:29 [PATCH 0/3] mm/migrate: batch PTE restoration for large folios Wandun Chen
2026-11-20 3:29 ` [PATCH 1/3] mm: factor out common softleaf offset PTE batch scanning Wandun Chen
2026-11-20 15:34 ` Lorenzo Stoakes (ARM)
2026-11-20 3:29 ` [PATCH 2/3] mm/migrate: batch PTE restoration in remove_migration_pte() Wandun Chen
2026-11-20 15:22 ` Lorenzo Stoakes (ARM)
2026-11-20 3:29 ` Wandun Chen [this message]
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=20261120032949.2036731-4-chenwandun1@gmail.com \
--to=chenwandun1@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=joshua.hahnjy@gmail.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.