From: "Garg, Shivank" <shivankg@amd.com>
To: "chenwandun1@gmail.com" <chenwandun1@gmail.com>,
"ljs@kernel.org" <ljs@kernel.org>
Cc: "rppt@kernel.org" <rppt@kernel.org>,
"byungchul@sk.com" <byungchul@sk.com>,
"vbabka@kernel.org" <vbabka@kernel.org>,
"ying.huang@linux.alibaba.com" <ying.huang@linux.alibaba.com>,
"matthew.brost@intel.com" <matthew.brost@intel.com>,
"david@kernel.org" <david@kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"surenb@google.com" <surenb@google.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"gourry@gourry.net" <gourry@gourry.net>,
"ziy@nvidia.com" <ziy@nvidia.com>,
"liam@infradead.org" <liam@infradead.org>,
"mhocko@suse.com" <mhocko@suse.com>,
"joshua.hahnjy@gmail.com" <joshua.hahnjy@gmail.com>,
"apopple@nvidia.com" <apopple@nvidia.com>
Subject: Re: [PATCH 2/3] mm/migrate: batch PTE restoration in remove_migration_pte()
Date: Sat, 28 Nov 2026 08:56:28 +0000 [thread overview]
Message-ID: <7a04fb96e91236be7c97fe688d360a02dcab0fbd.camel@amd.com> (raw)
In-Reply-To: <b50cd305-3528-445d-bfa6-e4d7ada43b13@gmail.com>
On Thu, 2026-11-26 at 14:51 +0800, Wandun wrote:
> [You don't often get email from chenwandun1@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On 11/23/26 15:25, Wandun wrote:
> >
> >
> > On 11/20/26 23:22, Lorenzo Stoakes (ARM) wrote:
> > > On Fri, Nov 20, 2026 at 11:29:48AM +0800, Wandun Chen wrote:
> > > > From: Wandun Chen <chenwandun@lixiang.com>
> > > >
> > > > remove_migration_pte() restores PTE-mapped large folios one PTE at a
> > > > time, constructing each new PTE and updating the folio references and
> > > > rmap separately.
> > > >
> > > > Add migration_pte_batch() to find adjacent migration entries with
> > > > consecutive PFNs and matching type and flags.
> > > >
> > > > When a batch covers the whole folio, the rmap helpers already call
> > > > mlock_vma_folio(). Skip the explicit call to avoid double mlock
> > > > accounting.
> > > >
> > > > Device-private PTEs encode PFNs as swap offsets. set_ptes() does not
> > > > handle this encoding when constructing subsequent PTEs, such as on
> > > > arm64 with a 16KB page granule, leaving device-private destinations
> > > > unbatched. The next patch enables batching for these entries by
> > > > advancing their softleaf offsets.
> > > >
> > > > Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> > > > Link: https://lore.kernel.org/lkml/5f9c449e-43b3-4732-9c14-8199418cace0@kernel.org/
> > > > Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
> > > > ---
> > > > mm/internal.h | 6 ++++++
> > > > mm/migrate.c | 35 +++++++++++++++++++++++++++++------
> > > > 2 files changed, 35 insertions(+), 6 deletions(-)
> > > >
> > > > diff --git a/mm/internal.h b/mm/internal.h
> > > > index 9f78c12882cb..e6ecf307d532 100644
> > > > --- a/mm/internal.h
> > > > +++ b/mm/internal.h
> > > > @@ -552,6 +552,12 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
> > > > return __softleaf_pte_batch(start_ptep, max_nr, pte);
> > > > }
> > > >
> > > > +static inline int migration_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
> > > > +{
> > > > + VM_WARN_ON(!softleaf_is_migration(softleaf_from_pte(pte)));
> > > > +
> > > > + return __softleaf_pte_batch(start_ptep, max_nr, pte);
> > > > +}
> > > > #endif /* CONFIG_MMU */
> > > >
> > > > void __acct_reclaim_writeback(pg_data_t *pgdat, struct folio *folio,
> > > > diff --git a/mm/migrate.c b/mm/migrate.c
> > > > index 3c39d309e6bd..e000ef77ea87 100644
> > > > --- a/mm/migrate.c
> > > > +++ b/mm/migrate.c
> > > > @@ -358,6 +358,7 @@ static bool remove_migration_pte(struct folio *folio,
> > > > while (page_vma_mapped_walk(&pvmw)) {
> > > > rmap_t rmap_flags = RMAP_NONE;
> > > > unsigned long idx = 0;
> > > > + int nr = 1;
> > > > softleaf_t entry;
> > > > struct page *new;
> > > > pte_t old_pte;
> > > > @@ -441,17 +442,34 @@ static bool remove_migration_pte(struct folio *folio,
> > > > } else
> > > > #endif
> > > > {
> > > > + if (folio_test_large(rmap_walk_arg->folio) &&
> > > > + !is_device_private_page(new)) {
> > > > + unsigned long end_addr = pmd_addr_end(pvmw.address, vma->vm_end);
> > > > + unsigned long max_nr = (end_addr - pvmw.address) >> PAGE_SHIFT;
> > >
> > > const please
> >
> > Will do in next version.
> > >
> > > > +
> > > > + max_nr = min_t(unsigned long, max_nr,
> > > > + PTRS_PER_PTE - pte_index(pvmw.address));
> > > > +
> > > > + max_nr = min_t(unsigned long, max_nr,
> > > > + folio_nr_pages(rmap_walk_arg->folio) - idx);
> > > > +
> > > > + nr = migration_pte_batch(pvmw.pte, max_nr, old_pte);
> > > > + }
> > > > + if (nr > 1)
> > > > + folio_ref_add(folio, nr - 1);
> > > > +
> > >
> > > Please let's not insert a bunch more open-coded bits in an already way-too-big
> > > function :)
> > >
> > > If you need to add functionality to a function like this, please take the time
> > > to pay down technical debt and refactor it first.
> >
> > Sure, I’ll do some refactoring first in the next version.
>
> I noticed that Shivank’s migration rmap batching series [1] covers much of the
> work I was planning in response to review feedback. That includes the preparatory
> refactoring and the restore-side PTE batching during the mlock discussion.
>
> Given that overlap, I’ll put my series on hold for now and see what follow-up
> work I can take on once Shivank’s series is merged.
>
> I’d also be happy to work with Shivank on restore-side PTE batching if that
> would be helpful.
>
> [1] https://lore.kernel.org/linux-mm/20260813-migrate-rmap-batch-v2-0-3c5424c555c7@amd.com/
>
Thanks Wandun :)
I've split the series: the unmap side is posted as v3 [1], and I'll post
the restore side (remove_migration_ptes() batching) as a separate series.
I'll Cc you, review and testing would be very helpful.
Reviews of [1] are welcome too.
[1] https://lore.kernel.org/linux-mm/20261126-migrate-rmap-batch-v3-0-4112998fb472@amd.com/
Thanks,
Shivank
next prev parent reply other threads:[~2026-11-28 8:56 UTC|newest]
Thread overview: 10+ 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-23 6:57 ` Wandun
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-23 7:25 ` Wandun
2026-11-26 6:51 ` Wandun
2026-11-28 8:56 ` Garg, Shivank [this message]
2026-11-20 3:29 ` [PATCH 3/3] mm/migrate: batch PTE restoration for device-private folios Wandun Chen
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=7a04fb96e91236be7c97fe688d360a02dcab0fbd.camel@amd.com \
--to=shivankg@amd.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=chenwandun1@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox