public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/migrate_device: document folio_get requirement before frozen PMD split
@ 2026-03-09 21:25 Usama Arif
  2026-03-09 22:00 ` David Hildenbrand (Arm)
  2026-03-11 12:45 ` Wei Yang
  0 siblings, 2 replies; 3+ messages in thread
From: Usama Arif @ 2026-03-09 21:25 UTC (permalink / raw)
  To: Andrew Morton, npache, david, ziy, linux-mm
  Cc: matthew.brost, joshua.hahnjy, hannes, rakie.kim, byungchul,
	gourry, ying.huang, apopple, linux-kernel, kernel-team,
	Usama Arif

split_huge_pmd_address() with freeze=true splits a PMD migration entry
into PTE migration entries, consuming one folio reference in the
process.  The folio_get() before it provides this reference.

Add a comment explaining this relationship. The expected folio refcount
at the start of migrate_vma_split_unmapped_folio() is 1.

Suggested-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Nico Pache <npache@redhat.com>
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
v1 -> v2:
- Remove warning if folio refcount !=1 at the start of
  migrate_vma_split_unmapped_folio() (David)
---
 mm/migrate_device.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 78c7acf02461..fbfe5715f635 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -908,6 +908,10 @@ static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate,
 	unsigned long flags;
 	int ret = 0;
 
+	/*
+	 * take a reference, since split_huge_pmd_address() with freeze = true
+	 * drops a reference at the end.
+	 */
 	folio_get(folio);
 	split_huge_pmd_address(migrate->vma, addr, true);
 	ret = folio_split_unmapped(folio, 0);
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mm/migrate_device: document folio_get requirement before frozen PMD split
  2026-03-09 21:25 [PATCH v2] mm/migrate_device: document folio_get requirement before frozen PMD split Usama Arif
@ 2026-03-09 22:00 ` David Hildenbrand (Arm)
  2026-03-11 12:45 ` Wei Yang
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-03-09 22:00 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, npache, ziy, linux-mm
  Cc: matthew.brost, joshua.hahnjy, hannes, rakie.kim, byungchul,
	gourry, ying.huang, apopple, linux-kernel, kernel-team

On 3/9/26 22:25, Usama Arif wrote:
> split_huge_pmd_address() with freeze=true splits a PMD migration entry
> into PTE migration entries, consuming one folio reference in the
> process.  The folio_get() before it provides this reference.
> 
> Add a comment explaining this relationship. The expected folio refcount
> at the start of migrate_vma_split_unmapped_folio() is 1.
> 
> Suggested-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Nico Pache <npache@redhat.com>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
> v1 -> v2:
> - Remove warning if folio refcount !=1 at the start of
>   migrate_vma_split_unmapped_folio() (David)
> ---
>  mm/migrate_device.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 78c7acf02461..fbfe5715f635 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -908,6 +908,10 @@ static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate,
>  	unsigned long flags;
>  	int ret = 0;
>  
> +	/*
> +	 * take a reference, since split_huge_pmd_address() with freeze = true
> +	 * drops a reference at the end.
> +	 */
>  	folio_get(folio);
>  	split_huge_pmd_address(migrate->vma, addr, true);
>  	ret = folio_split_unmapped(folio, 0);

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mm/migrate_device: document folio_get requirement before frozen PMD split
  2026-03-09 21:25 [PATCH v2] mm/migrate_device: document folio_get requirement before frozen PMD split Usama Arif
  2026-03-09 22:00 ` David Hildenbrand (Arm)
@ 2026-03-11 12:45 ` Wei Yang
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Yang @ 2026-03-11 12:45 UTC (permalink / raw)
  To: Usama Arif
  Cc: Andrew Morton, npache, david, ziy, linux-mm, matthew.brost,
	joshua.hahnjy, hannes, rakie.kim, byungchul, gourry, ying.huang,
	apopple, linux-kernel, kernel-team

On Mon, Mar 09, 2026 at 02:25:02PM -0700, Usama Arif wrote:
>split_huge_pmd_address() with freeze=true splits a PMD migration entry
>into PTE migration entries, consuming one folio reference in the
>process.  The folio_get() before it provides this reference.
>
>Add a comment explaining this relationship. The expected folio refcount
>at the start of migrate_vma_split_unmapped_folio() is 1.
>
>Suggested-by: Zi Yan <ziy@nvidia.com>
>Reviewed-by: Zi Yan <ziy@nvidia.com>
>Reviewed-by: Nico Pache <npache@redhat.com>
>Signed-off-by: Usama Arif <usama.arif@linux.dev>

Reviewed-by: Wei Yang <richard.weiyang@gmail.com>

Another thing come up my mind.

>---
>v1 -> v2:
>- Remove warning if folio refcount !=1 at the start of
>  migrate_vma_split_unmapped_folio() (David)
>---
> mm/migrate_device.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
>diff --git a/mm/migrate_device.c b/mm/migrate_device.c
>index 78c7acf02461..fbfe5715f635 100644
>--- a/mm/migrate_device.c
>+++ b/mm/migrate_device.c
>@@ -908,6 +908,10 @@ static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate,
> 	unsigned long flags;
> 	int ret = 0;
> 
>+	/*
>+	 * take a reference, since split_huge_pmd_address() with freeze = true
>+	 * drops a reference at the end.
>+	 */
> 	folio_get(folio);
> 	split_huge_pmd_address(migrate->vma, addr, true);
> 	ret = folio_split_unmapped(folio, 0);

This makes me think why we need an extra refcount, while other user of
split_huge_pmd_locked(@freeze = true) not.

The put_page() when @freeze = true in __split_huge_pmd_locked() is to balance
refcount for the mapping count change.  Since after freeze, the folio is
removed from one pmd mapping.

So we need an extra refcount here, as this folio is not mapped before split as
the function name indicated.

If my analysis above is correct, I am curious about the put_page() in
__split_huge_pmd_locked() now.

Currently we always drop refcount if @freeze = true. But when
pmd_is_migration_entry(), we already unmap it and drop one refcount in
set_pmd_migration_entry(). Would it be a problem to put_page() when
pmd_is_migration_entry()?

-- 
Wei Yang
Help you, Help me


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-11 12:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 21:25 [PATCH v2] mm/migrate_device: document folio_get requirement before frozen PMD split Usama Arif
2026-03-09 22:00 ` David Hildenbrand (Arm)
2026-03-11 12:45 ` Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox