mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Garg, Shivank" <shivankg@amd.com>
To: "rppt@kernel.org" <rppt@kernel.org>,
	"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>,
	"gourry@gourry.net" <gourry@gourry.net>,
	"ziy@nvidia.com" <ziy@nvidia.com>,
	"jannh@google.com" <jannh@google.com>,
	"liam@infradead.org" <liam@infradead.org>,
	"joannelkoong@gmail.com" <joannelkoong@gmail.com>,
	"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>
Cc: "Rao, Bharata Bhasker" <bharata@amd.com>,
	"kinseyho@google.com" <kinseyho@google.com>,
	"dev.jain@arm.com" <dev.jain@arm.com>,
	"linmiaohe@huawei.com" <linmiaohe@huawei.com>,
	"kmanaouil.dev@gmail.com" <kmanaouil.dev@gmail.com>,
	"fvdl@google.com" <fvdl@google.com>,
	"usama.arif@linux.dev" <usama.arif@linux.dev>,
	"weixugc@google.com" <weixugc@google.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"rientjes@google.com" <rientjes@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/3] mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one()
Date: Wed, 2 Dec 2026 14:17:09 +0000	[thread overview]
Message-ID: <594ab821cc50fa7d54010c2c9f8e447b3d9a23a4.camel@amd.com> (raw)
In-Reply-To: <d9be1276-f380-4413-a27c-076072d2b2f7@kernel.org>

On Tue, 2026-12-01 at 12:03 +0100, David Hildenbrand (Arm) wrote:
> On 11/26/26 10:53, Shivank Garg wrote:
> > try_to_migrate_one() interleaves hugetlb special handling through the
> > regular PTE/PMD migration path with folio_test_hugetlb() checks
> > scattered across the walk. Simplify this by moving hugetlb handling
> > into its own rmap_one callback, try_to_migrate_hugetlb_one().
> > 
> > Few minor changes:
> > - Since hugetlb uses separate counters, update_hiwater_rss() is not
> > needed for hugetlb path. Also, use huge_pte_dirty instead of pte_dirty
> > - No PVMW_SYNC flag is needed for hugetlb
> > - hugetlb folio has single mapping per VMA, so no loop is needed.
> > - Convert VM_BUG_ON to VM_WARN_ON_ONCE and not use irrelevant WARN check.
> > 
> > Signed-off-by: Shivank Garg <shivankg@amd.com>
> > ---
> >  mm/rmap.c | 251 +++++++++++++++++++++++++++++++++++---------------------------
> >  1 file changed, 144 insertions(+), 107 deletions(-)
> > 
> > diff --git a/mm/rmap.c b/mm/rmap.c
> > index 304581856d67..fe87df06fa06 100644
> > --- a/mm/rmap.c
> > +++ b/mm/rmap.c
> > @@ -2553,6 +2553,138 @@ static pte_t make_migration_pte(struct page *page, pte_t pteval,
> >  	return swp_pte;
> >  }
> >  
> > +/*
> > + * Replace the hugetlb page table mapping for folio with migration entries.
> > + *
> > + * @arg: enum ttu_flags will be passed to this argument.
> > + */
> > +static bool try_to_migrate_hugetlb_one(struct folio *folio,
> > +		struct vm_area_struct *vma, unsigned long address, void *arg)
> > +{
> > +	const unsigned long hsz = huge_page_size(hstate_vma(vma));
> > +	DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0);
> > +	enum ttu_flags flags = (enum ttu_flags)(long)arg;
> > +	bool anon_exclusive, writable, ret = true;
> > +	bool anon = folio_test_anon(folio);
> > +	struct mm_struct *mm = vma->vm_mm;
> > +	struct mmu_notifier_range range;
> > +	unsigned long pfn;
> > +	struct page *page;
> > +	pte_t pteval;
> > +
> > +	range.end = vma_address_end(&pvmw);
> > +	mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma->vm_mm,
> > +				address, range.end);
> > +	/* If sharing is possible, start and end will be adjusted accordingly. */
> > +	adjust_range_if_pmd_sharing_possible(vma, &range.start, &range.end);
> > +	mmu_notifier_invalidate_range_start(&range);
> > +
> > +	/* There is only a single mapping in a VMA. */
> > +	if (!page_vma_mapped_walk(&pvmw))
> > +		goto range_end;
> > +
> > +	address = pvmw.address;
> > +	pteval = huge_ptep_get(mm, address, pvmw.pte);
> > +	if (likely(pte_present(pteval)))
> > +		pfn = pte_pfn(pteval);
> > +	else
> > +		pfn = softleaf_to_pfn(softleaf_from_pte(pteval));
> 
> Do we have such a case for hugetlb?
> 
> 
> > +
> > +	page = folio_page(folio, pfn - folio_pfn(folio));
> 
> How can we ever not be at the head page.
> 
> 
> Likely, most of this sould be very similar to what we have in
> try_to_unmap_poisoned_hugetlb_one().
> 

Agreed. So I can directly use folio_page(folio, 0) or &folio->page.

try_to_unmap_poisoned_hugetlb_one() covers both case with this
	VM_WARN_ON_ONCE(!pte_present(pteval));
	VM_WARN_ON_ONCE(pte_pfn(pteval) != folio_pfn(folio));
> 
> Which raises the question if we can unify some stuff there instead? It's *a lot*
> of code duplication.
> 
> Just need to teach try_to_unmap_poisoned_hugetlb_one() to insert migration
> entries when asked.
> 
> Sounds reasonable?

yes, makes sense. I'll do this in V4.
Thanks for suggestion.

Best regards,
Shivank

  reply	other threads:[~2026-12-02 14:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:53 [PATCH v3 0/3] mm/rmap: batch the unmap of large folios during migration Shivank Garg
2026-11-26  9:53 ` [PATCH v3 1/3] mm/rmap: factor out migration PTE construction Shivank Garg
2026-12-01 10:56   ` David Hildenbrand (Arm)
2026-12-02  2:44   ` Zi Yan
2026-11-26  9:53 ` [PATCH v3 2/3] mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one() Shivank Garg
2026-12-01 11:03   ` David Hildenbrand (Arm)
2026-12-02 14:17     ` Garg, Shivank [this message]
2026-11-26  9:53 ` [PATCH v3 3/3] mm/rmap: batch the unmap of large folios in try_to_migrate_one() Shivank Garg
2026-11-30 20:02 ` [PATCH v3 0/3] mm/rmap: batch the unmap of large folios during migration Ravi Jonnalagadda
2026-12-01  9:46   ` 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=594ab821cc50fa7d54010c2c9f8e447b3d9a23a4.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=joannelkoong@gmail.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=linmiaohe@huawei.com \
    --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=usama.arif@linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®