Skip to contentSkip to conversation

powerpc/mm: THP page cache support

RFC PATCH In review Aneesh Kumar K.V 3 participants 4 messages Sep 22, 2016 – Sep 27, 2016

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 powerpc/mm: THP page cache support

Update arch hook in the generic THP page cache code, that will deposit and withdarw preallocated page table. Archs like ppc64 use this preallocated table to store the hash pte slot information.

This is an RFC patch and I am sharing this early to get feedback on the approach taken. I have used stress-ng mmap-file operation and that resulted in some thp_file_mmap as show below.

[/mnt/stress]$ grep thp_file /proc/vmstat
thp_file_alloc 25403
thp_file_mapped 16967
[/mnt/stress]$

I did observe wrong nr_ptes count once. I need to recreate the problem again.

---
 arch/powerpc/include/asm/book3s/64/pgtable.h |  3 ++
 include/asm-generic/pgtable.h                |  8 +++-
 mm/Kconfig                                   |  6 +--
 mm/huge_memory.c                             | 19 +++++++++-
 mm/khugepaged.c                              | 21 ++++++++++-
 mm/memory.c                                  | 56 +++++++++++++++++++++++-----
 6 files changed, 93 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -0
index 263bf39ced40..1f45b06ce78e 100644
@@ -1017,6 +1017,9 @@ static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
 	 */
 	return true;
 }
+
+#define arch_needs_pgtable_deposit() (true)
+
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
include/asm-generic/pgtable.h +7 -1
index d4458b6dbfb4..0d1e400e82a2 100644
@@ -660,11 +660,17 @@ static inline int pmd_move_must_withdraw(spinlock_t *new_pmd_ptl,
 	/*
 	 * With split pmd lock we also need to move preallocated
 	 * PTE page table if new_pmd is on different PMD page table.
+	 *
+	 * We also don't deposit and withdraw tables for file pages.
 	 */
-	return new_pmd_ptl != old_pmd_ptl;
+	return (new_pmd_ptl != old_pmd_ptl) && vma_is_anonymous(vma);
 }
 #endif
 
+#ifndef arch_needs_pgtable_deposit
+#define arch_needs_pgtable_deposit() (false)
+#endif
+
 /*
  * This function is meant to be used by sites walking pagetables with
  * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
mm/Kconfig +1 -5
index be0ee11fa0d9..0a279d399722 100644
@@ -447,13 +447,9 @@ choice
 	  benefit.
 endchoice
 
-#
-# We don't deposit page tables on file THP mapping,
-# but Power makes use of them to address MMU quirk.
-#
 config	TRANSPARENT_HUGE_PAGECACHE
 	def_bool y
-	depends on TRANSPARENT_HUGEPAGE && !PPC
+	depends on TRANSPARENT_HUGEPAGE
 
 #
 # UP and nommu archs use km based percpu allocator
mm/huge_memory.c +17 -2
index a6abd76baa72..37176f455d16 100644
@@ -1320,6 +1320,14 @@ out_unlocked:
 	return ret;
 }
 
+void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd)
+{
+	pgtable_t pgtable;
+	pgtable = pgtable_trans_huge_withdraw(mm, pmd);
+	pte_free(mm, pgtable);
+	atomic_long_dec(&mm->nr_ptes);
+}
+
 int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 		 pmd_t *pmd, unsigned long addr)
 {
@@ -1359,6 +1367,8 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 			atomic_long_dec(&tlb->mm->nr_ptes);
 			add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR);
 		} else {
+			if (arch_needs_pgtable_deposit())
+				zap_deposited_table(tlb->mm, pmd);
 			add_mm_counter(tlb->mm, MM_FILEPAGES, -HPAGE_PMD_NR);
 		}
 		spin_unlock(ptl);
@@ -1401,8 +1411,7 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
 		pmd = pmdp_huge_get_and_clear(mm, old_addr, old_pmd);
 		VM_BUG_ON(!pmd_none(*new_pmd));
 
-		if (pmd_move_must_withdraw(new_ptl, old_ptl) &&
-				vma_is_anonymous(vma)) {
+		if (pmd_move_must_withdraw(new_ptl, old_ptl)) {
 			pgtable_t pgtable;
 			pgtable = pgtable_trans_huge_withdraw(mm, old_pmd);
 			pgtable_trans_huge_deposit(mm, new_pmd, pgtable);
@@ -1525,6 +1534,12 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
 
 	if (!vma_is_anonymous(vma)) {
 		_pmd = pmdp_huge_clear_flush_notify(vma, haddr, pmd);
+		/*
+		 * We are going to unmap this huge page. So
+		 * just go ahead and zap it
+		 */
+		if (arch_needs_pgtable_deposit())
+			zap_deposited_table(mm, pmd);
 		if (is_huge_zero_pmd(_pmd))
 			put_huge_zero_page();
 		if (vma_is_dax(vma))
mm/khugepaged.c +19 -2
index 728d7790dc2d..9fb7b275cb63 100644
@@ -1240,6 +1240,7 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff)
 	struct vm_area_struct *vma;
 	unsigned long addr;
 	pmd_t *pmd, _pmd;
+	bool deposited = false;
 
 	i_mmap_lock_write(mapping);
 	vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
@@ -1264,10 +1265,26 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff)
 			spinlock_t *ptl = pmd_lock(vma->vm_mm, pmd);
 			/* assume page table is clear */
 			_pmd = pmdp_collapse_flush(vma, addr, pmd);
+			/*
+			 * now deposit the pgtable for arch that need it
+			 * otherwise free it.
+			 */
+			if (arch_needs_pgtable_deposit()) {
+				/*
+				 * The deposit should be visibile only after
+				 * collapse is seen by others.
+				 */
+				smp_wmb();
+				pgtable_trans_huge_deposit(vma->vm_mm, pmd,
+							   pmd_pgtable(_pmd));
+				deposited = true;
+			}
 			spin_unlock(ptl);
 			up_write(&vma->vm_mm->mmap_sem);
-			atomic_long_dec(&vma->vm_mm->nr_ptes);
-			pte_free(vma->vm_mm, pmd_pgtable(_pmd));
+			if (!deposited) {
+				atomic_long_dec(&vma->vm_mm->nr_ptes);
+				pte_free(vma->vm_mm, pmd_pgtable(_pmd));
+			}
 		}
 	}
 	i_mmap_unlock_write(mapping);
mm/memory.c +46 -10

107 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Aneesh Kumar K.V

Update arch hook in the generic THP page cache code, that will deposit and withdarw preallocated page table. Archs like ppc64 use this preallocated table to store the hash pte slot information.

This is an RFC patch and I am sharing this early to get feedback on the approach taken. I have used stress-ng mmap-file operation and that resulted in some thp_file_mmap as show below.

Quoted 7 lines

[/mnt/stress]$ grep thp_file /proc/vmstat
thp_file_alloc 25403
thp_file_mapped 16967
[/mnt/stress]$

I did observe wrong nr_ptes count once. I need to recreate the problem again.

I don't see anything that could cause that.

The patch looks good to me (apart from nr_ptes issue). Few minor nitpicks below.

Quoted 71 lines
---
 arch/powerpc/include/asm/book3s/64/pgtable.h |  3 ++
 include/asm-generic/pgtable.h                |  8 +++-
 mm/Kconfig                                   |  6 +--
 mm/huge_memory.c                             | 19 +++++++++-
 mm/khugepaged.c                              | 21 ++++++++++-
 mm/memory.c                                  | 56 +++++++++++++++++++++++-----
 6 files changed, 93 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -0
index 263bf39ced40..1f45b06ce78e 100644
@@ -1017,6 +1017,9 @@ static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
 	 */
 	return true;
 }
+
+#define arch_needs_pgtable_deposit() (true)
+
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
include/asm-generic/pgtable.h +7 -1
index d4458b6dbfb4..0d1e400e82a2 100644
@@ -660,11 +660,17 @@ static inline int pmd_move_must_withdraw(spinlock_t *new_pmd_ptl,
 	/*
 	 * With split pmd lock we also need to move preallocated
 	 * PTE page table if new_pmd is on different PMD page table.
+	 *
+	 * We also don't deposit and withdraw tables for file pages.
 	 */
-	return new_pmd_ptl != old_pmd_ptl;
+	return (new_pmd_ptl != old_pmd_ptl) && vma_is_anonymous(vma);
 }
 #endif
 
+#ifndef arch_needs_pgtable_deposit
+#define arch_needs_pgtable_deposit() (false)
+#endif
+
 /*
  * This function is meant to be used by sites walking pagetables with
  * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
mm/Kconfig +1 -5
index be0ee11fa0d9..0a279d399722 100644
@@ -447,13 +447,9 @@ choice
 	  benefit.
 endchoice
 
-#
-# We don't deposit page tables on file THP mapping,
-# but Power makes use of them to address MMU quirk.
-#
 config	TRANSPARENT_HUGE_PAGECACHE
 	def_bool y
-	depends on TRANSPARENT_HUGEPAGE && !PPC
+	depends on TRANSPARENT_HUGEPAGE
 
 #
 # UP and nommu archs use km based percpu allocator
mm/huge_memory.c +0 -0
index a6abd76baa72..37176f455d16 100644

mm/huge_memory.c out_unlocked: · line 1323

Quoted 4 lines
mm/huge_memory.c +1 -0
@@ -1320,6 +1320,14 @@ out_unlocked:
 	return ret;
 }
 
+void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd)

static?

Quoted 11 lines
mm/huge_memory.c +7 -0
+{
+	pgtable_t pgtable;
+	pgtable = pgtable_trans_huge_withdraw(mm, pmd);
+	pte_free(mm, pgtable);
+	atomic_long_dec(&mm->nr_ptes);
+}
+
 int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 		 pmd_t *pmd, unsigned long addr)
 {

mm/huge_memory.c int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, · line 1370

Quoted 4 lines
mm/huge_memory.c +1 -0
@@ -1359,6 +1367,8 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 			atomic_long_dec(&tlb->mm->nr_ptes);
 			add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR);
 		} else {
+			if (arch_needs_pgtable_deposit())

Just hide the arch_needs_pgtable_deposit() check in zap_deposited_table().

Quoted 4 lines
mm/huge_memory.c +1 -0
+				zap_deposited_table(tlb->mm, pmd);
 			add_mm_counter(tlb->mm, MM_FILEPAGES, -HPAGE_PMD_NR);
 		}
 		spin_unlock(ptl);
Signature · 7 lines
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 14 lines · Kirill A. Shutemov
Quoted 13 lines · Aneesh Kumar K.V

Update arch hook in the generic THP page cache code, that will deposit and withdarw preallocated page table. Archs like ppc64 use this preallocated table to store the hash pte slot information.

This is an RFC patch and I am sharing this early to get feedback on the approach taken. I have used stress-ng mmap-file operation and that resulted in some thp_file_mmap as show below.

[/mnt/stress]$ grep thp_file /proc/vmstat
thp_file_alloc 25403
thp_file_mapped 16967
[/mnt/stress]$

Quoted 5 lines
Quoted 2 lines

I did observe wrong nr_ptes count once. I need to recreate the problem again.

I don't see anything that could cause that.

I still need to debug this.

Quoted 77 lines

The patch looks good to me (apart from nr_ptes issue). Few minor nitpicks below.

Quoted 74 lines
---
 arch/powerpc/include/asm/book3s/64/pgtable.h |  3 ++
 include/asm-generic/pgtable.h                |  8 +++-
 mm/Kconfig                                   |  6 +--
 mm/huge_memory.c                             | 19 +++++++++-
 mm/khugepaged.c                              | 21 ++++++++++-
 mm/memory.c                                  | 56 +++++++++++++++++++++++-----
 6 files changed, 93 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -0
index 263bf39ced40..1f45b06ce78e 100644
@@ -1017,6 +1017,9 @@ static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
 	 */
 	return true;
 }
+
+#define arch_needs_pgtable_deposit() (true)
+
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
include/asm-generic/pgtable.h +7 -1
index d4458b6dbfb4..0d1e400e82a2 100644
@@ -660,11 +660,17 @@ static inline int pmd_move_must_withdraw(spinlock_t *new_pmd_ptl,
 	/*
 	 * With split pmd lock we also need to move preallocated
 	 * PTE page table if new_pmd is on different PMD page table.
+	 *
+	 * We also don't deposit and withdraw tables for file pages.
 	 */
-	return new_pmd_ptl != old_pmd_ptl;
+	return (new_pmd_ptl != old_pmd_ptl) && vma_is_anonymous(vma);
 }
 #endif
 
+#ifndef arch_needs_pgtable_deposit
+#define arch_needs_pgtable_deposit() (false)
+#endif
+
 /*
  * This function is meant to be used by sites walking pagetables with
  * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
mm/Kconfig +1 -5
index be0ee11fa0d9..0a279d399722 100644
@@ -447,13 +447,9 @@ choice
 	  benefit.
 endchoice
 
-#
-# We don't deposit page tables on file THP mapping,
-# but Power makes use of them to address MMU quirk.
-#
 config	TRANSPARENT_HUGE_PAGECACHE
 	def_bool y
-	depends on TRANSPARENT_HUGEPAGE && !PPC
+	depends on TRANSPARENT_HUGEPAGE
 
 #
 # UP and nommu archs use km based percpu allocator
mm/huge_memory.c +0 -0
index a6abd76baa72..37176f455d16 100644
@@ -1320,6 +1320,14 @@ out_unlocked:
 	return ret;
 }
 
Quoted 3 lines

mm/huge_memory.c out_unlocked: · line 1323

Quoted 1 line
mm/huge_memory.c +1 -0
+void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd)

static?

Ok I will fix that.

Quoted 10 lines
Quoted 10 lines
mm/huge_memory.c +7 -0
+{
+	pgtable_t pgtable;
+	pgtable = pgtable_trans_huge_withdraw(mm, pmd);
+	pte_free(mm, pgtable);
+	atomic_long_dec(&mm->nr_ptes);
+}
+
 int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 		 pmd_t *pmd, unsigned long addr)
Quoted 8 lines

mm/huge_memory.c int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, · line 1370

Quoted 6 lines
mm/huge_memory.c +1 -0
 {
@@ -1359,6 +1367,8 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 			atomic_long_dec(&tlb->mm->nr_ptes);
 			add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR);
 		} else {
+			if (arch_needs_pgtable_deposit())

Just hide the arch_needs_pgtable_deposit() check in zap_deposited_table().

ok.

Quoted 5 lines

mm/huge_memory.c int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, · line 1374

Quoted 5 lines
mm/huge_memory.c +1 -0
+				zap_deposited_table(tlb->mm, pmd);
 			add_mm_counter(tlb->mm, MM_FILEPAGES, -HPAGE_PMD_NR);
 		}
 		spin_unlock(ptl);

-aneesh