Skip to contentSkip to conversation

powerpc/THP: Wait for all hash_page calls to finish before invalidating HPTE entries

PATCH In review Aneesh Kumar K.V 3 participants 5 messages Jun 19, 2013 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/THP: Wait for all hash_page calls to finish before invalidating HPTE entries

From: "Aneesh Kumar K.V" <[email protected]>

When we collapse normal pages to hugepage, we first clear the pmd, then invalidate all the PTE entries. The assumption here is that any low level page fault will see pmd as none and take the slow path that will wait on mmap_sem. But we could very well be in a hash_page with local ptep pointer value. Such a hash page can result in adding new HPTE entries for normal subpages/small page. That means we could be modifying the page content as we copy them to a huge page. Fix this by waiting on hash_page to finish after marking the pmd none and bfore invalidating HPTE entries. We use the heavy kick_all_cpus_sync(). This should be ok as we do this in the background khugepaged thread and not in application context. But we block page fault handling for this time. Also if we find collapse slow we can ideally increase the scan rate.

---
 arch/powerpc/mm/pgtable_64.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/powerpc/mm/pgtable_64.c +8 -0
index bbecac4..4bb44c3 100644
@@ -543,6 +543,14 @@ pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
 		pmd = *pmdp;
 		pmd_clear(pmdp);
 		/*
+		 * Wait for all pending hash_page to finish
+		 * We can do this by waiting for a context switch to happen on
+		 * the cpus. Any new hash_page after this will see pmd none
+		 * and fallback to code that takes mmap_sem and hence will block
+		 * for collapse to finish.
+		 */
+		kick_all_cpus_sync();
+		/*
 		 * Now invalidate the hpte entries in the range
 		 * covered by pmd. This make sure we take a
 		 * fault and will find the pmd as none, which will
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 12 lines · Aneesh Kumar K.V

From: "Aneesh Kumar K.V" <[email protected]>

When we collapse normal pages to hugepage, we first clear the pmd, then invalidate all the PTE entries. The assumption here is that any low level page fault will see pmd as none and take the slow path that will wait on mmap_sem. But we could very well be in a hash_page with local ptep pointer value. Such a hash page can result in adding new HPTE entries for normal subpages/small page. That means we could be modifying the page content as we copy them to a huge page. Fix this by waiting on hash_page to finish after marking the pmd none and bfore invalidating HPTE entries. We use the heavy kick_all_cpus_sync(). This should be ok as we do this in the background khugepaged thread and not in application context. But we block page fault handling for this time. Also if we find collapse slow we can ideally increase the scan rate.

80 columns here

Quoted 12 lines
---
 arch/powerpc/mm/pgtable_64.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/powerpc/mm/pgtable_64.c +0 -0
index bbecac4..4bb44c3 100644
@@ -543,6 +543,14 @@ pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
 		pmd = *pmdp;

arch/powerpc/mm/pgtable_64.c pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address, · line 553

Quoted 10 lines
arch/powerpc/mm/pgtable_64.c +8 -0
 		pmd_clear(pmdp);
 		/*
+		 * Wait for all pending hash_page to finish
+		 * We can do this by waiting for a context switch to happen on
+		 * the cpus. Any new hash_page after this will see pmd none
+		 * and fallback to code that takes mmap_sem and hence will block
+		 * for collapse to finish.
+		 */
+		kick_all_cpus_sync();
+		/*

This doesn't apply on mainline... I assume it's needs your TPH patches?

Also, dumb question. Is this a bug we're fixing or just an optimisation?

Mikey

Quoted 11 lines
arch/powerpc/mm/pgtable_64.c +0 -0
 		 * Now invalidate the hpte entries in the range
 		 * covered by pmd. This make sure we take a
 		 * fault and will find the pmd as none, which will
Signature · 6 lines
1.8.1.2

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
#2 lore raw
Quoted 34 lines · Michael Neuling
Quoted 12 lines · Aneesh Kumar K.V

From: "Aneesh Kumar K.V" <[email protected]>

When we collapse normal pages to hugepage, we first clear the pmd, then invalidate all the PTE entries. The assumption here is that any low level page fault will see pmd as none and take the slow path that will wait on mmap_sem. But we could very well be in a hash_page with local ptep pointer value. Such a hash page can result in adding new HPTE entries for normal subpages/small page. That means we could be modifying the page content as we copy them to a huge page. Fix this by waiting on hash_page to finish after marking the pmd none and bfore invalidating HPTE entries. We use the heavy kick_all_cpus_sync(). This should be ok as we do this in the background khugepaged thread and not in application context. But we block page fault handling for this time. Also if we find collapse slow we can ideally increase the scan rate.

80 columns here

Quoted 17 lines
---
 arch/powerpc/mm/pgtable_64.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/powerpc/mm/pgtable_64.c +3 -0
index bbecac4..4bb44c3 100644
@@ -543,6 +543,14 @@ pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
 		pmd = *pmdp;
 		pmd_clear(pmdp);
 		/*
+		 * Wait for all pending hash_page to finish
+		 * We can do this by waiting for a context switch to happen on
+		 * the cpus. Any new hash_page after this will see pmd none
Quoted 8 lines

arch/powerpc/mm/pgtable_64.c pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address, · line 553

Quoted 5 lines
arch/powerpc/mm/pgtable_64.c +5 -0
+		 * and fallback to code that takes mmap_sem and hence will block
+		 * for collapse to finish.
+		 */
+		kick_all_cpus_sync();
+		/*

This doesn't apply on mainline... I assume it's needs your TPH patches?

yes, They are on top V10 THP series

Quoted 2 lines

Also, dumb question. Is this a bug we're fixing or just an optimisation?

This is a bug fix. The details can be found at

http://article.gmane.org/gmane.linux.ports.ppc.embedded/60266

-aneesh

#3 lore raw
Quoted 48 lines · Aneesh Kumar K.V
Quoted 37 lines · Michael Neuling
Quoted 12 lines · Aneesh Kumar K.V

From: "Aneesh Kumar K.V" <[email protected]>

When we collapse normal pages to hugepage, we first clear the pmd, then invalidate all the PTE entries. The assumption here is that any low level page fault will see pmd as none and take the slow path that will wait on mmap_sem. But we could very well be in a hash_page with local ptep pointer value. Such a hash page can result in adding new HPTE entries for normal subpages/small page. That means we could be modifying the page content as we copy them to a huge page. Fix this by waiting on hash_page to finish after marking the pmd none and bfore invalidating HPTE entries. We use the heavy kick_all_cpus_sync(). This should be ok as we do this in the background khugepaged thread and not in application context. But we block page fault handling for this time. Also if we find collapse slow we can ideally increase the scan rate.

80 columns here

Quoted 17 lines
---
 arch/powerpc/mm/pgtable_64.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/powerpc/mm/pgtable_64.c +3 -0
index bbecac4..4bb44c3 100644
@@ -543,6 +543,14 @@ pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
 		pmd = *pmdp;
 		pmd_clear(pmdp);
 		/*
+		 * Wait for all pending hash_page to finish
+		 * We can do this by waiting for a context switch to happen on
+		 * the cpus. Any new hash_page after this will see pmd none
Quoted 8 lines

arch/powerpc/mm/pgtable_64.c pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address, · line 553

Quoted 5 lines
arch/powerpc/mm/pgtable_64.c +5 -0
+		 * and fallback to code that takes mmap_sem and hence will block
+		 * for collapse to finish.
+		 */
+		kick_all_cpus_sync();
+		/*

This doesn't apply on mainline... I assume it's needs your TPH patches?

Quoted 6 lines

yes, They are on top V10 THP series

Quoted 2 lines

Also, dumb question. Is this a bug we're fixing or just an optimisation?

This is a bug fix. The details can be found at

Can you make this more obvious in the changelog (as well as making it 80 col). I don't see 'bug' mentioned anywhere. 'Fix' is mentioned somewhere in the middle of the changelog.

Quoted 2 lines

http://article.gmane.org/gmane.linux.ports.ppc.embedded/60266

OK, but V10 THP is not in yet, right? So why not roll it into that series rather than pushing broken stuff and fixing it?

Mikey

#4 lore raw
Quoted 11 lines · Michael Neuling
Quoted 1 line

This is a bug fix. The details can be found at

Can you make this more obvious in the changelog (as well as making it 80 col). I don't see 'bug' mentioned anywhere. 'Fix' is mentioned somewhere in the middle of the changelog.

Quoted 2 lines

http://article.gmane.org/gmane.linux.ports.ppc.embedded/60266

OK, but V10 THP is not in yet, right? So why not roll it into that series rather than pushing broken stuff and fixing it?

Right, this is expected. This fix is a result of me asking him to do it that way on ST and should eventually be folded in the series (or re-ordered to be in there before the patch that enables THP).

Cheers,
Ben.