Skip to contentSkip to conversation

sparc64: Multi-page size support

PATCH Applied Nitin Gupta 2 participants 5 messages Nov 22, 2016 – Dec 13, 2016 SPARC + UltraSPARC (sparc/sparc64)

v3 of 6 Applied Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 sparc64: Multi-page size support

Add support for using multiple hugepage sizes simultaneously on mainline. Currently, support for 256M has been added which can be used along with 8M pages.

Page tables are set like this (e.g. for 256M page):

    VA + (8M * x) -> PA + (8M * x) (sz bit = 256M) where x in [0, 31]

and TSB is set similarly:

    VA + (4M * x) -> PA + (4M * x) (sz bit = 256M) where x in [0, 63]

- Testing

Tested on Sonoma (which supports 256M pages) by running stream benchmark instances in parallel: one instance uses 8M pages and another uses 256M pages, consuming 48G each.

Boot params used:

default_hugepagesz%6M hugepagesz%6M hugepages00 hugepagesz=8M hugepages000

---

Changelog v2 vs v3:
- Remove unused label in tsb.S (David)
- Order local variables from longest to shortest line (David)

Changelog v1 vs v2:
- Fix warning due to unused __flush_huge_tsb_one() when CONFIG_HUGETLB is not defined.

---
 arch/sparc/include/asm/page_64.h     |   3 +-
 arch/sparc/include/asm/pgtable_64.h  |  23 +++--
 arch/sparc/include/asm/tlbflush_64.h |   5 +-
 arch/sparc/kernel/tsb.S              |  21 +----
 arch/sparc/mm/hugetlbpage.c          | 160 +++++++++++++++++++++++++++++++----
 arch/sparc/mm/init_64.c              |  45 +++++++++-
 arch/sparc/mm/tlb.c                  |  17 ++--
 arch/sparc/mm/tsb.c                  |  45 ++++++++--
 8 files changed, 257 insertions(+), 62 deletions(-)
arch/sparc/include/asm/page_64.h +2 -1
index c1263fc..d76f38d 100644
@@ -17,7 +17,7 @@
 
 #define HPAGE_SHIFT		23
 #define REAL_HPAGE_SHIFT	22
-
+#define HPAGE_256MB_SHIFT	28
 #define REAL_HPAGE_SIZE		(_AC(1,UL) << REAL_HPAGE_SHIFT)
 
 #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
@@ -26,6 +26,7 @@
 #define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
 #define REAL_HPAGE_PER_HPAGE	(_AC(1,UL) << (HPAGE_SHIFT - REAL_HPAGE_SHIFT))
+#define HUGE_MAX_HSTATE		2
 #endif
 
 #ifndef __ASSEMBLY__
arch/sparc/include/asm/pgtable_64.h +15 -8
index 1fb317f..96005b0 100644
@@ -375,7 +375,10 @@ static inline pgprot_t pgprot_noncached(pgprot_t prot)
 #define pgprot_noncached pgprot_noncached
 
 #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
-static inline unsigned long __pte_huge_mask(void)
+extern pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
+				struct page *page, int writable);
+#define arch_make_huge_pte arch_make_huge_pte
+static inline unsigned long __pte_default_huge_mask(void)
 {
 	unsigned long mask;
 
@@ -395,12 +398,14 @@ static inline unsigned long __pte_huge_mask(void)
 
 static inline pte_t pte_mkhuge(pte_t pte)
 {
-	return __pte(pte_val(pte) | _PAGE_PMD_HUGE | __pte_huge_mask());
+	return __pte(pte_val(pte) | __pte_default_huge_mask());
 }
 
-static inline bool is_hugetlb_pte(pte_t pte)
+static inline bool is_default_hugetlb_pte(pte_t pte)
 {
-	return !!(pte_val(pte) & __pte_huge_mask());
+	unsigned long mask = __pte_default_huge_mask();
+
+	return (pte_val(pte) & mask) = mask;
 }
 
 static inline bool is_hugetlb_pmd(pmd_t pmd)
@@ -875,10 +880,12 @@ static inline unsigned long pud_pfn(pud_t pud)
 
 /* Actual page table PTE updates.  */
 void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
-		   pte_t *ptep, pte_t orig, int fullmm);
+		   pte_t *ptep, pte_t orig, int fullmm,
+		   unsigned int hugepage_shift);
 
 static void maybe_tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
-				pte_t *ptep, pte_t orig, int fullmm)
+				pte_t *ptep, pte_t orig, int fullmm,
+				unsigned int hugepage_shift)
 {
 	/* It is more efficient to let flush_tlb_kernel_range()
 	 * handle init_mm tlb flushes.
@@ -887,7 +894,7 @@ static void maybe_tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
 	 *             and SUN4V pte layout, so this inline test is fine.
 	 */
 	if (likely(mm != &init_mm) && pte_accessible(mm, orig))
-		tlb_batch_add(mm, vaddr, ptep, orig, fullmm);
+		tlb_batch_add(mm, vaddr, ptep, orig, fullmm, hugepage_shift);
 }
 
 #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
@@ -906,7 +913,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
 	pte_t orig = *ptep;
 
 	*ptep = pte;
-	maybe_tlb_batch_add(mm, addr, ptep, orig, fullmm);
+	maybe_tlb_batch_add(mm, addr, ptep, orig, fullmm, PAGE_SHIFT);
 }
 
 #define set_pte_at(mm,addr,ptep,pte)	\
arch/sparc/include/asm/tlbflush_64.h +3 -2
index a8e192e..54be88a 100644
@@ -8,7 +8,7 @@
 #define TLB_BATCH_NR	192
 
 struct tlb_batch {
-	bool huge;
+	unsigned int hugepage_shift;
 	struct mm_struct *mm;
 	unsigned long tlb_nr;
 	unsigned long active;
@@ -17,7 +17,8 @@ struct tlb_batch {
 
 void flush_tsb_kernel_range(unsigned long start, unsigned long end);
 void flush_tsb_user(struct tlb_batch *tb);
-void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr, bool huge);
+void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr,
+			 unsigned int hugepage_shift);
 
 /* TLB flush operations. */
 
arch/sparc/kernel/tsb.S +3 -18
index d568c82..10689cf 100644
@@ -117,26 +117,11 @@ tsb_miss_page_table_walk_sun4v_fastpath:
 	/* Valid PTE is now in %g5.  */
 
 #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
-661:	sethi		%uhi(_PAGE_SZALL_4U), %g7
+	sethi		%uhi(_PAGE_PMD_HUGE), %g7
 	sllx		%g7, 32, %g7
-	.section	.sun4v_2insn_patch, "ax"
-	.word		661b
-	mov		_PAGE_SZALL_4V, %g7
-	nop
-	.previous
-
-	and		%g5, %g7, %g2
-
-661:	sethi		%uhi(_PAGE_SZHUGE_4U), %g7
-	sllx		%g7, 32, %g7
-	.section	.sun4v_2insn_patch, "ax"
-	.word		661b
-	mov		_PAGE_SZHUGE_4V, %g7
-	nop
-	.previous
 
-	cmp		%g2, %g7
-	bne,pt		%xcc, 60f
+	andcc		%g5, %g7, %g0
+	be,pt		%xcc, 60f
 	 nop
 
 	/* It is a huge page, use huge page TSB entry address we
arch/sparc/mm/hugetlbpage.c +144 -16

231 lines not on this page · raw message

arch/sparc/mm/init_64.c +44 -1

57 lines not on this page · raw message

arch/sparc/mm/tlb.c +8 -9
index c56a195..afda3bb 100644
@@ -67,7 +67,7 @@ void arch_leave_lazy_mmu_mode(void)
 }
 
 static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr,
-			      bool exec, bool huge)
+			      bool exec, unsigned int hugepage_shift)
 {
 	struct tlb_batch *tb = &get_cpu_var(tlb_batch);
 	unsigned long nr;
@@ -84,19 +84,19 @@ static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr,
 	}
 
 	if (!tb->active) {
-		flush_tsb_user_page(mm, vaddr, huge);
+		flush_tsb_user_page(mm, vaddr, hugepage_shift);
 		global_flush_tlb_page(mm, vaddr);
 		goto out;
 	}
 
 	if (nr = 0) {
 		tb->mm = mm;
-		tb->huge = huge;
+		tb->hugepage_shift = hugepage_shift;
 	}
 
-	if (tb->huge != huge) {
+	if (tb->hugepage_shift != hugepage_shift) {
 		flush_tlb_pending();
-		tb->huge = huge;
+		tb->hugepage_shift = hugepage_shift;
 		nr = 0;
 	}
 
@@ -110,10 +110,9 @@ static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr,
 }
 
 void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
-		   pte_t *ptep, pte_t orig, int fullmm)
+		   pte_t *ptep, pte_t orig, int fullmm,
+		   unsigned int hugepage_shift)
 {
-	bool huge = is_hugetlb_pte(orig);
-
 	if (tlb_type != hypervisor &&
 	    pte_dirty(orig)) {
 		unsigned long paddr, pfn = pte_pfn(orig);
@@ -139,7 +138,7 @@ void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
 
 no_cache_flush:
 	if (!fullmm)
-		tlb_batch_add_one(mm, vaddr, pte_exec(orig), huge);
+		tlb_batch_add_one(mm, vaddr, pte_exec(orig), hugepage_shift);
 }
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
arch/sparc/mm/tsb.c +38 -7

87 lines not on this page · raw message

Signature · 1 line
2.9.2
maintainer Applied
#1 lore raw

From: Nitin Gupta <[email protected]>
Date: Tue, 22 Nov 2016 14:09:28 -0800

Quoted 16 lines

Add support for using multiple hugepage sizes simultaneously on mainline. Currently, support for 256M has been added which can be used along with 8M pages.

Page tables are set like this (e.g. for 256M page):

    VA + (8M * x) -> PA + (8M * x) (sz bit = 256M) where x in [0, 31]

and TSB is set similarly:

    VA + (4M * x) -> PA + (4M * x) (sz bit = 256M) where x in [0, 63]

- Testing

Tested on Sonoma (which supports 256M pages) by running stream benchmark instances in parallel: one instance uses 8M pages and another uses 256M pages, consuming 48G each.

Quoted 6 lines

Boot params used:

default_hugepagesz%6M hugepagesz%6M hugepages00 hugepagesz=8M hugepages000

Applied.

maintainer
#2 lore raw

From: David Miller <[email protected]>
Date: Sun, 11 Dec 2016 21:06:30 -0500 (EST)

Quoted 1 line

Applied.

Actually, I'm reverting.

Just doing a simply "make -s -j128" kernel build on a T4-2 I'm getting kernel log warnings:

[2024810.925975] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[2024909.011397] random: crng init done
[2024970.860642] ------------[ cut here ]------------
[2024970.869970] WARNING: CPU: 85 PID: 19335 at arch/sparc/mm/tsb.c:99 __flush_huge_tsb_one_entry.constprop.0+0x30/0x74
[2024970.890947] Modules linked in: ipv6 usb_storage loop ehci_pci sg sr_mod igb ptp pps_core ehci_hcd n2_rng rng_core
[2024970.911785] CPU: 85 PID: 19335 Comm: ld Not tainted 4.9.0+ #9
[2024970.923588] Call Trace:
[2024970.928807]  [0000000000463a2c] __warn+0xb0/0xc8
[2024970.938349]  [000000000044efa4] __flush_huge_tsb_one_entry.constprop.0+0x30/0x74
[2024970.953463]  [000000000044f224] flush_tsb_user_page+0x88/0x9c
[2024970.965268]  [000000000044eabc] tlb_batch_add_one+0x5c/0xd4
[2024970.976722]  [000000000044ed84] set_pmd_at+0x104/0x184
[2024970.987329]  [0000000000552594] zap_huge_pmd+0x30/0x244
[2024970.998097]  [000000000052a7a8] unmap_page_range+0x18c/0x794
[2024971.009721]  [000000000052b05c] unmap_vmas+0x18/0x44
[2024971.019976]  [00000000005315f8] exit_mmap+0x94/0x114
[2024971.030207]  [0000000000461930] mmput+0x50/0xf8
[2024971.039593]  [00000000004674ac] do_exit+0x310/0x904
[2024971.049651]  [0000000000467c10] do_group_exit+0x80/0xbc
[2024971.060415]  [0000000000467c60] SyS_exit_group+0x14/0x20
[2024971.071363]  [0000000000406194] linux_sparc_syscall32+0x34/0x60

which is:

#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) static void __flush_huge_tsb_one_entry(unsigned long tsb, unsigned long v,
unsigned long hash_shift, unsigned long nentries, unsigned int hugepage_shift)

{
        unsigned int hpage_entries;
        unsigned int i;

        hpage_entries = 1 << (hugepage_shift - REAL_HPAGE_SHIFT);
        WARN_ON(v & ((1ul << hugepage_shift) - 1));
        ^^^^^^^
#3 lore raw
Quoted 39 lines · David Miller

From: David Miller <[email protected]>
Date: Sun, 11 Dec 2016 21:06:30 -0500 (EST)

Quoted 1 line

Applied.

Actually, I'm reverting.

Just doing a simply "make -s -j128" kernel build on a T4-2 I'm getting kernel log warnings:

[2024810.925975] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[2024909.011397] random: crng init done
[2024970.860642] ------------[ cut here ]------------
[2024970.869970] WARNING: CPU: 85 PID: 19335 at arch/sparc/mm/tsb.c:99 __flush_huge_tsb_one_entry.constprop.0+0x30/0x74
[2024970.890947] Modules linked in: ipv6 usb_storage loop ehci_pci sg sr_mod igb ptp pps_core ehci_hcd n2_rng rng_core
[2024970.911785] CPU: 85 PID: 19335 Comm: ld Not tainted 4.9.0+ #9
[2024970.923588] Call Trace:
[2024970.928807]  [0000000000463a2c] __warn+0xb0/0xc8
[2024970.938349]  [000000000044efa4] __flush_huge_tsb_one_entry.constprop.0+0x30/0x74
[2024970.953463]  [000000000044f224] flush_tsb_user_page+0x88/0x9c
[2024970.965268]  [000000000044eabc] tlb_batch_add_one+0x5c/0xd4
[2024970.976722]  [000000000044ed84] set_pmd_at+0x104/0x184
[2024970.987329]  [0000000000552594] zap_huge_pmd+0x30/0x244
[2024970.998097]  [000000000052a7a8] unmap_page_range+0x18c/0x794
[2024971.009721]  [000000000052b05c] unmap_vmas+0x18/0x44
[2024971.019976]  [00000000005315f8] exit_mmap+0x94/0x114
[2024971.030207]  [0000000000461930] mmput+0x50/0xf8
[2024971.039593]  [00000000004674ac] do_exit+0x310/0x904
[2024971.049651]  [0000000000467c10] do_group_exit+0x80/0xbc
[2024971.060415]  [0000000000467c60] SyS_exit_group+0x14/0x20
[2024971.071363]  [0000000000406194] linux_sparc_syscall32+0x34/0x60

which is:

#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) static void __flush_huge_tsb_one_entry(unsigned long tsb, unsigned long v,
unsigned long hash_shift, unsigned long nentries, unsigned int hugepage_shift)

Quoted 7 lines
{
        unsigned int hpage_entries;
        unsigned int i;

        hpage_entries = 1 << (hugepage_shift - REAL_HPAGE_SHIFT);
        WARN_ON(v & ((1ul << hugepage_shift) - 1));
        ^^^^^^^

The warning is getting triggered since we do 'vaddr |= 1' in case the addr is executable in tlb_batch_add_one().

I originally tested the patch with stream which allocates pages only for heap. Somehow, I cannot not reproduce it (on a Sonoma) even when I back text segments with huagepages using:

hugectl --force-preload --heap=8m --text=8m make -s -j128

I added this WARN_ON during debugging and can simply be removed. Do you want to see a v4 with this warning removed or can you reapply with just this change?

Thanks,
Nitin

maintainer
#4 lore raw

From: Nitin Gupta <[email protected]>
Date: Mon, 12 Dec 2016 14:43:07 -0800

Quoted 3 lines

I added this WARN_ON during debugging and can simply be removed. Do you want to see a v4 with this warning removed or can you reapply with just this change?

You always must absolutely make a new submission.