Skip to contentSkip to conversation

mm/migrate_device: document folio_get requirement before frozen PMD split

PATCH Applied Usama Arif 3 participants 3 messages Mar 9 – Mar 11

Subsystems (2)
lore
Share & tools
lore

Usama Arif

author
#0 lore raw

PATCH v2 1/1 mm/migrate_device: document folio_get requirement before frozen PMD split

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.

---
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(+)
mm/migrate_device.c +4 -0
index 78c7acf02461..fbfe5715f635 100644
@@ -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);
Signature · 1 line
2.47.3
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 24 lines · 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.

---
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(+)
mm/migrate_device.c +0 -0
index 78c7acf02461..fbfe5715f635 100644

mm/migrate_device.c static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate, · line 917

Quoted 10 lines
mm/migrate_device.c +4 -0
@@ -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);
Signature · 3 lines
Cheers,

David
Reviewed-by on v2 1/1
#2 lore raw
In reply to Usama Arif
Quoted 11 lines · 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.

Another thing come up my mind.

Quoted 13 lines

---
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(+)
mm/migrate_device.c +0 -0
index 78c7acf02461..fbfe5715f635 100644

mm/migrate_device.c static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate, · line 917

Quoted 10 lines
mm/migrate_device.c +4 -0
@@ -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()?

Signature · 2 lines
Wei Yang
Help you, Help me