sparc64: Multi-page size support
PATCH v4 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 v3 vs v4:
- Remove incorrect WARN_ON in __flush_huge_tsb_one_entry()
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 | 44 ++++++++-- 8 files changed, 256 insertions(+), 62 deletions(-)
arch/sparc/include/asm/page_64.h +2 -1
@@ -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
@@ -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
@@ -8,7 +8,7 @@#define TLB_BATCH_NR 192struct 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
@@ -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
@@ -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 +37 -7
86 lines not on this page · raw message
Signature · 1 line
2.9.2
David Miller
maintainerFrom: Nitin Gupta <[email protected]>
Date: Tue, 13 Dec 2016 10:03:18 -0800
arch/sparc/mm/hugetlbpage.c hugetlb_get_unmapped_area(struct file *file, unsigned long addr, · line 203
Quoted 9 lines
arch/sparc/mm/hugetlbpage.c +9
-0+static unsigned int sun4u_huge_tte_to_shift (pte_t entry) +{ +unsigned long tte_szbits =pte_val (entry) & _PAGE_SZALL_4V; +unsigned int shift; + +switch (tte_szbits) { +case _PAGE_SZ256MB_4U: + shift =HPAGE_256MB_SHIFT ; +break ;
You added all the code necessary to do this on the sun4u chips that support 256MB TTEs, so you might as well enable it in the initialization code.
I'm pretty sure this is an UltraSPARC-IV and later feature.
David Miller
maintainerFrom: Nitin Gupta <[email protected]>
Date: Tue, 13 Dec 2016 10:03:18 -0800
arch/sparc/mm/hugetlbpage.c hugetlb_get_unmapped_area(struct file *file, unsigned long addr, · line 197
Quoted 3 lines
arch/sparc/mm/hugetlbpage.c +3
-0+static unsigned int sun4u_huge_tte_to_shift (pte_t entry) +{ +unsigned long tte_szbits =pte_val (entry) & _PAGE_SZALL_4V;
Actually this should be _PAGE_SZALL_4U.
Quoted 16 lines · David Miller
From: Nitin Gupta <[email protected]>
Date: Tue, 13 Dec 2016 10:03:18 -0800arch/sparc/mm/hugetlbpage.c hugetlb_get_unmapped_area(struct file *file, unsigned long addr, · line 203
Quoted 9 lines
arch/sparc/mm/hugetlbpage.c +9
-0+static unsigned int sun4u_huge_tte_to_shift (pte_t entry) +{ +unsigned long tte_szbits =pte_val (entry) & _PAGE_SZALL_4V; +unsigned int shift; + +switch (tte_szbits) { +case _PAGE_SZ256MB_4U: + shift =HPAGE_256MB_SHIFT ; +break ;You added all the code necessary to do this on the sun4u chips that support 256MB TTEs, so you might as well enable it in the initialization code.
Quoted 2 lines
I'm pretty sure this is an UltraSPARC-IV and later feature.
I added sun4u related changes just for completeness sake. I don't have access to a sun4u machine so can't be sure if sun4u would work. That's why that _PAGE_SZALL_4V typo escaped my notice.
I will enable setup_hugepagesz() for non-hypervisor case and send a v5.
Thanks,
Nitin