All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Garg, Shivank" <shivankg@amd.com>
To: "kmanaouil.dev@gmail.com" <kmanaouil.dev@gmail.com>
Cc: "Rao, Bharata Bhasker" <bharata@amd.com>,
	"rppt@kernel.org" <rppt@kernel.org>,
	"weixugc@google.com" <weixugc@google.com>,
	"byungchul@sk.com" <byungchul@sk.com>,
	"rakie.kim@sk.com" <rakie.kim@sk.com>,
	"vbabka@kernel.org" <vbabka@kernel.org>,
	"harry@kernel.org" <harry@kernel.org>,
	"ying.huang@linux.alibaba.com" <ying.huang@linux.alibaba.com>,
	"riel@surriel.com" <riel@surriel.com>,
	"david@kernel.org" <david@kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"matthew.brost@intel.com" <matthew.brost@intel.com>,
	"surenb@google.com" <surenb@google.com>,
	"rientjes@google.com" <rientjes@google.com>,
	"kinseyho@google.com" <kinseyho@google.com>,
	"dev.jain@arm.com" <dev.jain@arm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"gourry@gourry.net" <gourry@gourry.net>,
	"ziy@nvidia.com" <ziy@nvidia.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"jannh@google.com" <jannh@google.com>,
	"liam@infradead.org" <liam@infradead.org>,
	"mhocko@suse.com" <mhocko@suse.com>,
	"ljs@kernel.org" <ljs@kernel.org>,
	"lance.yang@linux.dev" <lance.yang@linux.dev>,
	"joshua.hahnjy@gmail.com" <joshua.hahnjy@gmail.com>,
	"apopple@nvidia.com" <apopple@nvidia.com>,
	"fvdl@google.com" <fvdl@google.com>
Subject: Re: [PATCH v2 3/7] mm/migrate: split remove_migration_pte_hugetlb() out of remove_migration_pte()
Date: Wed, 19 Aug 2026 17:49:13 +0000	[thread overview]
Message-ID: <835e8dc70bf2080ef261c3bb52e13a08481fc638.camel@amd.com> (raw)
In-Reply-To: <20260819112419.n4fkhvbxxfhsyhun@wrangler>

On Wed, 2026-08-19 at 12:24 +0100, Karim Manaouil wrote:
> Hi Shivank,
> 
> On Thu, Aug 13, 2026 at 04:23:14AM +0000, Shivank Garg wrote:
> > remove_migration_pte() interleaves hugetlb handling with the regular
> > folio path. Move it into a dedicated callback selected by
> > remove_migration_ptes(), leaving the generic callback focused on regular
> > folios ahead of PTE batching.
> > 
> > With hugetlb folios routed separately, simplify the PMD mapping check to
> > a one-time warning.
> > 
> > Signed-off-by: Shivank Garg <shivankg@amd.com>
> > ---
> >  mm/migrate.c | 97 +++++++++++++++++++++++++++++++++++++++---------------------
> >  1 file changed, 63 insertions(+), 34 deletions(-)
> > 
> > diff --git a/mm/migrate.c b/mm/migrate.c
> > index a3362cc9ef66..ee1b8a55a2a4 100644
> > --- a/mm/migrate.c
> > +++ b/mm/migrate.c
> > @@ -375,6 +375,57 @@ static pte_t migration_entry_to_pte(struct folio *folio, struct page *new,
> >  	return pte;
> >  }
> >  
> > +/*
> > + * Restore a potential migration pte to a working pte entry for hugetlb folios.
> > + */
> > +#ifdef CONFIG_HUGETLB_PAGE
> > +static bool remove_migration_pte_hugetlb(struct folio *folio,
> > +		struct vm_area_struct *vma, unsigned long addr, void *arg)
> > +{
> > +	struct rmap_walk_arg *rmap_walk_arg = arg;
> > +	DEFINE_FOLIO_VMA_WALK(pvmw, rmap_walk_arg->folio, vma, addr, PVMW_SYNC | PVMW_MIGRATION);
> > +	struct hstate *h = hstate_vma(vma);
> > +	unsigned int shift = huge_page_shift(h);
> > +	unsigned long psize = huge_page_size(h);
> > +	struct page *new = folio_page(folio, 0);
> > +	rmap_t rmap_flags = RMAP_NONE;
> > +	pte_t old_pte, pte;
> > +	softleaf_t entry;
> > +
> > +	/* There is only a single mapping in a VMA. */
> 
> I don't think this comment is necessary. page_vma_mapped_walk() clearly
> explains what happens with HugeTLB entries.
> 
> > +	if (!page_vma_mapped_walk(&pvmw))
> > +		return true;
> > +

I carried this over from try_to_unmap_poisoned_hugetlb_one(), which has asimilar check. Dropping it here while retaining it at the other call site
would seem odd, so I kept it. I have no strong opinion, though.


> > +	old_pte = huge_ptep_get(vma->vm_mm, pvmw.address, pvmw.pte);
> > +	entry = softleaf_from_pte(old_pte);
> > +	folio_get(folio);
> > +	pte = migration_entry_to_pte(folio, new, entry, old_pte, vma,
&rmap_flags);
> > +	pte = arch_make_huge_pte(pte, shift, vma->vm_flags);
> > +	if (folio_test_anon(folio))
> > +		hugetlb_add_anon_rmap(folio, vma, pvmw.address,
rmap_flags);
> > +	else
> > +		hugetlb_add_file_rmap(folio);
> > +	set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte, psize);
> 
> I know nothing in HugeTLB, but can't they be mapped as 4KiB entries? In
> which case we have to use
> 
> 	while (page_vma_mapped_walk(&pvmw)) {
> 		...
> 	}
> 


The code/comment in page_vma_mapped_walk() show that it handles the only
possible mapping and returns not_found() on the next iteration. Therefore,
even if we used a while loop, it would run only once.

> It seems like it's not the case from my little investigation, but
> I'll keep it here just to be sure.



Thanks,
Shivank





  reply	other threads:[~2026-08-19 17:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13  4:23 [PATCH v2 0/7] mm: batch rmap walks during large folio migration Shivank Garg
2026-08-13  4:23 ` [PATCH v2 1/7] mm: factor out generic PTE batch detection from swap_pte_batch() Shivank Garg
2026-08-13  9:57   ` David Hildenbrand (Arm)
2026-08-14  8:00     ` Garg, Shivank
2026-08-16  7:48       ` Garg, Shivank
2026-08-13  4:23 ` [PATCH v2 2/7] mm/migrate: factor out migration PTE construction Shivank Garg
2026-08-13  4:23 ` [PATCH v2 3/7] mm/migrate: split remove_migration_pte_hugetlb() out of remove_migration_pte() Shivank Garg
2026-08-19 11:24   ` Karim Manaouil
2026-08-19 17:49     ` Garg, Shivank [this message]
2026-08-13  4:23 ` [PATCH v2 4/7] mm/migrate: batch the restore-side migration rmap walk Shivank Garg
2026-08-13  4:23 ` [PATCH v2 5/7] mm/rmap: factor out migration PTE construction Shivank Garg
2026-08-13  4:23 ` [PATCH v2 6/7] mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one() Shivank Garg
2026-08-13  4:23 ` [PATCH v2 7/7] mm/rmap: batch the unmap of large folios in try_to_migrate_one() Shivank Garg
2026-08-17  9:14   ` Lance Yang
2026-08-18  8:55     ` Miaohe Lin
2026-08-18  9:20       ` Lance Yang
2026-08-19  9:05         ` Miaohe Lin
2026-08-19  9:42         ` Huang, Ying
2026-08-19  9:57           ` Lance Yang
2026-08-19 10:09           ` Garg, Shivank

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=835e8dc70bf2080ef261c3bb52e13a08481fc638.camel@amd.com \
    --to=shivankg@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=bharata@amd.com \
    --cc=byungchul@sk.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=fvdl@google.com \
    --cc=gourry@gourry.net \
    --cc=harry@kernel.org \
    --cc=jannh@google.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kinseyho@google.com \
    --cc=kmanaouil.dev@gmail.com \
    --cc=lance.yang@linux.dev \
    --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=rakie.kim@sk.com \
    --cc=riel@surriel.com \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --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.