THP support for PPC64
Subsystems (12)
cover THP support for PPC64
Hi,
This patchset adds transparent hugepage support for PPC64.
Some numbers:
The latency measurements code from Anton found at
http://ozlabs.org/~anton/junkcode/latency2001.c
64K page size (With THP support)
--------------------------
[root@llmp24l02 test]# ./latency2001 8G
8589934592 428.49 cycles 120.50 ns
[root@llmp24l02 test]# ./latency2001 -l 8G
8589934592 471.16 cycles 132.50 ns
[root@llmp24l02 test]# echo never > /sys/kernel/mm/transparent_hugepage/enabled [root@llmp24l02 test]# ./latency2001 8G
8589934592 766.52 cycles 215.56 ns
[root@llmp24l02 test]#
4K page size (No THP support for 4K)
----------------------------
[root@llmp24l02 test]# ./latency2001 8G
8589934592 814.88 cycles 229.16 ns
[root@llmp24l02 test]# ./latency2001 -l 8G
8589934592 463.69 cycles 130.40 ns
[root@llmp24l02 test]#
We are close to hugetlbfs in latency and we can achieve this with zero config/page reservation. Most of the allocations above are fault allocated.
Another test that does 50000000 random access over 1GB area goes from 2.65 seconds to 1.07 seconds with this patchset.
split_huge_page impact:
---------------------
To look at the performance impact of large page invalidate, I tried the below experiment. The test involved, accessing a large contiguous region of memory location as below
for (i = 0; i < size; i += PAGE_SIZE) data[i] = i;
We wanted to access the data in sequential order so that we look at the worst case THP performance. Accesing the data in sequential order implies we have the Page table cached and overhead of TLB miss is as minimal as possible. We also don't touch the entire page, because that can result in cache evict.
After we touched the full range as above, we now call mprotect on each of that page. A mprotect will result in a hugepage split. This should allow us to measure the impact of hugepage split.
for (i = 0; i < size; i += PAGE_SIZE) mprotect(&data[i], PAGE_SIZE, PROT_READ);
Split hugepage impact:
---------------------
THP enabled: 2.851561705 seconds for test completion THP disable: 3.599146098 seconds for test completion
We are 20.7% better than non THP case even when we have all the large pages split.
Detailed output:
THP enabled:
---------------------------------------
[root@llmp24l02 ~]# cat /proc/vmstat | grep thpthp_fault_alloc 0thp_fault_fallback 0thp_collapse_alloc 0thp_collapse_alloc_failed 0thp_split 0thp_zero_page_alloc 0thp_zero_page_alloc_failed 0
[root@llmp24l02 ~]# /root/thp/tools/perf/perf stat -e page-faults,dTLB-load-misses ./split-huge-page-mpro 20G time taken to touch all the data in ns: 2763096913
Performance counter stats for './split-huge-page-mpro 20G':
1,581 page-faults
3,159 dTLB-load-misses
2.851561705 seconds time elapsed[root@llmp24l02 ~]#
[root@llmp24l02 ~]# cat /proc/vmstat | grep thpthp_fault_alloc 1279thp_fault_fallback 0thp_collapse_alloc 0thp_collapse_alloc_failed 0thp_split 1279thp_zero_page_alloc 0thp_zero_page_alloc_failed 0
[root@llmp24l02 ~]#
77.05% split-huge-page [kernel.kallsyms] [k] .clear_user_page
7.10% split-huge-page [kernel.kallsyms] [k] .perf_event_mmap_ctx
1.51% split-huge-page split-huge-page-mpro [.] 0x0000000000000a70
0.96% split-huge-page [unknown] [H] 0x000000000157e3bc
0.81% split-huge-page [kernel.kallsyms] [k] .up_write
0.76% split-huge-page [kernel.kallsyms] [k] .perf_event_mmap
0.76% split-huge-page [kernel.kallsyms] [k] .down_write
0.74% split-huge-page [kernel.kallsyms] [k] .lru_add_page_tail
0.61% split-huge-page [kernel.kallsyms] [k] .split_huge_page
0.59% split-huge-page [kernel.kallsyms] [k] .change_protection
0.51% split-huge-page [kernel.kallsyms] [k] .release_pages 0.96% split-huge-page [unknown] [H] 0x000000000157e3bc
|
|--79.44%-- reloc_start
| |
| |--86.54%-- .__pSeries_lpar_hugepage_invalidate
| | .pSeries_lpar_hugepage_invalidate
| | .hpte_need_hugepage_flush
| | .split_huge_page
| | .__split_huge_page_pmd
| | .vma_adjust
| | .vma_merge
| | .mprotect_fixup
| | .SyS_mprotectTHP disabled:
---------------
[root@llmp24l02 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled [root@llmp24l02 ~]# /root/thp/tools/perf/perf stat -e page-faults,dTLB-load-misses ./split-huge-page-mpro 20G time taken to touch all the data in ns: 3513767220
Performance counter stats for './split-huge-page-mpro 20G':
3,27,726 page-faults
3,29,654 dTLB-load-misses
3.599146098 seconds time elapsed[root@llmp24l02 ~]#
Changes from V5:
* Address review comments
* Added new patch to not use hugepd for explcit hugepages. Explicit hugepaes now use PTE format similar to transparent hugepages.
* We don't use page->_mapcount for tracking free PTE frags in a PTE page.
* rebased to a86d52667d8eda5de39393ce737794403bdce1eb
* Tested with libhugetlbfs test suite
Changes from V4:
* Fix bad page error in page_table_alloc
BUG: Bad page state in process stream pfn:f1a59 page:f0000000034dc378 count:1 mapcount:0 mapping: (null) index:0x0 [c000000f322c77d0] [c00000000015e198] .bad_page+0xe8/0x140 [c000000f322c7860] [c00000000015e3c4] .free_pages_prepare+0x1d4/0x1e0 [c000000f322c7910] [c000000000160450] .free_hot_cold_page+0x50/0x230 [c000000f322c79c0] [c00000000003ad18] .page_table_alloc+0x168/0x1c0
Changes from V3:
* PowerNV boot fixes
Change from V2:
* Change patch "powerpc: Reduce PTE table memory wastage" to use much simpler approach for PTE page sharing.
* Changes to handle huge pages in KVM code.
* Address other review comments
Changes from V1
* Address review comments
* More patch split
* Add batch hpte invalidate for hugepages.
Changes from RFC V2:
* Address review comments
* More code cleanup and patch split
Changes from RFC V1:
* HugeTLB fs now works
* Compile issues fixed
* rebased to v3.8
* Patch series reorded so that ppc64 cleanups and MM THP changes are moved early in the series. This should help in picking those patches early.
Thanks,
-aneesh
PATCH 1/27 powerpc: Use signed formatting when printing error
From: "Aneesh Kumar K.V" <[email protected]>
PAPR defines these errors as negative values. So print them accordingly for easy debugging.
--- arch/powerpc/platforms/pseries/lpar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/lpar.c +1 -1
@@ -155,7 +155,7 @@ static long pSeries_lpar_hpte_insert(unsigned long hpte_group,*/ if (unlikely (lpar_rc !=H_SUCCESS )) {if (!(vflags &HPTE_V_BOLTED )) -pr_devel (" lpar err %lu\n" , lpar_rc); +pr_devel (" lpar err %ld\n" , lpar_rc);return -2 ; }if (!(vflags &HPTE_V_BOLTED ))
Signature · 1 line
1.7.10
PATCH 2/27 powerpc: Save DAR and DSISR in pt_regs on MCE
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We were not saving DAR and DSISR on MCE. Save then and also print the values along with exception details in xmon.
--- arch/powerpc/kernel/exceptions-64s.S | 9 +++++++++ arch/powerpc/xmon/xmon.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-)
arch/powerpc/kernel/exceptions-64s.S +9 -0
@@ -688,9 +688,18 @@ slb_miss_user_pseries: .align 7 .globl machine_check_common machine_check_common: + + mfspr r10,SPRN_DAR + std r10,PACA_EXGEN+EX_DAR(r13) + mfspr r10,SPRN_DSISR + stw r10,PACA_EXGEN+EX_DSISR(r13) EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC) FINISH_NAP DISABLE_INTS + ld r3,PACA_EXGEN+EX_DAR(r13) + lwz r4,PACA_EXGEN+EX_DSISR(r13) + std r3,_DAR(r1) + std r4,_DSISR(r1) bl .save_nvgprs addi r3,r1,STACK_FRAME_OVERHEAD bl .machine_check_exception
arch/powerpc/xmon/xmon.c +1 -1
@@ -1430,7 +1430,7 @@ static void excprint(struct pt_regs *fp)printf (" sp: %lx\n" , fp->gpr[1 ]);printf (" msr: %lx\n" , fp->msr); -if (trap ==0x300 || trap ==0x380 || trap ==0x600 ) { +if (trap ==0x300 || trap ==0x380 || trap ==0x600 || trap ==0x200 ) {printf (" dar: %lx\n" , fp->dar);if (trap !=0x380 )printf (" dsisr: %lx\n" , fp->dsisr);
Signature · 1 line
1.7.10
PATCH 3/27 powerpc: Don't hard code the size of pte page
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
USE PTRS_PER_PTE to indicate the size of pte page. To support THP, later patches will be changing PTRS_PER_PTE value.
--- arch/powerpc/include/asm/pgtable.h | 6 ++++++ arch/powerpc/mm/hash_low_64.S | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/pgtable.h +6 -0
@@ -17,6 +17,12 @@ struct mm_struct;# include <asm/pgtable-ppc32.h> #endif +/* +* We save the slot number & secondary bit in the second half of the +* PTE page. We use the 8 bytes per each pte entry. +*/ +#define PTE_PAGE_HIDX_OFFSET (PTRS_PER_PTE * 8) +#ifndef __ASSEMBLY__#include <asm/tlbflush.h>
arch/powerpc/mm/hash_low_64.S +2 -2
@@ -490,7 +490,7 @@ END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE) beq htab_inval_old_hpte ld r6,STK_PARAM(R6)(r1) - ori r26,r6,0x8000 /* Load the hidx mask */ + ori r26,r6,PTE_PAGE_HIDX_OFFSET /* Load the hidx mask. */ ld r26,0(r26) addi r5,r25,36 /* Check actual HPTE_SUB bit, this */ rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
@@ -607,7 +607,7 @@ htab_pte_insert_ok: sld r4,r4,r5 andc r26,r26,r4 or r26,r26,r3 - ori r5,r6,0x8000 + ori r5,r6,PTE_PAGE_HIDX_OFFSET std r26,0(r5) lwsync std r30,0(r6)
Signature · 1 line
1.7.10
PATCH 4/27 powerpc: Don't truncate pgd_index wrongly
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
With PGD_INDEX_SIZE set to 12 the existing macro doesn't work. Fix it to use PTRS_PER_PGD
The idea originally was to have one more bit in the result of pgd_index() than PGD_INDEX_SIZE, so that if one had an address corresponding to the last PGD entry, and then incremented that address by PGD_SIZE, and took pgd_index() of that, you wouldn't end up with zero. The commit that introduced that dates back to 2002, and the code that was sensitive to that edge case has long since been refactored (several times), so there is no need for it these days.
--- arch/powerpc/include/asm/pgtable-ppc64.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/include/asm/pgtable-ppc64.h +1 -2
@@ -167,8 +167,7 @@* Find an entry in a page-table-directory. We combine the address region * (the high order N bits) and the pgd portion of the address. */ -/* to avoid overflow in free_pgtables we don't use PTRS_PER_PGD here */ -#define pgd_index (address) (((address) >> (PGDIR_SHIFT)) & 0x1ff) +#define pgd_index (address) (((address) >> (PGDIR_SHIFT)) & (PTRS_PER_PGD - 1))#define pgd_offset (mm, address) ((mm)->pgd + pgd_index(address))
Signature · 1 line
1.7.10
PATCH 5/27 powerpc: New hugepage directory format
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
Change the hugepage directory format so that we can have leaf ptes directly at page directory avoiding the allocation of hugepage directory.
With the new table format we have 3 cases for pgds and pmds:
(1) invalid (all zeroes)
(2) pointer to next table, as normal; bottom 6 bits == 0
(4) hugepd pointer, bottom two bits == 00, next 4 bits indicate size of table
Instead of storing shift value in hugepd pointer we use mmu_psize_def index so that we can fit all the supported hugepage size in 4 bits
--- arch/powerpc/include/asm/hugetlb.h | 13 +++++++++++-- arch/powerpc/include/asm/mmu-hash64.h | 20 +++++++++++++++++++- arch/powerpc/include/asm/page.h | 18 +++++------------- arch/powerpc/include/asm/pgalloc-64.h | 5 ++++- arch/powerpc/mm/hugetlbpage.c | 23 ++++------------------- arch/powerpc/mm/init_64.c | 3 +-- 6 files changed, 44 insertions(+), 38 deletions(-)
arch/powerpc/include/asm/hugetlb.h +11 -2
@@ -9,12 +9,21 @@ extern struct kmem_cache *hugepte_cache;static inline pte_t *hugepd_page (hugepd_t hpd) {BUG_ON (!hugepd_ok (hpd)); -return (pte_t *)((hpd.pd & ~HUGEPD_SHIFT_MASK ) |PD_HUGE ); +/* +* We have only four bits to encode, MMU page size +*/ +BUILD_BUG_ON ((MMU_PAGE_COUNT -1 ) >0xf ); +return (pte_t *)(hpd.pd & ~HUGEPD_SHIFT_MASK ); +} + +static inline unsigned int hugepd_mmu_psize (hugepd_t hpd) +{ +return (hpd.pd &HUGEPD_SHIFT_MASK ) >>2 ; }static inline unsigned int hugepd_shift (hugepd_t hpd) { -return hpd.pd &HUGEPD_SHIFT_MASK ; +return mmu_psize_to_shift (hugepd_mmu_psize (hpd)); } static inline pte_t *hugepte_offset(hugepd_t *hpdp, unsigned long addr,
arch/powerpc/include/asm/mmu-hash64.h +19 -1
@@ -21,6 +21,7 @@* complete pgtable.h but only a portion of it. */ #include <asm/pgtable-ppc64.h> +#include <asm/bug.h> /* * Segment table
@@ -159,6 +160,24 @@ struct mmu_psize_defunsigned long avpnm;/* bits to mask out in AVPN in the HPTE */ unsigned long sllp; /* SLB L||LP (exact mask to use in slbmte) */ }; +extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT ]; + +static inline int shift_to_mmu_psize (unsigned int shift) +{ +int psize; + +for (psize =0 ; psize <MMU_PAGE_COUNT ; ++psize) +if (mmu_psize_defs[psize].shift == shift) +return psize; +return -1 ; +} + +static inline unsigned int mmu_psize_to_shift (unsigned int mmu_psize) +{ +if (mmu_psize_defs[mmu_psize].shift) +return mmu_psize_defs[mmu_psize].shift; +BUG (); +}#endif /* __ASSEMBLY__ */
@@ -193,7 +212,6 @@ static inline int segment_shift(int ssize)/* * The current system page and segment sizes */ -extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT ];extern int mmu_linear_psize;extern int mmu_virtual_psize;extern int mmu_vmalloc_psize;
arch/powerpc/include/asm/page.h +5 -13
@@ -250,18 +250,6 @@ extern long long virt_phys_offset;#endif /* -* Use the top bit of the higher-level page table entries to indicate whether -* the entries we point to contain hugepages. This works because we know that -* the page tables live in kernel space. If we ever decide to support having -* page tables at arbitrary addresses, this breaks and will have to change. -*/ -#ifdef CONFIG_PPC64 -#define PD_HUGE 0x8000000000000000 -#else -#define PD_HUGE 0x80000000 -#endif - -/* * Some number of bits at the level of the page table that points to * a hugepte are used to encode the size. This masks those bits. */
@@ -356,7 +344,11 @@ typedef struct { signed long pd; } hugepd_t;#ifdef CONFIG_HUGETLB_PAGE static inline int hugepd_ok (hugepd_t hpd) { -return (hpd.pd >0 ); +/* +* hugepd pointer, bottom two bits == 00 and next 4 bits +* indicate size of table +*/ +return (((hpd.pd &0x3 ) ==0x0 ) && ((hpd.pd &HUGEPD_SHIFT_MASK ) !=0 )); }#define is_hugepd (pdep) (hugepd_ok(*((hugepd_t *)(pdep))))
arch/powerpc/include/asm/pgalloc-64.h +4 -1
@@ -35,7 +35,10 @@ struct vmemmap_backing {#define MAX_PGTABLE_INDEX_SIZE 0xfextern struct kmem_cache *pgtable_cache[]; -#define PGT_CACHE (shift) (pgtable_cache[(shift)-1]) +#define PGT_CACHE (shift) ({ \ + BUG_ON(!(shift)); \ + pgtable_cache[(shift) - 1]; \ + })static inline pgd_t *pgd_alloc (struct mm_struct *mm) {
arch/powerpc/mm/hugetlbpage.c +4 -19
@@ -48,23 +48,6 @@ static u64 gpage_freearray[MAX_NUMBER_GPAGES];static unsigned nr_gpages;#endif -static inline int shift_to_mmu_psize (unsigned int shift) -{ -int psize; - -for (psize =0 ; psize <MMU_PAGE_COUNT ; ++psize) -if (mmu_psize_defs[psize].shift == shift) -return psize; -return -1 ; -} - -static inline unsigned int mmu_psize_to_shift (unsigned int mmu_psize) -{ -if (mmu_psize_defs[mmu_psize].shift) -return mmu_psize_defs[mmu_psize].shift; -BUG (); -} -#define hugepd_none (hpd) ((hpd).pd == 0)pte_t *find_linux_pte_or_hugepte (pgd_t *pgdir,unsigned long ea,unsigned *shift)
@@ -145,7 +128,8 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t *hpdp,if (unlikely (!hugepd_none (*hpdp)))break ;else - hpdp->pd = ((unsigned long )new & ~PD_HUGE ) | pshift; + hpdp->pd = (unsigned long )new | + (shift_to_mmu_psize (pshift) <<2 ); }/* If we bailed from the for loop early, an error occurred, clean up */ if (i < num_hugepd) {
@@ -157,7 +141,8 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t *hpdp,if (!hugepd_none (*hpdp))kmem_cache_free (cachep, new);else - hpdp->pd = ((unsigned long )new & ~PD_HUGE ) | pshift; + hpdp->pd = (unsigned long )new | + (shift_to_mmu_psize (pshift) <<2 );#endif spin_unlock (&mm->page_table_lock);return 0 ;
arch/powerpc/mm/init_64.c +1 -2
@@ -129,8 +129,7 @@ void pgtable_cache_add(unsigned shift, void (*ctor)(void *)) align = max_t(unsigned long, align, minalign); name =kasprintf (GFP_KERNEL ,"pgtable-2^%d" , shift); new =kmem_cache_create (name, table_size, align,0 , ctor); -PGT_CACHE (shift) = new; - + pgtable_cache[shift -1 ] = new;pr_debug ("Allocated pgtable cache for order %d\n" , shift); }
Signature · 1 line
1.7.10
Re: [PATCH -V6 05/27] powerpc: New hugepage directory format
Quoted 2 lines · Aneesh Kumar K.V
Instead of storing shift value in hugepd pointer we use
mmu_psize_defindex so that we can fit all the supported hugepage size in 4 bits
That works, but does mean that we have to scan the mmu_psize_defs[] array to work out the encoding for a particular page size. Instead, we could use the fact that all large page sizes are powers of 4, as are all supported page sizes on embedded processors. So we could encode using page_code = (page_order - 12) / 2, where page_order is the log base 2 of the page size, and that lets us represent all power of 4 page sizes between 2^12 (4kB) and 2^42 bytes (4TB).
Paul.
Re: [PATCH -V6 05/27] powerpc: New hugepage directory format
Quoted 7 lines · Paul Mackerras
Quoted 2 lines · Aneesh Kumar K.V
Instead of storing shift value in hugepd pointer we use
mmu_psize_defindex so that we can fit all the supported hugepage size in 4 bitsThat works, but does mean that we have to scan the mmu_psize_defs[] array to work out the encoding for a particular page size.
We do the scan only when allocating hugepgd. While walking it is only mmu_psize_defs dereference. Yes, that could possibly have a performance impact, but having a well defined way to map page shift to a smaller index and using the same method all the place is nice. I will try to measure the impact and switch to the below method if needed.
Quoted 6 lines
Instead,
we could use the fact that all large page sizes are powers of 4, as are all supported page sizes on embedded processors. So we could encode usingpage_code= (page_order- 12) / 2, wherepage_orderis the log base 2 of the page size, and that lets us represent all power of 4 page sizes between 2^12 (4kB) and 2^42 bytes (4TB).
I guess i can add this as an addon patch on the top of the series if the current patch series is going in to Benh's tree ?
-aneesh
Re: [PATCH -V6 05/27] powerpc: New hugepage directory format
In reply to Aneesh Kumar K.VQuoted 1 line · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
[snip]
arch/powerpc/include/asm/page.h extern long long virt_phys_offset; · line 262
Quoted 11 lines
/*
- * Use the top bit of the higher-level page table entries to indicate whether
- * the entries we point to contain hugepages. This works because we know that
- * the page tables live in kernel space. If we ever decide to support having
- * page tables at arbitrary addresses, this breaks and will have to change.
- */arch/powerpc/include/asm/page.h +0
-5-#ifdef CONFIG_PPC64 -#define PD_HUGE 0x8000000000000000 -#else -#define PD_HUGE 0x80000000 -#endif
I think this is a good thing to do ultimately, but if you do this you also need to fix arch/powerpc/kernel/head_fsl_booke.S:
#ifdef CONFIG_PTE_64BIT
#ifdef CONFIG_HUGETLB_PAGE
#define FIND_PTE \ rlwinm r12, r10, 13, 19, 29; /* Compute pgdir/pmd offset */ \ lwzx r11, r12, r11; /* Get pgd/pmd entry */ \ rlwinm. r12, r11, 0, 0, 20; /* Extract pt base address */ \ blt 1000f; /* Normal non-huge page */ \ beq 2f; /* Bail if no table */ \ oris r11, r11, PD_HUGE@h; /* Put back address bit */ \ andi. r10, r11, HUGEPD_SHIFT_MASK@l; /* extract size field */ \ xor r12, r10, r11; /* drop size bits from pointer */ \ b 1001f; \
and this, from arch/powerpc/mm/tlb_low_64e.S:
cmpdi cr0,r14,0 bge tlb_miss_fault_bolted /* Bad pgd entry or hugepage; bail */
(of which there are several similar instances in that file).
If you want to avoid fixing these bits of assembly code (and any others I missed in my quick scan), you'll need to keep the definition of PD_HUGE, at least on anything not 64-bit Book3S.
Paul.
Re: [PATCH -V6 05/27] powerpc: New hugepage directory format
Quoted 22 lines · Paul Mackerras
Quoted 1 line · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
[snip]
Review
Quoted 11 lines
/*
- * Use the top bit of the higher-level page table entries to indicate whether
- * the entries we point to contain hugepages. This works because we know that
- * the page tables live in kernel space. If we ever decide to support having
- * page tables at arbitrary addresses, this breaks and will have to change.
- */(quoted diff) +0
-5-#ifdef CONFIG_PPC64 -#define PD_HUGE 0x8000000000000000 -#else -#define PD_HUGE 0x80000000 -#endifI think this is a good thing to do ultimately, but if you do this you also need to fix
arch/powerpc/kernel/head_fsl_booke.S:#ifdef
CONFIG_PTE_64BIT
#ifdefCONFIG_HUGETLB_PAGE
Quoted 11 lines
#define FIND_PTE \ rlwinm r12, r10, 13, 19, 29; /* Compute pgdir/pmd offset */ \ lwzx r11, r12, r11; /* Get pgd/pmd entry */ \ rlwinm. r12, r11, 0, 0, 20; /* Extract pt base address */ \ blt 1000f; /* Normal non-huge page */ \ beq 2f; /* Bail if no table */ \ oris r11, r11, PD_HUGE@h; /* Put back address bit */ \ andi. r10, r11, HUGEPD_SHIFT_MASK@l; /* extract size field */ \ xor r12, r10, r11; /* drop size bits from pointer */ \ b 1001f; \
that should be easy, but
Quoted 10 lines
and this, from
arch/powerpc/mm/tlb_low_64e.S:cmpdi cr0,r14,0 bge tlb_miss_fault_bolted /* Bad pgd entry or hugepage; bail */(of which there are several similar instances in that file).
If you want to avoid fixing these bits of assembly code (and any others I missed in my quick scan), you'll need to keep the definition of
PD_HUGE, at least on anything not 64-bit Book3S.
I am not sure we can find all such usages easily. I looked at the commit d1b9b12811ef079c37fe464f51953746d8b78e2a and am worried we might be breaking assumptions like that. Considering that I won't be able to test FSL, I am inclined to go with the second option you listed, even though that adds few more #ifdef. How about
arch/powerpc/include/asm/hugetlb.h +30 -0
@@ -6,6 +6,33 @@extern struct kmem_cache *hugepte_cache; +#ifdef CONFIG_PPC_BOOK3S_64 +/* +* This should work for other subarchs too. But right now we use the +* new format only for 64bit book3s +*/ +static inline pte_t *hugepd_page (hugepd_t hpd) +{ +BUG_ON (!hugepd_ok (hpd)); +/* +* We have only four bits to encode, MMU page size +*/ +BUILD_BUG_ON ((MMU_PAGE_COUNT -1 ) >0xf ); +return (pte_t *)(hpd.pd & ~HUGEPD_SHIFT_MASK ); +} + +static inline unsigned int hugepd_mmu_psize (hugepd_t hpd) +{ +return (hpd.pd &HUGEPD_SHIFT_MASK ) >>2 ; +} + +static inline unsigned int hugepd_shift (hugepd_t hpd) +{ +return mmu_psize_to_shift (hugepd_mmu_psize (hpd)); +} + +#else +static inline pte_t *hugepd_page (hugepd_t hpd) {BUG_ON (!hugepd_ok (hpd));
@@ -17,6 +44,9 @@ static inline unsigned int hugepd_shift(hugepd_t hpd) return hpd.pd & HUGEPD_SHIFT_MASK; } +#endif /* CONFIG_PPC_BOOK3S_64 */ + +static inline pte_t *hugepte_offset (hugepd_t *hpdp,unsigned long addr,unsigned pdshift) {
arch/powerpc/include/asm/mmu-hash64.h +19 -1
@@ -21,6 +21,7 @@* complete pgtable.h but only a portion of it. */ #include <asm/pgtable-ppc64.h> +#include <asm/bug.h> /* * Segment table
@@ -159,6 +160,24 @@ struct mmu_psize_defunsigned long avpnm;/* bits to mask out in AVPN in the HPTE */ unsigned long sllp; /* SLB L||LP (exact mask to use in slbmte) */ }; +extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT ]; + +static inline int shift_to_mmu_psize (unsigned int shift) +{ +int psize; + +for (psize =0 ; psize <MMU_PAGE_COUNT ; ++psize) +if (mmu_psize_defs[psize].shift == shift) +return psize; +return -1 ; +} + +static inline unsigned int mmu_psize_to_shift (unsigned int mmu_psize) +{ +if (mmu_psize_defs[mmu_psize].shift) +return mmu_psize_defs[mmu_psize].shift; +BUG (); +}#endif /* __ASSEMBLY__ */
@@ -193,7 +212,6 @@ static inline int segment_shift(int ssize)/* * The current system page and segment sizes */ -extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT ];extern int mmu_linear_psize;extern int mmu_virtual_psize;extern int mmu_vmalloc_psize;
arch/powerpc/include/asm/page.h +13 -0
@@ -249,6 +249,7 @@ extern long long virt_phys_offset;#define is_kernel_addr (x) ((x) >= PAGE_OFFSET)#endif +#ifndef CONFIG_PPC_BOOK3S_64 /* * Use the top bit of the higher-level page table entries to indicate whether * the entries we point to contain hugepages. This works because we know that
@@ -260,6 +261,7 @@ extern long long virt_phys_offset;#else #define PD_HUGE 0x80000000#endif +#endif /* CONFIG_PPC_BOOK3S_64 */ /* * Some number of bits at the level of the page table that points to
@@ -354,10 +356,21 @@ typedef unsigned long pgprot_t;typedef struct {signed long pd; }hugepd_t ;#ifdef CONFIG_HUGETLB_PAGE +#ifdef CONFIG_PPC_BOOK3S_64 +static inline int hugepd_ok (hugepd_t hpd) +{ +/* +* hugepd pointer, bottom two bits == 00 and next 4 bits +* indicate size of table +*/ +return (((hpd.pd &0x3 ) ==0x0 ) && ((hpd.pd &HUGEPD_SHIFT_MASK ) !=0 )); +} +#else static inline int hugepd_ok (hugepd_t hpd) {return (hpd.pd >0 ); } +#endif #define is_hugepd (pdep) (hugepd_ok(*((hugepd_t *)(pdep))))#else /* CONFIG_HUGETLB_PAGE */
arch/powerpc/include/asm/pgalloc-64.h +4 -1
@@ -35,7 +35,10 @@ struct vmemmap_backing {#define MAX_PGTABLE_INDEX_SIZE 0xfextern struct kmem_cache *pgtable_cache[]; -#define PGT_CACHE (shift) (pgtable_cache[(shift)-1]) +#define PGT_CACHE (shift) ({ \ + BUG_ON(!(shift)); \ + pgtable_cache[(shift) - 1]; \ + })static inline pgd_t *pgd_alloc (struct mm_struct *mm) {
arch/powerpc/mm/hugetlbpage.c +8 -18
@@ -48,23 +48,6 @@ static u64 gpage_freearray[MAX_NUMBER_GPAGES];static unsigned nr_gpages;#endif -static inline int shift_to_mmu_psize (unsigned int shift) -{ -int psize; - -for (psize =0 ; psize <MMU_PAGE_COUNT ; ++psize) -if (mmu_psize_defs[psize].shift == shift) -return psize; -return -1 ; -} - -static inline unsigned int mmu_psize_to_shift (unsigned int mmu_psize) -{ -if (mmu_psize_defs[mmu_psize].shift) -return mmu_psize_defs[mmu_psize].shift; -BUG (); -} -#define hugepd_none (hpd) ((hpd).pd == 0)pte_t *find_linux_pte_or_hugepte (pgd_t *pgdir,unsigned long ea,unsigned *shift)
@@ -145,6 +128,7 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t *hpdp,if (unlikely (!hugepd_none (*hpdp)))break ;else +/* We use the old format for PPC_FSL_BOOK3E */ hpdp->pd = ((unsigned long )new & ~PD_HUGE ) | pshift; }/* If we bailed from the for loop early, an error occurred, clean up */
@@ -156,9 +140,15 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t *hpdp,#else if (!hugepd_none (*hpdp))kmem_cache_free (cachep, new); -else +else { +#ifdef CONFIG_PPC_BOOK3S_64 + hpdp->pd = (unsigned long )new | + (shift_to_mmu_psize (pshift) <<2 ); +#else hpdp->pd = ((unsigned long )new & ~PD_HUGE ) | pshift;#endif + } +#endif spin_unlock (&mm->page_table_lock);return 0 ; }
arch/powerpc/mm/init_64.c +1 -2
@@ -129,8 +129,7 @@ void pgtable_cache_add(unsigned shift, void (*ctor)(void *)) align = max_t(unsigned long, align, minalign); name =kasprintf (GFP_KERNEL ,"pgtable-2^%d" , shift); new =kmem_cache_create (name, table_size, align,0 , ctor); -PGT_CACHE (shift) = new; - + pgtable_cache[shift -1 ] = new;pr_debug ("Allocated pgtable cache for order %d\n" , shift); }
PATCH 6/27 powerpc: Switch 16GB and 16MB explicit hugepages to a different page table format
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We will be switching PMD_SHIFT to 24 bits to facilitate THP impmenetation. With PMD_SHIFT set to 24, we now have 16MB huge pages allocated at PGD level. That means with 32 bit process we cannot allocate normal pages at all, because we cover the entire address space with one pgd entry. Fix this by switching to a new page table format for hugepages. With the new page table format for 16GB and 16MB hugepages we won't allocate hugepage directory. Instead we encode the PTE information directly at the directory level. This forces 16MB hugepage at PMD level. This will also make the page take walk much simpler later when we add the THP support.
With the new table format we have 4 cases for pgds and pmds:
(1) invalid (all zeroes)
(2) pointer to next table, as normal; bottom 6 bits == 0
(3) leaf pte for huge page, bottom two bits != 00
(4) hugepd pointer, bottom two bits == 00, next 4 bits indicate size of table
--- arch/powerpc/include/asm/page.h | 2 + arch/powerpc/include/asm/pgtable.h | 2 + arch/powerpc/mm/gup.c | 18 +++- arch/powerpc/mm/hugetlbpage.c | 176 ++++++++++++++++++++++++++++++------ 4 files changed, 168 insertions(+), 30 deletions(-)
arch/powerpc/include/asm/page.h +2 -0
@@ -352,8 +352,10 @@ static inline int hugepd_ok(hugepd_t hpd) }#define is_hugepd (pdep) (hugepd_ok(*((hugepd_t *)(pdep)))) +int pgd_huge (pgd_t pgd);#else /* CONFIG_HUGETLB_PAGE */ #define is_hugepd (pdep) 0 +#define pgd_huge (pgd) 0#endif /* CONFIG_HUGETLB_PAGE */ struct page ;
arch/powerpc/include/asm/pgtable.h +2 -0
@@ -218,6 +218,8 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);extern int gup_hugepd (hugepd_t *hugepd,unsigned pdshift,unsigned long addr,unsigned long end,int write,struct page **pages,int *nr); +extern int gup_hugepte (pte_t *ptep,unsigned long sz,unsigned long addr, +unsigned long end,int write,struct page **pages,int *nr);#endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */
arch/powerpc/mm/gup.c +15 -3
@@ -68,7 +68,11 @@ static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end, next =pmd_addr_end (addr, end);if (pmd_none (pmd))return 0 ; -if (is_hugepd (pmdp)) { +if (pmd_huge (pmd)) { +if (!gup_hugepte ((pte_t *)pmdp,PMD_SIZE , addr, next, + write, pages, nr)) +return 0 ; + }else if (is_hugepd (pmdp)) {if (!gup_hugepd ((hugepd_t *)pmdp,PMD_SHIFT , addr, next, write, pages, nr))return 0 ;
@@ -92,7 +96,11 @@ static int gup_pud_range(pgd_t pgd, unsigned long addr, unsigned long end, next =pud_addr_end (addr, end);if (pud_none (pud))return 0 ; -if (is_hugepd (pudp)) { +if (pud_huge (pud)) { +if (!gup_hugepte ((pte_t *)pudp,PUD_SIZE , addr, next, + write, pages, nr)) +return 0 ; + }else if (is_hugepd (pudp)) {if (!gup_hugepd ((hugepd_t *)pudp,PUD_SHIFT , addr, next, write, pages, nr))return 0 ;
@@ -153,7 +161,11 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, next =pgd_addr_end (addr, end);if (pgd_none (pgd)) goto slow; -if (is_hugepd (pgdp)) { +if (pgd_huge (pgd)) { +if (!gup_hugepte ((pte_t *)pgdp,PGDIR_SIZE , addr, next, + write, pages, &nr)) + goto slow; + }else if (is_hugepd (pgdp)) {if (!gup_hugepd ((hugepd_t *)pgdp,PGDIR_SHIFT , addr, next, write, pages, &nr)) goto slow;
arch/powerpc/mm/hugetlbpage.c +149 -27
244 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 7/27 powerpc: Reduce the PTE_INDEX_SIZE
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This make one PMD cover 16MB range. That helps in easier implementation of THP on power. THP core code make use of one pmd entry to track the hugepage and the range mapped by a single pmd entry should be equal to the hugepage size supported by the hardware.
This also switch PGD to cover 16GB. That is needed so that we can simplify the hugetlb page walking code so that we have same pte format for explicit hugepage and THP hugepage.
--- arch/powerpc/include/asm/pgtable-ppc64-64k.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/pgtable-ppc64-64k.h +3 -3
@@ -4,10 +4,10 @@#include <asm-generic/pgtable-nopud.h> -#define PTE_INDEX_SIZE 12 -#define PMD_INDEX_SIZE 12 +#define PTE_INDEX_SIZE 8 +#define PMD_INDEX_SIZE 10#define PUD_INDEX_SIZE 0 -#define PGD_INDEX_SIZE 6 +#define PGD_INDEX_SIZE 12#ifndef __ASSEMBLY__#define PTE_TABLE_SIZE (sizeof(real_pte_t) << PTE_INDEX_SIZE)
Signature · 1 line
1.7.10
PATCH 8/27 powerpc: Move the pte free routines from common header
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This patch moves the common code to 32/64 bit headers and also duplicate 4K_PAGES and 64K_PAGES section. We will later change the 64 bit 64K_PAGES version to support smaller PTE fragments. The patch doesn't introduce any functional changes.
--- arch/powerpc/include/asm/pgalloc-32.h | 45 ++++++++++ arch/powerpc/include/asm/pgalloc-64.h | 157 ++++++++++++++++++++++++++++++--- arch/powerpc/include/asm/pgalloc.h | 46 +--------- 3 files changed, 189 insertions(+), 59 deletions(-)
arch/powerpc/include/asm/pgalloc-32.h +45 -0
@@ -37,6 +37,17 @@ extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);extern pte_t *pte_alloc_one_kernel (struct mm_struct *mm,unsigned long addr);extern pgtable_t pte_alloc_one (struct mm_struct *mm,unsigned long addr); +static inline void pte_free_kernel (struct mm_struct *mm,pte_t *pte) +{ +free_page ((unsigned long )pte); +} + +static inline void pte_free (struct mm_struct *mm,pgtable_t ptepage) +{ +pgtable_page_dtor (ptepage); +__free_page (ptepage); +} +static inline void pgtable_free (void *table,unsigned index_size) {BUG_ON (index_size);/* 32-bit doesn't use this */
@@ -45,4 +56,38 @@ static inline void pgtable_free(void *table, unsigned index_size)#define check_pgt_cache () do { } while (0) +#ifdef CONFIG_SMP +static inline void pgtable_free_tlb (struct mmu_gather *tlb, +void *table,int shift) +{ +unsigned long pgf = (unsigned long )table; +BUG_ON (shift >MAX_PGTABLE_INDEX_SIZE ); + pgf |= shift; +tlb_remove_table (tlb, (void *)pgf); +} + +static inline void __tlb_remove_table (void *_table) +{ +void *table = (void *)((unsigned long )_table & ~MAX_PGTABLE_INDEX_SIZE ); +unsigned shift = (unsigned long )_table &MAX_PGTABLE_INDEX_SIZE ; + +pgtable_free (table, shift); +} +#else +static inline void pgtable_free_tlb (struct mmu_gather *tlb, +void *table,int shift) +{ +pgtable_free (table, shift); +} +#endif + +static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t table, +unsigned long address) +{ +struct page *page =page_address (table); + +tlb_flush_pgtable (tlb, address); +pgtable_page_dtor (page); +pgtable_free_tlb (tlb, page,0 ); +}#endif /* _ASM_POWERPC_PGALLOC_32_H */
arch/powerpc/include/asm/pgalloc-64.h +143 -14
194 lines not on this page · raw message
arch/powerpc/include/asm/pgalloc.h +1 -45
63 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 9/27 powerpc: Reduce PTE table memory wastage
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We allocate one page for the last level of linux page table. With THP and large page size of 16MB, that would mean we are wasting large part of that page. To map 16MB area, we only need a PTE space of 2K with 64K page size. This patch reduce the space wastage by sharing the page allocated for the last level of linux page table with multiple pmd entries. We call these smaller chunks PTE page fragments and allocated page, PTE page.
In order to support systems which doesn't have 64K HPTE support, we also add another 2K to PTE page fragment. The second half of the PTE fragments is used for storing slot and secondary bit information of an HPTE. With this we now have a 4K PTE fragment.
We use a simple approach to share the PTE page. On allocation, we bump the PTE page refcount to 16 and share the PTE page with the next 16 pte alloc request. This should help in the node locality of the PTE page fragment, assuming that the immediate pte alloc request will mostly come from the same NUMA node. We don't try to reuse the freed PTE page fragment. Hence we could be waisting some space.
--- arch/powerpc/include/asm/mmu-book3e.h | 4 ++ arch/powerpc/include/asm/mmu-hash64.h | 4 ++ arch/powerpc/include/asm/page.h | 4 ++ arch/powerpc/include/asm/pgalloc-64.h | 82 +++++++---------------- arch/powerpc/kernel/setup_64.c | 4 +- arch/powerpc/mm/mmu_context_hash64.c | 37 +++++++++++ arch/powerpc/mm/pgtable_64.c | 118 +++++++++++++++++++++++++++++++++ 7 files changed, 195 insertions(+), 58 deletions(-)
arch/powerpc/include/asm/mmu-book3e.h +4 -0
@@ -231,6 +231,10 @@ typedef struct {u64 high_slices_psize;/* 4 bits per slice for now */ u16 user_psize;/* page size index */ #endif +#ifdef CONFIG_PPC_64K_PAGES +/* for 4K PTE fragment support */ +void *pte_frag; +#endif } mm_context_t;/* Page size definitions, common between 32 and 64-bit
arch/powerpc/include/asm/mmu-hash64.h +4 -0
@@ -516,6 +516,10 @@ typedef struct {unsigned long acop;/* mask of enabled coprocessor types */ unsigned int cop_pid;/* pid value used with coprocessors */ #endif /* CONFIG_PPC_ICSWX */ +#ifdef CONFIG_PPC_64K_PAGES +/* for 4K PTE fragment support */ +void *pte_frag; +#endif } mm_context_t;
arch/powerpc/include/asm/page.h +4 -0
@@ -372,7 +372,11 @@ void arch_free_page(struct page *page, int order);struct vm_area_struct ; +#ifdef CONFIG_PPC_64K_PAGES +typedef pte_t *pgtable_t ; +#else typedef struct page *pgtable_t ; +#endif #include <asm-generic/memory_model.h> #endif /* __ASSEMBLY__ */
arch/powerpc/include/asm/pgalloc-64.h +25 -57
128 lines not on this page · raw message
arch/powerpc/kernel/setup_64.c +3 -1
@@ -583,7 +583,9 @@ void __init setup_arch(char **cmdline_p) init_mm.end_code = (unsigned long ) _etext; init_mm.end_data = (unsigned long ) _edata; init_mm.brk = klimit; - +#ifdef CONFIG_PPC_64K_PAGES + init_mm.context.pte_frag =NULL ; +#endif irqstack_early_init ();exc_lvl_early_init ();emergency_stack_init ();
arch/powerpc/mm/mmu_context_hash64.c +37 -0
@@ -23,6 +23,7 @@#include <linux/slab.h> #include <asm/mmu_context.h> +#include <asm/pgalloc.h> #include "icswx.h"
@@ -85,6 +86,9 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)spin_lock_init (mm->context.cop_lockp);#endif /* CONFIG_PPC_ICSWX */ +#ifdef CONFIG_PPC_64K_PAGES + mm->context.pte_frag =NULL ; +#endif return 0 ; }
@@ -96,13 +100,46 @@ void __destroy_context(int context_id) }EXPORT_SYMBOL_GPL (__destroy_context); +#ifdef CONFIG_PPC_64K_PAGES +static void destroy_pagetable_page (struct mm_struct *mm) +{ +int count; +void *pte_frag; +struct page *page; + + pte_frag = mm->context.pte_frag; +if (!pte_frag) +return ; + + page =virt_to_page (pte_frag); +/* drop all the pending references */ + count = ((unsigned long )pte_frag & ~PAGE_MASK ) >>PTE_FRAG_SIZE_SHIFT ; +/* We allow PTE_FRAG_NR fragments from a PTE page */ + count =atomic_sub_return (PTE_FRAG_NR - count, &page->_count); +if (!count) { +pgtable_page_dtor (page); +free_hot_cold_page (page,0 ); + } +} + +#else +static inline void destroy_pagetable_page (struct mm_struct *mm) +{ +return ; +} +#endif + +void destroy_context (struct mm_struct *mm) { +#ifdef CONFIG_PPC_ICSWX drop_cop (mm->context.acop, mm);kfree (mm->context.cop_lockp); mm->context.cop_lockp =NULL ;#endif /* CONFIG_PPC_ICSWX */ + +destroy_pagetable_page (mm);__destroy_context (mm->context.id);subpage_prot_free (mm); mm->context.id =MMU_NO_CONTEXT ;
arch/powerpc/mm/pgtable_64.c +118 -0
121 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 10/27 powerpc: Use encode avpn where we need only avpn values
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
In all these cases we are doing something similar to
HPTE_V_COMPARE(hpte_v, want_v) which ignores the HPTE_V_LARGE bit
With MPSS support we would need actual page size to set HPTE_V_LARGE bit and that won't be available in most of these cases. Since we are ignoring HPTE_V_LARGE bit, use the avpn value instead. There should not be any change in behaviour after this patch.
--- arch/powerpc/mm/hash_native_64.c | 8 ++++---- arch/powerpc/platforms/cell/beat_htab.c | 10 +++++----- arch/powerpc/platforms/ps3/htab.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/mm/hash_native_64.c +4 -4
@@ -252,7 +252,7 @@ static long native_hpte_updatepp(unsigned long slot, unsigned long newpp,unsigned long hpte_v, want_v;int ret =0 ; - want_v =hpte_encode_v (vpn, psize, ssize); + want_v =hpte_encode_avpn (vpn, psize, ssize);DBG_LOW (" update(vpn=%016lx, avpnv=%016lx, group=%lx, newpp=%lx)" , vpn, want_v &HPTE_V_AVPN , slot, newpp);
@@ -288,7 +288,7 @@ static long native_hpte_find(unsigned long vpn, int psize, int ssize)unsigned long want_v, hpte_v; hash =hpt_hash (vpn, mmu_psize_defs[psize].shift, ssize); - want_v =hpte_encode_v (vpn, psize, ssize); + want_v =hpte_encode_avpn (vpn, psize, ssize);/* Bolted mappings are only ever in the primary group */ slot = (hash & htab_hash_mask) *HPTES_PER_GROUP ;
@@ -348,7 +348,7 @@ static void native_hpte_invalidate(unsigned long slot, unsigned long vpn,DBG_LOW (" invalidate(vpn=%016lx, hash: %lx)\n" , vpn, slot); - want_v =hpte_encode_v (vpn, psize, ssize); + want_v =hpte_encode_avpn (vpn, psize, ssize);native_lock_hpte (hptep); hpte_v = hptep->v;
@@ -520,7 +520,7 @@ static void native_flush_hash_range(unsigned long number, int local) slot = (hash & htab_hash_mask) *HPTES_PER_GROUP ; slot += hidx & _PTEIDX_GROUP_IX; hptep = htab_address + slot; - want_v =hpte_encode_v (vpn, psize, ssize); + want_v =hpte_encode_avpn (vpn, psize, ssize);native_lock_hpte (hptep); hpte_v = hptep->v; if (!HPTE_V_COMPARE(hpte_v, want_v) ||
arch/powerpc/platforms/cell/beat_htab.c +5 -5
@@ -191,7 +191,7 @@ static long beat_lpar_hpte_updatepp(unsigned long slot,u64 dummy0, dummy1;unsigned long want_v; - want_v =hpte_encode_v (vpn, psize,MMU_SEGSIZE_256M ); + want_v =hpte_encode_avpn (vpn, psize,MMU_SEGSIZE_256M ); DBG_LOW(" update: " "avpnv=%016lx, slot=%016lx, psize: %d, newpp %016lx ... ",
@@ -228,7 +228,7 @@ static long beat_lpar_hpte_find(unsigned long vpn, int psize)unsigned long want_v, hpte_v; hash =hpt_hash (vpn, mmu_psize_defs[psize].shift,MMU_SEGSIZE_256M ); - want_v =hpte_encode_v (vpn, psize,MMU_SEGSIZE_256M ); + want_v =hpte_encode_avpn (vpn, psize,MMU_SEGSIZE_256M );for (j =0 ; j <2 ; j++) { slot = (hash & htab_hash_mask) *HPTES_PER_GROUP ;
@@ -283,7 +283,7 @@ static void beat_lpar_hpte_invalidate(unsigned long slot, unsigned long vpn,DBG_LOW (" inval : slot=%lx, va=%016lx, psize: %d, local: %d\n" , slot, va, psize, local); - want_v =hpte_encode_v (vpn, psize,MMU_SEGSIZE_256M ); + want_v =hpte_encode_avpn (vpn, psize,MMU_SEGSIZE_256M );raw_spin_lock_irqsave (&beat_htab_lock, flags); dummy1 =beat_lpar_hpte_getword0 (slot);
@@ -372,7 +372,7 @@ static long beat_lpar_hpte_updatepp_v3(unsigned long slot,unsigned long want_v;unsigned long pss; - want_v =hpte_encode_v (vpn, psize,MMU_SEGSIZE_256M ); + want_v =hpte_encode_avpn (vpn, psize,MMU_SEGSIZE_256M ); pss = (psize ==MMU_PAGE_4K ) ?-1UL : mmu_psize_defs[psize].penc; DBG_LOW(" update: "
@@ -402,7 +402,7 @@ static void beat_lpar_hpte_invalidate_v3(unsigned long slot, unsigned long vpn,DBG_LOW (" inval : slot=%lx, vpn=%016lx, psize: %d, local: %d\n" , slot, vpn, psize, local); - want_v =hpte_encode_v (vpn, psize,MMU_SEGSIZE_256M ); + want_v =hpte_encode_avpn (vpn, psize,MMU_SEGSIZE_256M ); pss = (psize ==MMU_PAGE_4K ) ?-1UL : mmu_psize_defs[psize].penc; lpar_rc =beat_invalidate_htab_entry3 (0 , slot, want_v, pss);
arch/powerpc/platforms/ps3/htab.c +1 -1
@@ -117,7 +117,7 @@ static long ps3_hpte_updatepp(unsigned long slot, unsigned long newpp,unsigned long flags;long ret; - want_v =hpte_encode_v (vpn, psize, ssize); + want_v =hpte_encode_avpn (vpn, psize, ssize);spin_lock_irqsave (&ps3_htab_lock, flags);
Signature · 1 line
1.7.10
PATCH 11/27 powerpc: Decode the pte-lp-encoding bits correctly.
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We look at both the segment base page size and actual page size and store the pte-lp-encodings in an array per base page size.
We also update all relevant functions to take actual page size argument so that we can use the correct PTE LP encoding in HPTE. This should also get the basic Multiple Page Size per Segment (MPSS) support. This is needed to enable THP on ppc64.
--- arch/powerpc/include/asm/machdep.h | 3 +- arch/powerpc/include/asm/mmu-hash64.h | 33 ++++---- arch/powerpc/kvm/book3s_hv.c | 8 +- arch/powerpc/mm/hash_low_64.S | 18 +++-- arch/powerpc/mm/hash_native_64.c | 135 ++++++++++++++++++++++--------- arch/powerpc/mm/hash_utils_64.c | 121 +++++++++++++++++---------- arch/powerpc/mm/hugetlbpage-hash64.c | 4 +- arch/powerpc/platforms/cell/beat_htab.c | 16 ++-- arch/powerpc/platforms/ps3/htab.c | 6 +- arch/powerpc/platforms/pseries/lpar.c | 6 +- 10 files changed, 233 insertions(+), 117 deletions(-)
arch/powerpc/include/asm/machdep.h +2 -1
@@ -50,7 +50,8 @@ struct machdep_calls {unsigned long prpn, unsigned long rflags, unsigned long vflags, - int psize, int ssize); + int psize, int apsize, + int ssize);long (*hpte_remove)(unsigned long hpte_group);void (*hpte_removebolted)(unsigned long ea,int psize,int ssize);
arch/powerpc/include/asm/mmu-hash64.h +19 -14
@@ -155,7 +155,7 @@ extern unsigned long htab_hash_mask;struct mmu_psize_def {unsigned int shift;/* number of bits */ -unsigned int penc;/* HPTE encoding */ +int penc[MMU_PAGE_COUNT ];/* HPTE encoding */ unsigned int tlbiel;/* tlbiel supported for that page size */ unsigned long avpnm;/* bits to mask out in AVPN in the HPTE */ unsigned long sllp;/* SLB L||LP (exact mask to use in slbmte) */
@@ -200,6 +200,13 @@ static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize)*/ #define VPN_SHIFT 12 +/* +* HPTE Large Page (LP) details +*/ +#define LP_SHIFT 12 +#define LP_BITS 8 +#define LP_MASK (i) ((0xFF >> (i)) << LP_SHIFT) +#ifndef __ASSEMBLY__static inline int segment_shift (int ssize)
@@ -255,14 +262,14 @@ static inline unsigned long hpte_encode_avpn(unsigned long vpn, int psize,/* * This function sets the AVPN and L fields of the HPTE appropriately -* for the page size +* using the base page size and actual page size. */ -static inline unsigned long hpte_encode_v (unsigned long vpn, -int psize,int ssize) +static inline unsigned long hpte_encode_v (unsigned long vpn,int base_psize, +int actual_psize,int ssize) {unsigned long v; - v =hpte_encode_avpn (vpn, psize, ssize); -if (psize !=MMU_PAGE_4K ) + v =hpte_encode_avpn (vpn, base_psize, ssize); +if (actual_psize !=MMU_PAGE_4K ) v |=HPTE_V_LARGE ;return v; }
@@ -272,19 +279,17 @@ static inline unsigned long hpte_encode_v(unsigned long vpn,* for the page size. We assume the pa is already "clean" that is properly * aligned for the requested page size */ -static inline unsigned long hpte_encode_r (unsigned long pa,int psize) +static inline unsigned long hpte_encode_r (unsigned long pa,int base_psize, +int actual_psize) { -unsigned long r; -/* A 4K page needs no special encoding */ -if (psize ==MMU_PAGE_4K ) +if (actual_psize ==MMU_PAGE_4K )return pa &HPTE_R_RPN ;else { -unsigned int penc = mmu_psize_defs[psize].penc; -unsigned int shift = mmu_psize_defs[psize].shift; -return (pa & ~((1ul << shift) -1 )) | (penc <<12 ); +unsigned int penc = mmu_psize_defs[base_psize].penc[actual_psize]; +unsigned int shift = mmu_psize_defs[actual_psize].shift; +return (pa & ~((1ul << shift) -1 )) | (penc <<LP_SHIFT ); } -return r; }/*
arch/powerpc/kvm/book3s_hv.c +7 -1
@@ -1515,7 +1515,13 @@ static void kvmppc_add_seg_page_size(struct kvm_ppc_one_seg_page_size **sps, (*sps)->page_shift = def->shift; (*sps)->slb_enc = def->sllp; (*sps)->enc[0 ].page_shift = def->shift; - (*sps)->enc[0 ].pte_enc = def->penc; +/* +* Only return base page encoding. We don't want to return +* all the supporting pte_enc, because our H_ENTER doesn't +* support MPSS yet. Once they do, we can start passing all +* support pte_enc here +*/ + (*sps)->enc[0 ].pte_enc = def->penc[linux_psize]; (*sps)++; }
arch/powerpc/mm/hash_low_64.S +12 -6
@@ -196,7 +196,8 @@ htab_insert_pte: mr r4,r29 /* Retrieve vpn */ li r7,0 /* !bolted, !secondary */ li r8,MMU_PAGE_4K /* page size */ - ld r9,STK_PARAM(R9)(r1) /* segment size */ + li r9,MMU_PAGE_4K /* actual page size */ + ld r10,STK_PARAM(R9)(r1) /* segment size */ _GLOBAL(htab_call_hpte_insert1) bl . /* Patched by htab_finish_init() */ cmpdi 0,r3,0
@@ -219,7 +220,8 @@ _GLOBAL(htab_call_hpte_insert1) mr r4,r29 /* Retrieve vpn */ li r7,HPTE_V_SECONDARY /* !bolted, secondary */ li r8,MMU_PAGE_4K /* page size */ - ld r9,STK_PARAM(R9)(r1) /* segment size */ + li r9,MMU_PAGE_4K /* actual page size */ + ld r10,STK_PARAM(R9)(r1) /* segment size */ _GLOBAL(htab_call_hpte_insert2) bl . /* Patched by htab_finish_init() */ cmpdi 0,r3,0
@@ -515,7 +517,8 @@ htab_special_pfn: mr r4,r29 /* Retrieve vpn */ li r7,0 /* !bolted, !secondary */ li r8,MMU_PAGE_4K /* page size */ - ld r9,STK_PARAM(R9)(r1) /* segment size */ + li r9,MMU_PAGE_4K /* actual page size */ + ld r10,STK_PARAM(R9)(r1) /* segment size */ _GLOBAL(htab_call_hpte_insert1) bl . /* patched by htab_finish_init() */ cmpdi 0,r3,0
@@ -542,7 +545,8 @@ _GLOBAL(htab_call_hpte_insert1) mr r4,r29 /* Retrieve vpn */ li r7,HPTE_V_SECONDARY /* !bolted, secondary */ li r8,MMU_PAGE_4K /* page size */ - ld r9,STK_PARAM(R9)(r1) /* segment size */ + li r9,MMU_PAGE_4K /* actual page size */ + ld r10,STK_PARAM(R9)(r1) /* segment size */ _GLOBAL(htab_call_hpte_insert2) bl . /* patched by htab_finish_init() */ cmpdi 0,r3,0
@@ -840,7 +844,8 @@ ht64_insert_pte: mr r4,r29 /* Retrieve vpn */ li r7,0 /* !bolted, !secondary */ li r8,MMU_PAGE_64K - ld r9,STK_PARAM(R9)(r1) /* segment size */ + li r9,MMU_PAGE_64K /* actual page size */ + ld r10,STK_PARAM(R9)(r1) /* segment size */ _GLOBAL(ht64_call_hpte_insert1) bl . /* patched by htab_finish_init() */ cmpdi 0,r3,0
@@ -863,7 +868,8 @@ _GLOBAL(ht64_call_hpte_insert1) mr r4,r29 /* Retrieve vpn */ li r7,HPTE_V_SECONDARY /* !bolted, secondary */ li r8,MMU_PAGE_64K - ld r9,STK_PARAM(R9)(r1) /* segment size */ + li r9,MMU_PAGE_64K /* actual page size */ + ld r10,STK_PARAM(R9)(r1) /* segment size */ _GLOBAL(ht64_call_hpte_insert2) bl . /* patched by htab_finish_init() */ cmpdi 0,r3,0
arch/powerpc/mm/hash_native_64.c +98 -37
302 lines not on this page · raw message
arch/powerpc/mm/hash_utils_64.c +79 -42
183 lines not on this page · raw message
arch/powerpc/mm/hugetlbpage-hash64.c +2 -2
@@ -103,7 +103,7 @@ repeat:/* Insert into the hash table, primary slot */ slot = ppc_md.hpte_insert (hpte_group, vpn, pa, rflags,0 , - mmu_psize, ssize); + mmu_psize, mmu_psize, ssize);/* Primary is full, try the secondary */ if (unlikely (slot ==-1 )) {
@@ -111,7 +111,7 @@ repeat: HPTES_PER_GROUP) & ~0x7UL; slot = ppc_md.hpte_insert (hpte_group, vpn, pa, rflags,HPTE_V_SECONDARY , - mmu_psize, ssize); + mmu_psize, mmu_psize, ssize);if (slot ==-1 ) {if (mftb () &0x1 ) hpte_group = ((hash & htab_hash_mask) *
arch/powerpc/platforms/cell/beat_htab.c +8 -8
@@ -90,7 +90,7 @@ static inline unsigned int beat_read_mask(unsigned hpte_group)static long beat_lpar_hpte_insert (unsigned long hpte_group,unsigned long vpn,unsigned long pa,unsigned long rflags,unsigned long vflags, -int psize,int ssize) +int psize,int apsize,int ssize) {unsigned long lpar_rc;u64 hpte_v, hpte_r, slot;
@@ -103,9 +103,9 @@ static long beat_lpar_hpte_insert(unsigned long hpte_group,"rflags=%lx, vflags=%lx, psize=%d)\n" , hpte_group, va, pa, rflags, vflags, psize); - hpte_v =hpte_encode_v (vpn, psize,MMU_SEGSIZE_256M ) | + hpte_v =hpte_encode_v (vpn, psize, apsize,MMU_SEGSIZE_256M ) | vflags |HPTE_V_VALID ; - hpte_r =hpte_encode_r (pa, psize) | rflags; + hpte_r =hpte_encode_r (pa, psize, apsize) | rflags;if (!(vflags &HPTE_V_BOLTED ))DBG_LOW (" hpte_v=%016lx, hpte_r=%016lx\n" , hpte_v, hpte_r);
@@ -314,7 +314,7 @@ void __init hpte_init_beat(void)static long beat_lpar_hpte_insert_v3 (unsigned long hpte_group,unsigned long vpn,unsigned long pa,unsigned long rflags,unsigned long vflags, -int psize,int ssize) +int psize,int apsize,int ssize) {unsigned long lpar_rc;u64 hpte_v, hpte_r, slot;
@@ -327,9 +327,9 @@ static long beat_lpar_hpte_insert_v3(unsigned long hpte_group,"rflags=%lx, vflags=%lx, psize=%d)\n" , hpte_group, vpn, pa, rflags, vflags, psize); - hpte_v =hpte_encode_v (vpn, psize,MMU_SEGSIZE_256M ) | + hpte_v =hpte_encode_v (vpn, psize, apsize,MMU_SEGSIZE_256M ) | vflags |HPTE_V_VALID ; - hpte_r =hpte_encode_r (pa, psize) | rflags; + hpte_r =hpte_encode_r (pa, psize, apsize) | rflags;if (!(vflags &HPTE_V_BOLTED ))DBG_LOW (" hpte_v=%016lx, hpte_r=%016lx\n" , hpte_v, hpte_r);
@@ -373,7 +373,7 @@ static long beat_lpar_hpte_updatepp_v3(unsigned long slot,unsigned long pss; want_v =hpte_encode_avpn (vpn, psize,MMU_SEGSIZE_256M ); - pss = (psize ==MMU_PAGE_4K ) ?-1UL : mmu_psize_defs[psize].penc; + pss = (psize ==MMU_PAGE_4K ) ?-1UL : mmu_psize_defs[psize].penc[psize]; DBG_LOW(" update: " "avpnv=%016lx, slot=%016lx, psize: %d, newpp %016lx ... ",
@@ -403,7 +403,7 @@ static void beat_lpar_hpte_invalidate_v3(unsigned long slot, unsigned long vpn,DBG_LOW (" inval : slot=%lx, vpn=%016lx, psize: %d, local: %d\n" , slot, vpn, psize, local); want_v =hpte_encode_avpn (vpn, psize,MMU_SEGSIZE_256M ); - pss = (psize ==MMU_PAGE_4K ) ?-1UL : mmu_psize_defs[psize].penc; + pss = (psize ==MMU_PAGE_4K ) ?-1UL : mmu_psize_defs[psize].penc[psize]; lpar_rc =beat_invalidate_htab_entry3 (0 , slot, want_v, pss);
arch/powerpc/platforms/ps3/htab.c +3 -3
@@ -46,7 +46,7 @@ static DEFINE_SPINLOCK(ps3_htab_lock);static long ps3_hpte_insert (unsigned long hpte_group,unsigned long vpn,unsigned long pa,unsigned long rflags,unsigned long vflags, -int psize,int ssize) +int psize,int apsize,int ssize) {int result;u64 hpte_v, hpte_r;
@@ -62,8 +62,8 @@ static long ps3_hpte_insert(unsigned long hpte_group, unsigned long vpn,*/ vflags &= ~HPTE_V_SECONDARY ; - hpte_v =hpte_encode_v (vpn, psize, ssize) | vflags |HPTE_V_VALID ; - hpte_r =hpte_encode_r (ps3_mm_phys_to_lpar (pa), psize) | rflags; + hpte_v =hpte_encode_v (vpn, psize, apsize, ssize) | vflags |HPTE_V_VALID ; + hpte_r =hpte_encode_r (ps3_mm_phys_to_lpar (pa), psize, apsize) | rflags;spin_lock_irqsave (&ps3_htab_lock, flags);
arch/powerpc/platforms/pseries/lpar.c +3 -3
@@ -109,7 +109,7 @@ void vpa_init(int cpu)static long pSeries_lpar_hpte_insert (unsigned long hpte_group,unsigned long vpn,unsigned long pa,unsigned long rflags,unsigned long vflags, -int psize,int ssize) +int psize,int apsize,int ssize) {unsigned long lpar_rc;unsigned long flags;
@@ -121,8 +121,8 @@ static long pSeries_lpar_hpte_insert(unsigned long hpte_group,"pa=%016lx, rflags=%lx, vflags=%lx, psize=%d)\n" , hpte_group, vpn, pa, rflags, vflags, psize); - hpte_v =hpte_encode_v (vpn, psize, ssize) | vflags |HPTE_V_VALID ; - hpte_r =hpte_encode_r (pa, psize) | rflags; + hpte_v =hpte_encode_v (vpn, psize, apsize, ssize) | vflags |HPTE_V_VALID ; + hpte_r =hpte_encode_r (pa, psize, apsize) | rflags;if (!(vflags &HPTE_V_BOLTED ))pr_devel (" hpte_v=%016lx, hpte_r=%016lx\n" , hpte_v, hpte_r);
Signature · 1 line
1.7.10
PATCH 12/27 powerpc: Fix hpte_decode to use the correct decoding for page sizes
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
As per ISA doc, we encode base and actual page size in the LP bits of PTE. The number of bit used to encode the page sizes depend on actual page size. ISA doc lists this as
PTE LP actual page size
rrrr rrrz >=8KB
rrrr rrzz >=16KB
rrrr rzzz >=32KB
rrrr zzzz >=64KB
rrrz zzzz >=128KB
rrzz zzzz >=256KB
rzzz zzzz >=512KB
zzzz zzzz >=1MB
ISA doc also says
"The values of the “z” bits used to specify each size, along with all possible values of “r” bits in the LP field, must result in LP values distinct from other LP values for other sizes."
based on the above update hpte_decode to use the correct decoding for LP bits.
--- arch/powerpc/mm/hash_native_64.c | 53 ++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 31 deletions(-)
arch/powerpc/mm/hash_native_64.c +22 -31
@@ -245,19 +245,10 @@ static long native_hpte_remove(unsigned long hpte_group)return i; } -static inline int hpte_actual_psize (struct hash_pte *hptep,int psize) +static inline int __hpte_actual_psize (unsigned int lp,int psize) {int i, shift;unsigned int mask; -/* Look at the 8 bit LP value */ -unsigned int lp = (hptep->r >>LP_SHIFT ) & ((1 <<LP_BITS ) -1 ); - -if (!(hptep->v &HPTE_V_VALID )) -return -1 ; - -/* First check if it is large page */ -if (!(hptep->v &HPTE_V_LARGE )) -return MMU_PAGE_4K ;/* start from 1 ignoring MMU_PAGE_4K */ for (i =1 ; i <MMU_PAGE_COUNT ; i++) {
@@ -284,6 +275,21 @@ static inline int hpte_actual_psize(struct hash_pte *hptep, int psize)return -1 ; } +static inline int hpte_actual_psize (struct hash_pte *hptep,int psize) +{ +/* Look at the 8 bit LP value */ +unsigned int lp = (hptep->r >>LP_SHIFT ) & ((1 <<LP_BITS ) -1 ); + +if (!(hptep->v &HPTE_V_VALID )) +return -1 ; + +/* First check if it is large page */ +if (!(hptep->v &HPTE_V_LARGE )) +return MMU_PAGE_4K ; + +return __hpte_actual_psize (lp, psize); +} +static long native_hpte_updatepp (unsigned long slot,unsigned long newpp,unsigned long vpn,int psize,int ssize,int local)
@@ -425,42 +431,27 @@ static void hpte_decode(struct hash_pte *hpte, unsigned long slot, int *psize, int *apsize, int *ssize, unsigned long *vpn) { unsigned long avpn, pteg, vpi; -unsigned long hpte_r = hpte->r;unsigned long hpte_v = hpte->v;unsigned long vsid, seg_off; -int i, size, a_size, shift, penc; +int size, a_size, shift; +/* Look at the 8 bit LP value */ +unsigned int lp = (hpte->r >>LP_SHIFT ) & ((1 <<LP_BITS ) -1 );if (!(hpte_v &HPTE_V_LARGE )) { size =MMU_PAGE_4K ; a_size =MMU_PAGE_4K ; }else { -for (i =0 ; i <LP_BITS ; i++) { -if ((hpte_r &LP_MASK (i+1 )) ==LP_MASK (i+1 )) -break ; - } - penc =LP_MASK (i+1 ) >>LP_SHIFT ;for (size =0 ; size <MMU_PAGE_COUNT ; size++) {/* valid entries have a shift value */ if (!mmu_psize_defs[size].shift)continue ; -for (a_size =0 ; a_size <MMU_PAGE_COUNT ; a_size++) { - -/* 4K pages are not represented by LP */ -if (a_size ==MMU_PAGE_4K ) -continue ; -/* valid entries have a shift value */ -if (!mmu_psize_defs[a_size].shift) -continue ; - -if (penc == mmu_psize_defs[size].penc[a_size]) - goto out; - } + a_size =__hpte_actual_psize (lp, size); +if (a_size !=-1 ) +break ; } } - -out:/* This works for all page sizes, and for 256M and 1T segments */ *ssize = hpte_v >>HPTE_V_SSIZE_SHIFT ; shift = mmu_psize_defs[size].shift;
Signature · 1 line
1.7.10
PATCH 13/27 powerpc: print both base and actual page size on hash failure
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
--- arch/powerpc/include/asm/mmu-hash64.h | 3 ++- arch/powerpc/mm/hash_utils_64.c | 12 +++++++----- arch/powerpc/mm/hugetlbpage-hash64.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/mmu-hash64.h +2 -1
@@ -342,7 +342,8 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, unsigned int shift, unsigned int mmu_psize);extern void hash_failure_debug (unsigned long ea,unsigned long access,unsigned long vsid,unsigned long trap, -int ssize,int psize,unsigned long pte); +int ssize,int psize,int lpsize, +unsigned long pte);extern int htab_bolt_mapping (unsigned long vstart,unsigned long vend,unsigned long pstart,unsigned long prot,int psize,int ssize);
arch/powerpc/mm/hash_utils_64.c +7 -5
@@ -936,14 +936,14 @@ static inline int subpage_protection(struct mm_struct *mm, unsigned long ea)void hash_failure_debug (unsigned long ea,unsigned long access,unsigned long vsid,unsigned long trap, -int ssize,int psize,unsigned long pte) +int ssize,int psize,int lpsize,unsigned long pte) {if (!printk_ratelimit ())return ;pr_info ("mm: Hashing failure ! EA=0x%lx access=0x%lx current=%s\n" , ea, access, current->comm); -pr_info (" trap=0x%lx vsid=0x%lx ssize=%d psize=%d pte=0x%lx\n" , - trap, vsid, ssize, psize, pte); +pr_info (" trap=0x%lx vsid=0x%lx ssize=%d base psize=%d psize %d pte=0x%lx\n" , + trap, vsid, ssize, psize, lpsize, pte); }/* Result code is:
@@ -1116,7 +1116,7 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap)*/ if (rc ==-1 )hash_failure_debug (ea, access, vsid, trap, ssize, psize, -pte_val (*ptep)); + psize,pte_val (*ptep));#ifndef CONFIG_PPC_64K_PAGES DBG_LOW (" o-pte: %016lx\n" ,pte_val (*ptep));#else
@@ -1194,7 +1194,9 @@ void hash_preload(struct mm_struct *mm, unsigned long ea,*/ if (rc ==-1 )hash_failure_debug (ea, access, vsid, trap, ssize, - mm->context.user_psize,pte_val (*ptep)); + mm->context.user_psize, + mm->context.user_psize, +pte_val (*ptep));local_irq_restore (flags); }
arch/powerpc/mm/hugetlbpage-hash64.c +1 -1
@@ -129,7 +129,7 @@ repeat:if (unlikely (slot ==-2 )) { *ptep =__pte (old_pte);hash_failure_debug (ea, access, vsid, trap, ssize, - mmu_psize, old_pte); + mmu_psize, mmu_psize, old_pte);return -1 ; }
Signature · 1 line
1.7.10
PATCH 14/27 powerpc: Print page size info during boot
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This gives hint about different base and actual page size combination supported by the platform.
--- arch/powerpc/mm/hash_utils_64.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/mm/hash_utils_64.c +5 -5
@@ -316,7 +316,7 @@ static int __init htab_dt_scan_page_sizes(unsigned long node, prop = (u32 *)of_get_flat_dt_prop (node,"ibm,segment-page-sizes" , &size);if (prop !=NULL ) { -DBG ("Page sizes from device-tree:\n" ); +pr_info ("Page sizes from device-tree:\n" ); size /=4 ; cur_cpu_spec->mmu_features &= ~(MMU_FTR_16M_PAGE );while (size >0 ) {
@@ -370,10 +370,10 @@ static int __init htab_dt_scan_page_sizes(unsigned long node, "shift=%d\n", base_shift, shift); def->penc[idx] = penc; -DBG (" %d: shift=%02x, sllp=%04lx, " -"avpnm=%08lx, tlbiel=%d, penc=%d\n" , - idx, shift, def->sllp, def->avpnm, - def->tlbiel, def->penc[idx]); +pr_info ("base_shift=%d: shift=%d, sllp=0x%04lx," +" avpnm=0x%08lx, tlbiel=%d, penc=%d\n" , + base_shift, shift, def->sllp, + def->avpnm, def->tlbiel, def->penc[idx]); } }return 1 ;
Signature · 1 line
1.7.10
PATCH 15/27 powerpc: Update tlbie/tlbiel as per ISA doc
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
Encode the actual page correctly in tlbie/tlbiel. This make sure we handle multiple page size segment correctly.
--- arch/powerpc/mm/hash_native_64.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
arch/powerpc/mm/hash_native_64.c +30 -2
@@ -61,7 +61,10 @@ static inline void __tlbie(unsigned long vpn, int psize, int apsize, int ssize)switch (psize) {case MMU_PAGE_4K : +/* clear out bits after (52) [0....52.....63] */ + va &= ~((1ul << (64 -52 )) -1 ); va |= ssize <<8 ; + va |= mmu_psize_defs[apsize].sllp <<6 ; asm volatile(ASM_FTR_IFCLR("tlbie %0,0", PPC_TLBIE(%1,%0), %2) : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206) : "memory");
@@ -69,9 +72,20 @@ static inline void __tlbie(unsigned long vpn, int psize, int apsize, int ssize)default :/* We need 14 to 14 + i bits of va */ penc = mmu_psize_defs[psize].penc[apsize]; - va &= ~((1ul << mmu_psize_defs[psize].shift) -1 ); + va &= ~((1ul << mmu_psize_defs[apsize].shift) -1 ); va |= penc <<12 ; va |= ssize <<8 ; +/* Add AVAL part */ +if (psize != apsize) { +/* +* MPSS, 64K base page size and 16MB parge page size +* We don't need all the bits, but rest of the bits +* must be ignored by the processor. +* vpn cover upto 65 bits of va. (0...65) and we need +* 58..64 bits of va. +*/ + va |= (vpn &0xfe ); + } va |=1 ;/* L */ asm volatile(ASM_FTR_IFCLR("tlbie %0,1", PPC_TLBIE(%1,%0), %2) : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206)
@@ -96,16 +110,30 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)switch (psize) {case MMU_PAGE_4K : +/* clear out bits after(52) [0....52.....63] */ + va &= ~((1ul << (64 -52 )) -1 ); va |= ssize <<8 ; + va |= mmu_psize_defs[apsize].sllp <<6 ; asmvolatile (".long 0x7c000224 | (%0 << 11) | (0 << 21)" : :"r" (va) :"memory" );break ;default :/* We need 14 to 14 + i bits of va */ penc = mmu_psize_defs[psize].penc[apsize]; - va &= ~((1ul << mmu_psize_defs[psize].shift) -1 ); + va &= ~((1ul << mmu_psize_defs[apsize].shift) -1 ); va |= penc <<12 ; va |= ssize <<8 ; +/* Add AVAL part */ +if (psize != apsize) { +/* +* MPSS, 64K base page size and 16MB parge page size +* We don't need all the bits, but rest of the bits +* must be ignored by the processor. +* vpn cover upto 65 bits of va. (0...65) and we need +* 58..64 bits of va. +*/ + va |= (vpn &0xfe ); + } va |=1 ;/* L */ asmvolatile (".long 0x7c000224 | (%0 << 11) | (1 << 21)" : :"r" (va) :"memory" );
Signature · 1 line
1.7.10
PATCH 16/27 mm/THP: HPAGE_SHIFT is not a #define on some arch
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
On archs like powerpc that support different hugepage sizes, HPAGE_SHIFT and other derived values like HPAGE_PMD_ORDER are not constants. So move that to hugepage_init
--- include/linux/huge_mm.h | 3 --- mm/huge_memory.c | 9 ++++++--- 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/huge_mm.h +0 -3
@@ -119,9 +119,6 @@ extern void __split_huge_page_pmd(struct vm_area_struct *vma, }while (0 ) extern void split_huge_page_pmd_mm(struct mm_struct *mm, unsigned long address,pmd_t *pmd); -#if HPAGE_PMD_ORDER >MAX_ORDER -#error "hugepages can't be allocated by the buddy allocator" -#endif extern int hugepage_madvise (struct vm_area_struct *vma,unsigned long *vm_flags,int advice); extern void __vma_adjust_trans_huge(struct vm_area_struct *vma,
mm/huge_memory.c +6 -3
@@ -45,7 +45,7 @@ unsigned long transparent_hugepage_flags __read_mostly = (1 <<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG );/* default scan 8*512 pte (or vmas) every 30 second */ -static unsigned int khugepaged_pages_to_scan__read_mostly =HPAGE_PMD_NR *8 ; +static unsigned int khugepaged_pages_to_scan__read_mostly ;static unsigned int khugepaged_pages_collapsed;static unsigned int khugepaged_full_scans;static unsigned int khugepaged_scan_sleep_millisecs__read_mostly =10000 ;
@@ -60,7 +60,7 @@ static DECLARE_WAIT_QUEUE_HEAD(khugepaged_wait);* it would have happened if the vma was large enough during page * fault. */ -static unsigned int khugepaged_max_ptes_none__read_mostly =HPAGE_PMD_NR -1 ; +static unsigned int khugepaged_max_ptes_none__read_mostly ;static int khugepaged (void *none);static int khugepaged_slab_init (void );
@@ -620,11 +620,14 @@ static int __init hugepage_init(void)int err;struct kobject *hugepage_kobj; -if (!has_transparent_hugepage ()) { +if (!has_transparent_hugepage () || (HPAGE_PMD_ORDER >MAX_ORDER )) { transparent_hugepage_flags =0 ;return -EINVAL ; } + khugepaged_pages_to_scan =HPAGE_PMD_NR *8 ; + khugepaged_max_ptes_none =HPAGE_PMD_NR -1 ; + err =hugepage_init_sysfs (&hugepage_kobj);if (err)return err;
Signature · 1 line
1.7.10
Re: [PATCH -V6 16/27] mm/THP: HPAGE_SHIFT is not a #define on some arch
Quoted 10 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
On archs like powerpc that support different hugepage sizes,
HPAGE_SHIFTand other derived values likeHPAGE_PMD_ORDERare not constants. So move that tohugepage_initCc Andrea Arcangeli <[email protected]>Reviewed-by David Gibson <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>
PATCH 17/27 mm/THP: Add pmd args to pgtable deposit and withdraw APIs
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This will be later used by powerpc THP support. In powerpc we want to use pgtable for storing the hash index values. So instead of adding them to mm_context list, we would like to store them in the second half of pmd
--- arch/s390/include/asm/pgtable.h | 5 +++-- arch/s390/mm/pgtable.c | 5 +++-- arch/sparc/include/asm/pgtable_64.h | 5 +++-- arch/sparc/mm/tlb.c | 5 +++-- include/asm-generic/pgtable.h | 5 +++-- mm/huge_memory.c | 18 +++++++++--------- mm/pgtable-generic.c | 5 +++-- 7 files changed, 27 insertions(+), 21 deletions(-)
arch/s390/include/asm/pgtable.h +3 -2
@@ -1283,10 +1283,11 @@ static inline void __pmd_idte(unsigned long address, pmd_t *pmdp)#define SEGMENT_RW __pgprot(_HPAGE_TYPE_RW)#define __HAVE_ARCH_PGTABLE_DEPOSIT -extern void pgtable_trans_huge_deposit (struct mm_struct *mm,pgtable_t pgtable); +extern void pgtable_trans_huge_deposit (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pgtable);#define __HAVE_ARCH_PGTABLE_WITHDRAW -extern pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm); +extern pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm,pmd_t *pmdp);static inline int pmd_trans_splitting (pmd_t pmd) {
arch/s390/mm/pgtable.c +3 -2
@@ -920,7 +920,8 @@ void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address, } } -void pgtable_trans_huge_deposit (struct mm_struct *mm,pgtable_t pgtable) +void pgtable_trans_huge_deposit (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pgtable) {struct list_head *lh = (struct list_head *) pgtable;
@@ -934,7 +935,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable) mm->pmd_huge_pte = pgtable; } -pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm) +pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm,pmd_t *pmdp) {struct list_head *lh;pgtable_t pgtable;
arch/sparc/include/asm/pgtable_64.h +3 -2
@@ -853,10 +853,11 @@ extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd);#define __HAVE_ARCH_PGTABLE_DEPOSIT -extern void pgtable_trans_huge_deposit (struct mm_struct *mm,pgtable_t pgtable); +extern void pgtable_trans_huge_deposit (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pgtable);#define __HAVE_ARCH_PGTABLE_WITHDRAW -extern pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm); +extern pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm,pmd_t *pmdp);#endif /* Encode and de-code a swap entry */
arch/sparc/mm/tlb.c +3 -2
@@ -157,7 +157,8 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr, } } -void pgtable_trans_huge_deposit (struct mm_struct *mm,pgtable_t pgtable) +void pgtable_trans_huge_deposit (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pgtable) {struct list_head *lh = (struct list_head *) pgtable;
@@ -171,7 +172,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable) mm->pmd_huge_pte = pgtable; } -pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm) +pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm,pmd_t *pmdp) {struct list_head *lh;pgtable_t pgtable;
include/asm-generic/pgtable.h +3 -2
@@ -163,11 +163,12 @@ extern void pmdp_splitting_flush(struct vm_area_struct *vma,#endif #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT -extern void pgtable_trans_huge_deposit (struct mm_struct *mm,pgtable_t pgtable); +extern void pgtable_trans_huge_deposit (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pgtable);#endif #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW -extern pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm); +extern pgtable_t pgtable_trans_huge_withdraw (struct mm_struct *mm,pmd_t *pmdp);#endif #ifndef __HAVE_ARCH_PMDP_INVALIDATE
mm/huge_memory.c +9 -9
@@ -735,7 +735,7 @@ static int __do_huge_pmd_anonymous_page(struct mm_struct *mm,*/ page_add_new_anon_rmap (page, vma, haddr);set_pmd_at (mm, haddr, pmd, entry); -pgtable_trans_huge_deposit (mm, pgtable); +pgtable_trans_huge_deposit (mm, pmd, pgtable);add_mm_counter (mm,MM_ANONPAGES ,HPAGE_PMD_NR ); mm->nr_ptes++;spin_unlock (&mm->page_table_lock);
@@ -777,7 +777,7 @@ static bool set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm, entry =pmd_wrprotect (entry); entry =pmd_mkhuge (entry);set_pmd_at (mm, haddr, pmd, entry); -pgtable_trans_huge_deposit (mm, pgtable); +pgtable_trans_huge_deposit (mm, pmd, pgtable); mm->nr_ptes++;return true; }
@@ -922,7 +922,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,pmdp_set_wrprotect (src_mm, addr, src_pmd); pmd =pmd_mkold (pmd_wrprotect (pmd));set_pmd_at (dst_mm, addr, dst_pmd, pmd); -pgtable_trans_huge_deposit (dst_mm, pgtable); +pgtable_trans_huge_deposit (dst_mm, dst_pmd, pgtable); dst_mm->nr_ptes++; ret =0 ;
@@ -992,7 +992,7 @@ static int do_huge_pmd_wp_zero_page_fallback(struct mm_struct *mm,pmdp_clear_flush (vma, haddr, pmd);/* leave pmd empty until pte is filled */ - pgtable =pgtable_trans_huge_withdraw (mm); + pgtable =pgtable_trans_huge_withdraw (mm, pmd);pmd_populate (mm, &_pmd, pgtable);for (i =0 ; i <HPAGE_PMD_NR ; i++, haddr +=PAGE_SIZE ) {
@@ -1087,10 +1087,10 @@ static int do_huge_pmd_wp_page_fallback(struct mm_struct *mm, goto out_free_pages;VM_BUG_ON (!PageHead (page)); + pgtable =pgtable_trans_huge_withdraw (mm, pmd);pmdp_clear_flush (vma, haddr, pmd);/* leave pmd empty until pte is filled */ - pgtable =pgtable_trans_huge_withdraw (mm);pmd_populate (mm, &_pmd, pgtable);for (i =0 ; i <HPAGE_PMD_NR ; i++, haddr +=PAGE_SIZE ) {
@@ -1363,7 +1363,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page;pgtable_t pgtable;pmd_t orig_pmd; - pgtable =pgtable_trans_huge_withdraw (tlb->mm); + pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd); orig_pmd =pmdp_get_and_clear (tlb->mm, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr);if (is_huge_zero_pmd (orig_pmd)) {
@@ -1695,7 +1695,7 @@ static int __split_huge_page_map(struct page *page, pmd =page_check_address_pmd (page, mm, address,PAGE_CHECK_ADDRESS_PMD_SPLITTING_FLAG );if (pmd) { - pgtable =pgtable_trans_huge_withdraw (mm); + pgtable =pgtable_trans_huge_withdraw (mm, pmd);pmd_populate (mm, &_pmd, pgtable); haddr = address;
@@ -2352,7 +2352,7 @@ static void collapse_huge_page(struct mm_struct *mm,page_add_new_anon_rmap (new_page, vma, address);set_pmd_at (mm, address, pmd, _pmd);update_mmu_cache_pmd (vma, address, pmd); -pgtable_trans_huge_deposit (mm, pgtable); +pgtable_trans_huge_deposit (mm, pmd, pgtable);spin_unlock (&mm->page_table_lock); *hpage =NULL ;
@@ -2658,7 +2658,7 @@ static void __split_huge_zero_page_pmd(struct vm_area_struct *vma,pmdp_clear_flush (vma, haddr, pmd);/* leave pmd empty until pte is filled */ - pgtable =pgtable_trans_huge_withdraw (mm); + pgtable =pgtable_trans_huge_withdraw (mm, pmd);pmd_populate (mm, &_pmd, pgtable);for (i =0 ; i <HPAGE_PMD_NR ; i++, haddr +=PAGE_SIZE ) {
mm/pgtable-generic.c +3 -2
@@ -124,7 +124,8 @@ void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address, #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT #ifdef CONFIG_TRANSPARENT_HUGEPAGE -void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable) +void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp, + pgtable_t pgtable) { assert_spin_locked(&mm->page_table_lock);
@@ -141,7 +142,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable) #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* no "address" argument so destroys page coloring of some arch */ -pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm) +pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp) { pgtable_t pgtable;
Signature · 1 line
1.7.10
Re: [PATCH -V6 17/27] mm/THP: Add pmd args to pgtable deposit and withdraw APIs
Quoted 7 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
This will be later used by powerpc THP support. In powerpc we want to use pgtable for storing the hash index values. So instead of adding them to
mm_contextlist, we would like to store them in the second half of pmdCc Andrea Arcangeli <[email protected]>
*snip*
Quoted 9 lines
#ifndef
__HAVE_ARCH_PGTABLE_DEPOSIT
#ifdefCONFIG_TRANSPARENT_HUGEPAGEmm/pgtable-generic.c +2
-1-void pgtable_trans_huge_deposit (struct mm_struct *mm,pgtable_t pgtable) +void pgtable_trans_huge_deposit (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pgtable) {assert_spin_locked (&mm->page_table_lock);
mm/pgtable-generic.c void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable) · line 147
Quoted 7 lines
mm/pgtable-generic.c +1
-1@@ -141,7 +142,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable) #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* no "address" argument so destroys page coloring of some arch */ -pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm) +pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp) { pgtable_t pgtable;
This will add micro overhead with more variables put in certain regs or stack. The micro overhead could be optimized away by wrapping the call with a generic and per-arch header and by adding a __ prefix to the above one in the generic .c file. I'm neutral but I pointed out so others are free to comment on it.
PATCH 18/27 mm/THP: withdraw the pgtable after pmdp related operations
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
For architectures like ppc64 we look at deposited pgtable when calling pmdp_get_and_clear. So do the pgtable_trans_huge_withdraw after finishing pmdp related operations.
--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/huge_memory.c +2 -1
@@ -1363,9 +1363,10 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page;pgtable_t pgtable;pmd_t orig_pmd; - pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd); + orig_pmd =pmdp_get_and_clear (tlb->mm, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr); + pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd);if (is_huge_zero_pmd (orig_pmd)) { tlb->mm->nr_ptes--;spin_unlock (&tlb->mm->page_table_lock);
Signature · 1 line
1.7.10
Re: [PATCH -V6 18/27] mm/THP: withdraw the pgtable after pmdp related operations
Hi,
Quoted 18 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
For architectures like ppc64 we look at deposited pgtable when calling
pmdp_get_and_clear. So do thepgtable_trans_huge_withdrawafter finishing pmdp related operations.Cc Andrea Arcangeli <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/huge_memory.c +0
-0@@ -1363,9 +1363,10 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page;
mm/huge_memory.c int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, · line 1372
Quoted 10 lines
mm/huge_memory.c +2
-1pgtable_t pgtable;pmd_t orig_pmd; - pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd); + orig_pmd =pmdp_get_and_clear (tlb->mm, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr); + pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd);if (is_huge_zero_pmd (orig_pmd)) { tlb->mm->nr_ptes--;spin_unlock (&tlb->mm->page_table_lock);
I think here a comment inline (not only in the commit msg) is in order. Otherwise it's hard to imagine others to be aware of this arch detail when they will read the code later. So it would be prone to break later without a comment.
Thanks,
Andrea
Re: [PATCH -V6 18/27] mm/THP: withdraw the pgtable after pmdp related operations
Quoted 28 lines · Andrea Arcangeli
Hi,
Quoted 25 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
For architectures like ppc64 we look at deposited pgtable when calling
pmdp_get_and_clear. So do thepgtable_trans_huge_withdrawafter finishing pmdp related operations.Cc Andrea Arcangeli <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/huge_memory.c +2
-1@@ -1363,9 +1363,10 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page;pgtable_t pgtable;pmd_t orig_pmd; - pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd); + orig_pmd =pmdp_get_and_clear (tlb->mm, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr); + pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd);
Quoted 8 lines
mm/huge_memory.c int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, · line 1372
Quoted 3 lines
mm/huge_memory.c +0
-0if (is_huge_zero_pmd (orig_pmd)) { tlb->mm->nr_ptes--;spin_unlock (&tlb->mm->page_table_lock);I think here a comment inline (not only in the commit msg) is in order. Otherwise it's hard to imagine others to be aware of this arch detail when they will read the code later. So it would be prone to break later without a comment.
How about ?
Quoted 1 line
From
7444a5eda33c00eea465b51c405cb830c57513b7Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Wed, 6 Mar 2013 12:50:37 +0530
Subject: [PATCH] mm/THP: withdraw the pgtable after pmdp related operations
For architectures like ppc64 we look at deposited pgtable when calling pmdp_get_and_clear. So do the pgtable_trans_huge_withdraw after finishing pmdp related operations.
--- mm/huge_memory.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
mm/huge_memory.c +7 -1
@@ -1363,9 +1363,15 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page;pgtable_t pgtable;pmd_t orig_pmd; - pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd); +/* +* For architectures like ppc64 we look at deposited pgtable +* when calling pmdp_get_and_clear. So do the +* pgtable_trans_huge_withdraw after finishing pmdp related +* operations. +*/ orig_pmd =pmdp_get_and_clear (tlb->mm, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr); + pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd);if (is_huge_zero_pmd (orig_pmd)) { tlb->mm->nr_ptes--;spin_unlock (&tlb->mm->page_table_lock);
Signature · 1 line
1.7.10
Andrea Arcangeli
Reviewed-byRe: [PATCH -V6 18/27] mm/THP: withdraw the pgtable after pmdp related operations
Hi,
Quoted 9 lines · Aneesh Kumar K.V
From
7444a5eda33c00eea465b51c405cb830c57513b7Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Wed, 6 Mar 2013 12:50:37 +0530
Subject: [PATCH] mm/THP: withdraw the pgtable after pmdp related operationsFor architectures like ppc64 we look at deposited pgtable when calling
pmdp_get_and_clear. So do thepgtable_trans_huge_withdrawafter finishing pmdp related operations.
Quoted 5 lines
Cc Andrea Arcangeli <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- mm/huge_memory.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 9 lines
mm/huge_memory.c +0
-0@@ -1363,9 +1363,15 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page;pgtable_t pgtable;pmd_t orig_pmd;
mm/huge_memory.c int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, · line 1374
Quoted 10 lines
mm/huge_memory.c +7
-1- pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd); +/* +* For architectures like ppc64 we look at deposited pgtable +* when calling pmdp_get_and_clear. So do the +* pgtable_trans_huge_withdraw after finishing pmdp related +* operations. +*/ orig_pmd =pmdp_get_and_clear (tlb->mm, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr); + pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd);
So I assume you're going to check the pmdp pointer address in _withdraw, as the *pmd content is already clear. And that you're checking the deposited pmd earlier in pmdp_get_and_clear. A bit strange overall not seeing how exactly you're using the new parameter and the deposited pmds, but safe.
Thanks,
Andrea
Re: [PATCH -V6 18/27] mm/THP: withdraw the pgtable after pmdp related operations
Quoted 35 lines · Andrea Arcangeli
Hi,
Quoted 9 lines · Aneesh Kumar K.V
From
7444a5eda33c00eea465b51c405cb830c57513b7Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <[email protected]>
Date: Wed, 6 Mar 2013 12:50:37 +0530
Subject: [PATCH] mm/THP: withdraw the pgtable after pmdp related operationsFor architectures like ppc64 we look at deposited pgtable when calling
pmdp_get_and_clear. So do thepgtable_trans_huge_withdrawafter finishing pmdp related operations.Quoted 5 lines
Cc Andrea Arcangeli <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- mm/huge_memory.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Reviewed-by Andrea Arcangeli <[email protected]>Quoted 15 lines
mm/huge_memory.c +5
-1@@ -1363,9 +1363,15 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,struct page *page;pgtable_t pgtable;pmd_t orig_pmd; - pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd); +/* +* For architectures like ppc64 we look at deposited pgtable +* when calling pmdp_get_and_clear. So do the +* pgtable_trans_huge_withdraw after finishing pmdp related +* operations.
Quoted 8 lines
mm/huge_memory.c int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, · line 1374
Quoted 4 lines
mm/huge_memory.c +2
-0+*/ orig_pmd =pmdp_get_and_clear (tlb->mm, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr); + pgtable =pgtable_trans_huge_withdraw (tlb->mm, pmd);So I assume you're going to check the pmdp pointer address in
_withdraw, as the *pmd content is already clear. And that you're checking the deposited pmd earlier inpmdp_get_and_clear.
Yes.
Quoted 3 lines
A bit
strange overall not seeing how exactly you're using the new parameter and the deposited pmds, but safe.
That patch inlined below shows how we are using the new parameter. hpte_need_hugepage_flush() shows the usage.You can find the full series at
https://lists.ozlabs.org/pipermail/linuxppc-dev/2013-April/105614.html
commit d77e766dc211e68208d527476d5f71aa0e06aae9
Author: Aneesh Kumar K.V <[email protected]> Date: Wed Mar 6 12:50:37 2013 +0530
powerpc/THP: Implement transparent hugepages for ppc64
We now have pmd entries covering 16MB range and the PMD table double its original size. We use the second half of the PMD table to deposit the pgtable (PTE page). The depoisted PTE page is further used to track the HPTE information. The information include [ secondary group | 3 bit hidx | valid ]. We use one byte per each HPTE entry. With 16MB hugepage and 64K HPTE we need 256 entries and with 4K HPTE we need 4096 entries. Both will fit in a 4K PTE page. On hugepage invalidate we need to walk the PTE page and invalidate all valid HPTEs.
This patch implements necessary arch specific functions for THP support and also hugepage invalidate logic. These PMD related functions are intentionally kept similar to their PTE counter-part.
arch/powerpc/include/asm/page.h +10 -1
@@ -37,8 +37,17 @@#define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)#ifndef __ASSEMBLY__ -#ifdef CONFIG_HUGETLB_PAGE +/* +* With hugetlbfs enabled we allow the HPAGE_SHIFT to run time +* configurable. But we enable THP only with 16MB hugepage. +* With only THP configured, we force hugepage size to 16MB. +* This should ensure that all subarchs that doesn't support +* THP continue to work fine with HPAGE_SHIFT usage. +*/ +#if defined(CONFIG_HUGETLB_PAGE )extern unsigned int HPAGE_SHIFT ; +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE ) +#define HPAGE_SHIFT PMD_SHIFT#else #define HPAGE_SHIFT PAGE_SHIFT#endif
arch/powerpc/include/asm/pgtable-ppc64-64k.h +2 -1
@@ -33,7 +33,8 @@#define PGDIR_MASK (~(PGDIR_SIZE-1))/* Bits to mask out from a PMD to get to the PTE page */ -#define PMD_MASKED_BITS 0x1ff +/* PMDs point to PTE table fragments which are 4K aligned. */ +#define PMD_MASKED_BITS 0xfff/* Bits to mask out from a PGD/PUD to get to the PMD page */ #define PUD_MASKED_BITS 0x1ff
arch/powerpc/include/asm/pgtable-ppc64.h +258 -1
269 lines not on this page · raw message
arch/powerpc/include/asm/pgtable.h +5 -0
@@ -222,5 +222,10 @@ extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, unsigned long end, int write, struct page **pages, int *nr);#endif /* __ASSEMBLY__ */ +#ifndef CONFIG_TRANSPARENT_HUGEPAGE +#define pmd_large (pmd) 0 +#define has_transparent_hugepage () 0 +#endif +#endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_PGTABLE_H */
arch/powerpc/include/asm/pte-hash64-64k.h +17 -0
@@ -38,6 +38,23 @@*/ #define PTE_RPN_SHIFT (30) +/* +* THP pages can't be special. So use the _PAGE_SPECIAL +*/ +#define _PAGE_SPLITTING _PAGE_SPECIAL + +/* +* PTE flags to conserve for HPTE identification for THP page. +* We drop _PAGE_COMBO here, because we overload that with _PAGE_TH_HUGE. +*/ +#define _PAGE_THP_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE) + +/* +* We need to differentiate between explicit huge page and THP huge +* page, since THP huge page also need to track real subpage details +*/ +#define _PAGE_THP_HUGE _PAGE_COMBO +#ifndef __ASSEMBLY__/*
arch/powerpc/mm/pgtable_64.c +318 -0
327 lines not on this page · raw message
arch/powerpc/platforms/Kconfig.cputype +1 -0
@@ -71,6 +71,7 @@ config PPC_BOOK3S_64 select PPC_FPU select PPC_HAVE_PMU_SUPPORT select SYS_SUPPORTS_HUGETLBFS + select HAVE_ARCH_TRANSPARENT_HUGEPAGE if PPC_64K_PAGES config PPC_BOOK3E_64 bool "Embedded processors"
PATCH 19/27 powerpc/THP: Double the PMD table size for THP
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
THP code does PTE page allocation along with large page request and deposit them for later use. This is to ensure that we won't have any failures when we split hugepages to regular pages.
On powerpc we want to use the deposited PTE page for storing hash pte slot and secondary bit information for the HPTEs. We use the second half of the pmd table to save the deposted PTE page.
--- arch/powerpc/include/asm/pgalloc-64.h | 6 +++--- arch/powerpc/include/asm/pgtable-ppc64.h | 6 +++++- arch/powerpc/mm/init_64.c | 9 ++++++--- 3 files changed, 14 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/pgalloc-64.h +3 -3
@@ -221,17 +221,17 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,static inline pmd_t *pmd_alloc_one (struct mm_struct *mm,unsigned long addr) { -return kmem_cache_alloc (PGT_CACHE (PMD_INDEX_SIZE ), +return kmem_cache_alloc (PGT_CACHE (PMD_CACHE_INDEX ),GFP_KERNEL |__GFP_REPEAT); }static inline void pmd_free (struct mm_struct *mm,pmd_t *pmd) { -kmem_cache_free (PGT_CACHE (PMD_INDEX_SIZE ), pmd); +kmem_cache_free (PGT_CACHE (PMD_CACHE_INDEX ), pmd); }#define __pmd_free_tlb (tlb, pmd, addr) \ - pgtable_free_tlb(tlb, pmd, PMD_INDEX_SIZE) + pgtable_free_tlb(tlb, pmd, PMD_CACHE_INDEX)#ifndef CONFIG_PPC_64K_PAGES #define __pud_free_tlb (tlb, pud, addr) \ pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE)
arch/powerpc/include/asm/pgtable-ppc64.h +5 -1
@@ -20,7 +20,11 @@ PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT)#define PGTABLE_RANGE (ASM_CONST(1) << PGTABLE_EADDR_SIZE) - +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#define PMD_CACHE_INDEX (PMD_INDEX_SIZE + 1) +#else +#define PMD_CACHE_INDEX PMD_INDEX_SIZE +#endif /* * Define the address range of the kernel non-linear virtual area */
arch/powerpc/mm/init_64.c +6 -3
@@ -88,7 +88,11 @@ static void pgd_ctor(void *addr)static void pmd_ctor (void *addr) { +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +memset (addr,0 ,PMD_TABLE_SIZE *2 ); +#else memset (addr,0 ,PMD_TABLE_SIZE ); +#endif }struct kmem_cache *pgtable_cache[MAX_PGTABLE_INDEX_SIZE ];
@@ -137,10 +141,9 @@ void pgtable_cache_add(unsigned shift, void (*ctor)(void *))void pgtable_cache_init (void ) {pgtable_cache_add (PGD_INDEX_SIZE , pgd_ctor); -pgtable_cache_add (PMD_INDEX_SIZE , pmd_ctor); -if (!PGT_CACHE (PGD_INDEX_SIZE ) || !PGT_CACHE (PMD_INDEX_SIZE )) +pgtable_cache_add (PMD_CACHE_INDEX , pmd_ctor); +if (!PGT_CACHE (PGD_INDEX_SIZE ) || !PGT_CACHE (PMD_CACHE_INDEX ))panic ("Couldn't allocate pgtable caches" ); -/* In all current configs, when the PUD index exists it's the * same size as either the pgd or pmd index. Verify that the * initialization above has also created a PUD cache. This
Signature · 1 line
1.7.10
PATCH 20/27 powerpc/THP: Implement transparent hugepages for ppc64
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We now have pmd entries covering 16MB range and the PMD table double its original size. We use the second half of the PMD table to deposit the pgtable (PTE page). The depoisted PTE page is further used to track the HPTE information. The information include [ secondary group | 3 bit hidx | valid ]. We use one byte per each HPTE entry. With 16MB hugepage and 64K HPTE we need 256 entries and with 4K HPTE we need 4096 entries. Both will fit in a 4K PTE page. On hugepage invalidate we need to walk the PTE page and invalidate all valid HPTEs.
This patch implements necessary arch specific functions for THP support and also hugepage invalidate logic. These PMD related functions are intentionally kept similar to their PTE counter-part.
--- arch/powerpc/include/asm/page.h | 11 +- arch/powerpc/include/asm/pgtable-ppc64-64k.h | 3 +- arch/powerpc/include/asm/pgtable-ppc64.h | 259 ++++++++++++++++++++- arch/powerpc/include/asm/pgtable.h | 5 + arch/powerpc/include/asm/pte-hash64-64k.h | 17 ++ arch/powerpc/mm/pgtable_64.c | 318 ++++++++++++++++++++++++++ arch/powerpc/platforms/Kconfig.cputype | 1 + 7 files changed, 611 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/page.h +10 -1
@@ -37,8 +37,17 @@#define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)#ifndef __ASSEMBLY__ -#ifdef CONFIG_HUGETLB_PAGE +/* +* With hugetlbfs enabled we allow the HPAGE_SHIFT to run time +* configurable. But we enable THP only with 16MB hugepage. +* With only THP configured, we force hugepage size to 16MB. +* This should ensure that all subarchs that doesn't support +* THP continue to work fine with HPAGE_SHIFT usage. +*/ +#if defined(CONFIG_HUGETLB_PAGE )extern unsigned int HPAGE_SHIFT ; +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE ) +#define HPAGE_SHIFT PMD_SHIFT#else #define HPAGE_SHIFT PAGE_SHIFT#endif
arch/powerpc/include/asm/pgtable-ppc64-64k.h +2 -1
@@ -33,7 +33,8 @@#define PGDIR_MASK (~(PGDIR_SIZE-1))/* Bits to mask out from a PMD to get to the PTE page */ -#define PMD_MASKED_BITS 0x1ff +/* PMDs point to PTE table fragments which are 4K aligned. */ +#define PMD_MASKED_BITS 0xfff/* Bits to mask out from a PGD/PUD to get to the PMD page */ #define PUD_MASKED_BITS 0x1ff
arch/powerpc/include/asm/pgtable-ppc64.h +258 -1
269 lines not on this page · raw message
arch/powerpc/include/asm/pgtable.h +5 -0
@@ -222,5 +222,10 @@ extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, unsigned long end, int write, struct page **pages, int *nr);#endif /* __ASSEMBLY__ */ +#ifndef CONFIG_TRANSPARENT_HUGEPAGE +#define pmd_large (pmd) 0 +#define has_transparent_hugepage () 0 +#endif +#endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_PGTABLE_H */
arch/powerpc/include/asm/pte-hash64-64k.h +17 -0
@@ -38,6 +38,23 @@*/ #define PTE_RPN_SHIFT (30) +/* +* THP pages can't be special. So use the _PAGE_SPECIAL +*/ +#define _PAGE_SPLITTING _PAGE_SPECIAL + +/* +* PTE flags to conserve for HPTE identification for THP page. +* We drop _PAGE_COMBO here, because we overload that with _PAGE_TH_HUGE. +*/ +#define _PAGE_THP_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE) + +/* +* We need to differentiate between explicit huge page and THP huge +* page, since THP huge page also need to track real subpage details +*/ +#define _PAGE_THP_HUGE _PAGE_COMBO +#ifndef __ASSEMBLY__/*
arch/powerpc/mm/pgtable_64.c +318 -0
327 lines not on this page · raw message
arch/powerpc/platforms/Kconfig.cputype +1 -0
@@ -71,6 +71,7 @@ config PPC_BOOK3S_64 select PPC_FPU select PPC_HAVE_PMU_SUPPORT select SYS_SUPPORTS_HUGETLBFS + select HAVE_ARCH_TRANSPARENT_HUGEPAGE if PPC_64K_PAGES config PPC_BOOK3E_64 bool "Embedded processors"
Signature · 1 line
1.7.10
PATCH 21/27 powerpc: move find_linux_pte_or_hugepte and gup_hugepte to common code
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We will use this in the later patch for handling THP pages
--- arch/powerpc/include/asm/hugetlb.h | 8 +- arch/powerpc/include/asm/pgtable-ppc64.h | 11 -- arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/hugetlbpage.c | 251 +++++++++++++++--------------- 4 files changed, 136 insertions(+), 136 deletions(-)
arch/powerpc/include/asm/hugetlb.h +7 -1
@@ -169,8 +169,14 @@ static inline void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr) { } -#endif /* CONFIG_HUGETLB_PAGE */ +#define hugepd_shift (x) 0 +static inline pte_t *hugepte_offset (hugepd_t *hpdp,unsigned long addr, +unsigned pdshift) +{ +return 0 ; +} +#endif /* CONFIG_HUGETLB_PAGE */ /* * FSL Book3E platforms require special gpage handling - the gpages
arch/powerpc/include/asm/pgtable-ppc64.h +0 -11
@@ -367,19 +367,8 @@ static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea) return pt; } -#ifdef CONFIG_HUGETLB_PAGE pte_t *find_linux_pte_or_hugepte (pgd_t *pgdir,unsigned long ea,unsigned *shift); -#else -static inline pte_t *find_linux_pte_or_hugepte (pgd_t *pgdir,unsigned long ea, -unsigned *shift) -{ -if (shift) - *shift =0 ; -return find_linux_pte (pgdir, ea); -} -#endif /* !CONFIG_HUGETLB_PAGE */ -#endif /* __ASSEMBLY__ */ #ifndef _PAGE_SPLITTING
arch/powerpc/mm/Makefile +1 -1
@@ -28,8 +28,8 @@ obj-$(CONFIG_44x) += 44x_mmu.o obj-$(CONFIG_PPC_FSL_BOOK3E) += fsl_booke_mmu.o obj-$(CONFIG_NEED_MULTIPLE_NODES) += numa.o obj-$(CONFIG_PPC_MM_SLICES) += slice.o -ifeq ($(CONFIG_HUGETLB_PAGE),y) obj-y += hugetlbpage.o +ifeq ($(CONFIG_HUGETLB_PAGE),y) obj-$(CONFIG_PPC_STD_MMU_64) += hugetlbpage-hash64.o obj-$(CONFIG_PPC_BOOK3E_MMU) += hugetlbpage-book3e.o endif
arch/powerpc/mm/hugetlbpage.c +128 -123
272 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 22/27 powerpc: Update find_linux_pte_or_hugepte to handle transparent hugepages
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
--- arch/powerpc/mm/hugetlbpage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/mm/hugetlbpage.c +1 -1
@@ -949,7 +949,7 @@ pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, unsigned *shift pdshift =PMD_SHIFT ; pm =pmd_offset (pu, ea); -if (pmd_huge (*pm)) { +if (pmd_huge (*pm) ||pmd_large (*pm)) { ret_pte = (pte_t *) pm; goto out; }else if (is_hugepd (pm))
Signature · 1 line
1.7.10
PATCH 23/27 powerpc: Replace find_linux_pte with find_linux_pte_or_hugepte
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
Replace find_linux_pte with find_linux_pte_or_hugepte and explicitly document why we don't need to handle transparent hugepages at callsites.
--- arch/powerpc/include/asm/pgtable-ppc64.h | 24 ------------------------ arch/powerpc/kernel/io-workarounds.c | 10 ++++++++-- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 4 +++- arch/powerpc/mm/hash_utils_64.c | 8 +++++++- arch/powerpc/mm/hugetlbpage.c | 8 ++++++-- arch/powerpc/mm/tlb_hash64.c | 7 ++++++- arch/powerpc/platforms/pseries/eeh.c | 7 ++++++- 7 files changed, 36 insertions(+), 32 deletions(-)
arch/powerpc/include/asm/pgtable-ppc64.h +0 -24
@@ -343,30 +343,6 @@ static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)void pgtable_cache_add (unsigned shift,void (*ctor)(void *));void pgtable_cache_init (void ); - -/* -* find_linux_pte returns the address of a linux pte for a given -* effective address and directory. If not found, it returns zero. -*/ -static inline pte_t *find_linux_pte (pgd_t *pgdir,unsigned long ea) -{ -pgd_t *pg; -pud_t *pu; -pmd_t *pm; -pte_t *pt =NULL ; - - pg = pgdir +pgd_index (ea); -if (!pgd_none (*pg)) { - pu =pud_offset (pg, ea); -if (!pud_none (*pu)) { - pm =pmd_offset (pu, ea); -if (pmd_present (*pm)) - pt =pte_offset_kernel (pm, ea); - } - } -return pt; -} -pte_t *find_linux_pte_or_hugepte (pgd_t *pgdir,unsigned long ea,unsigned *shift);#endif /* __ASSEMBLY__ */
arch/powerpc/kernel/io-workarounds.c +8 -2
@@ -55,6 +55,7 @@ static struct iowa_bus *iowa_pci_find(unsigned long vaddr, unsigned long paddr)struct iowa_bus *iowa_mem_find_bus (const PCI_IO_ADDR addr) { +unsigned shift;struct iowa_bus *bus;int token;
@@ -70,11 +71,16 @@ struct iowa_bus *iowa_mem_find_bus(const PCI_IO_ADDR addr)if (vaddr <PHB_IO_BASE || vaddr >=PHB_IO_END )return NULL ; - ptep =find_linux_pte (init_mm.pgd, vaddr); + ptep =find_linux_pte_or_hugepte (init_mm.pgd, vaddr, &shift);if (ptep ==NULL ) paddr =0 ; -else +else { +/* +* we don't have hugepages backing iomem +*/ +BUG_ON (shift); paddr =pte_pfn (*ptep) <<PAGE_SHIFT ; + } bus =iowa_pci_find (vaddr, paddr);if (bus ==NULL )
arch/powerpc/kvm/book3s_hv_rm_mmu.c +3 -1
@@ -24,13 +24,15 @@/* Translate address of a vmalloc'd thing to a linear map address */ static void *real_vmalloc_addr (void *x) { +unsigned shift;unsigned long addr = (unsigned long ) x;pte_t *p; - p =find_linux_pte (swapper_pg_dir, addr); + p =find_linux_pte_or_hugepte (swapper_pg_dir, addr, &shift);if (!p || !pte_present (*p))return NULL ;/* assume we don't have huge pages in vmalloc space... */ +BUG_ON (shift); addr = (pte_pfn (*p) <<PAGE_SHIFT ) | (addr & ~PAGE_MASK );return __va (addr); }
arch/powerpc/mm/hash_utils_64.c +7 -1
@@ -1131,6 +1131,7 @@ EXPORT_SYMBOL_GPL(hash_page);void hash_preload (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap) { +int shift;unsigned long vsid;pgd_t *pgdir;pte_t *ptep;
@@ -1152,10 +1153,15 @@ void hash_preload(struct mm_struct *mm, unsigned long ea, pgdir = mm->pgd;if (pgdir ==NULL )return ; - ptep =find_linux_pte (pgdir, ea); +/* +* THP pages use update_mmu_cache_pmd. We don't do +* hash preload there. Hence can ignore THP here +*/ + ptep =find_linux_pte_or_hugepte (pgdir, ea, &shift);if (!ptep)return ; +BUG_ON (shift);#ifdef CONFIG_PPC_64K_PAGES /* If either _PAGE_4K_PFN or _PAGE_NO_CACHE is set (and we are on * a 64K kernel), then we don't preload, hash_page() will take
arch/powerpc/mm/hugetlbpage.c +6 -2
@@ -105,6 +105,7 @@ int pgd_huge(pgd_t pgd)pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) { +/* Only called for HugeTLB pages, hence can ignore THP */ return find_linux_pte_or_hugepte (mm->pgd, addr,NULL ); }
@@ -668,11 +669,14 @@ follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)struct page *page;unsigned shift;unsigned long mask; - +/* +* Transparent hugepages are handled by generic code. We can skip them +* here. +*/ ptep =find_linux_pte_or_hugepte (mm->pgd, address, &shift);/* Verify it is a huge page else bail. */ -if (!ptep || !shift) +if (!ptep || !shift ||pmd_trans_huge ((pmd_t)*ptep))return ERR_PTR (-EINVAL ); mask = (1UL << shift) -1 ;
arch/powerpc/mm/tlb_hash64.c +6 -1
@@ -189,6 +189,7 @@ void tlb_flush(struct mmu_gather *tlb)void __flush_hash_table_range (struct mm_struct *mm,unsigned long start,unsigned long end) { +int shift;unsigned long flags; start =_ALIGN_DOWN (start,PAGE_SIZE );
@@ -206,11 +207,15 @@ void __flush_hash_table_range(struct mm_struct *mm, unsigned long start,local_irq_save (flags);arch_enter_lazy_mmu_mode ();for (; start < end; start +=PAGE_SIZE ) { -pte_t *ptep =find_linux_pte (mm->pgd, start); +pte_t *ptep =find_linux_pte_or_hugepte (mm->pgd, start, &shift);unsigned long pte;if (ptep ==NULL )continue ; +/* +* We won't find hugepages here, this is iomem. +*/ +BUG_ON (shift); pte =pte_val (*ptep);if (!(pte & _PAGE_HASHPTE))continue ;
arch/powerpc/platforms/pseries/eeh.c +6 -1
@@ -258,12 +258,17 @@ void eeh_slot_error_detail(struct eeh_pe *pe, int severity)*/ static inline unsigned long eeh_token_to_phys (unsigned long token) { +int shift;pte_t *ptep;unsigned long pa; - ptep =find_linux_pte (init_mm.pgd, token); +/* +* We won't find hugepages here, iomem +*/ + ptep =find_linux_pte_or_hugepte (init_mm.pgd, token, &shift);if (!ptep)return token; +BUG_ON (shift); pa =pte_pfn (*ptep) <<PAGE_SHIFT ;return pa | (token & (PAGE_SIZE -1 ));
Signature · 1 line
1.7.10
Re: [PATCH -V6 23/27] powerpc: Replace find_linux_pte with find_linux_pte_or_hugepte
Quoted 13 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
Replace
find_linux_ptewithfind_linux_pte_or_hugepteand explicitly document why we don't need to handle transparent hugepages at callsites.arch/powerpc/kvm/book3s_hv_rm_mmu.c +0
-0@@ -24,13 +24,15 @@/* Translate address of a vmalloc'd thing to a linear map address */ static void *real_vmalloc_addr (void *x) {
arch/powerpc/kvm/book3s_hv_rm_mmu.c line 35
Quoted 10 lines
arch/powerpc/kvm/book3s_hv_rm_mmu.c +3
-1+unsigned shift;unsigned long addr = (unsigned long ) x;pte_t *p; - p =find_linux_pte (swapper_pg_dir, addr); + p =find_linux_pte_or_hugepte (swapper_pg_dir, addr, &shift);if (!p || !pte_present (*p))return NULL ;/* assume we don't have huge pages in vmalloc space... */ +BUG_ON (shift);
Please don't add BUG_ON in this file. At this point we're basically still in guest context (though in real mode), and BUG_ON would cause a trap which we would handle very badly...
Paul.
PATCH 24/27 powerpc: Update gup_pmd_range to handle transparent hugepages
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
--- arch/powerpc/mm/gup.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
arch/powerpc/mm/gup.c +13 -2
@@ -66,9 +66,20 @@ static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end,pmd_t pmd = *pmdp; next =pmd_addr_end (addr, end); -if (pmd_none (pmd)) +/* +* The pmd_trans_splitting() check below explains why +* pmdp_splitting_flush has to flush the tlb, to stop +* this gup-fast code from running while we set the +* splitting bit in the pmd. Returning zero will take +* the slow path that will call wait_split_huge_page() +* if the pmd is still in splitting state. gup-fast +* can't because it has irq disabled and +* wait_split_huge_page() would never return as the +* tlb flush IPI wouldn't run. +*/ +if (pmd_none (pmd) ||pmd_trans_splitting (pmd))return 0 ; -if (pmd_huge (pmd)) { +if (pmd_huge (pmd) ||pmd_large (pmd)) {if (!gup_hugepte ((pte_t *)pmdp,PMD_SIZE , addr, next, write, pages, nr))return 0 ;
Signature · 1 line
1.7.10
PATCH 25/27 powerpc/THP: Add code to handle HPTE faults for large pages
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
The deposted PTE page in the second half of the PMD table is used to track the state on hash PTEs. After updating the HPTE, we mark the coresponding slot in the deposted PTE page valid.
--- arch/powerpc/include/asm/mmu-hash64.h | 13 +++ arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/hash_utils_64.c | 13 ++- arch/powerpc/mm/hugepage-hash64.c | 180 +++++++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+), 4 deletions(-) create mode 100644 arch/powerpc/mm/hugepage-hash64.c
arch/powerpc/include/asm/mmu-hash64.h +13 -0
@@ -340,6 +340,19 @@ extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap)int __hash_page_huge (unsigned long ea,unsigned long access,unsigned long vsid,pte_t *ptep,unsigned long trap,int local,int ssize,unsigned int shift,unsigned int mmu_psize); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +extern int __hash_page_thp (unsigned long ea,unsigned long access, +unsigned long vsid,pmd_t *pmdp,unsigned long trap, +int local,int ssize,unsigned int psize); +#else +static inline int __hash_page_thp (unsigned long ea,unsigned long access, +unsigned long vsid,pmd_t *pmdp, +unsigned long trap,int local, +int ssize,unsigned int psize) +{ +BUG (); +} +#endif extern void hash_failure_debug(unsigned long ea, unsigned long access, unsigned long vsid, unsigned long trap, int ssize, int psize, int lpsize,
arch/powerpc/mm/Makefile +1 -0
@@ -33,6 +33,7 @@ ifeq ($(CONFIG_HUGETLB_PAGE),y) obj-$(CONFIG_PPC_STD_MMU_64) += hugetlbpage-hash64.o obj-$(CONFIG_PPC_BOOK3E_MMU) += hugetlbpage-book3e.o endif +obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += hugepage-hash64.o obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage-prot.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_HIGHMEM) += highmem.o
arch/powerpc/mm/hash_utils_64.c +9 -4
@@ -1041,11 +1041,16 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap)return 1 ; } +if (hugeshift) { +if (pmd_trans_huge ((pmd_t) *ptep)) +return __hash_page_thp (ea, access, vsid, (pmd_t *)ptep, + trap, local, ssize, psize);#ifdef CONFIG_HUGETLB_PAGE -if (hugeshift) -return __hash_page_huge (ea, access, vsid, ptep, trap, local, - ssize, hugeshift, psize); -#endif /* CONFIG_HUGETLB_PAGE */ + else + return __hash_page_huge(ea, access, vsid, ptep, trap, +local ,ssize ,hugeshift ,psize ); +#endif + }#ifndef CONFIG_PPC_64K_PAGES DBG_LOW (" i-pte: %016lx\n" ,pte_val (*ptep));
arch/powerpc/mm/hugepage-hash64.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 26/27 powerpc/THP: Enable THP on PPC64
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We enable only if the we support 16MB page size.
--- arch/powerpc/include/asm/pgtable-ppc64.h | 3 +-- arch/powerpc/mm/pgtable_64.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/pgtable-ppc64.h +1 -2
@@ -426,8 +426,7 @@ static inline unsigned long pmd_pfn(pmd_t pmd) return pmd_val(pmd) >> PTE_RPN_SHIFT; } -/* We will enable it in the last patch */ -#define has_transparent_hugepage () 0 +extern int has_transparent_hugepage (void );#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int pmd_young (pmd_t pmd)
arch/powerpc/mm/pgtable_64.c +28 -0
@@ -754,6 +754,34 @@ void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,return ; } +int has_transparent_hugepage (void ) +{ +if (!mmu_has_feature (MMU_FTR_16M_PAGE )) +return 0 ; +/* +* We support THP only if HPAGE_SHIFT is 16MB. +*/ +if (!HPAGE_SHIFT || (HPAGE_SHIFT != mmu_psize_defs[MMU_PAGE_16M ].shift)) +return 0 ; +/* +* We need to make sure that we support 16MB hugepage in a segement +* with base page size 64K or 4K. We only enable THP with a PAGE_SIZE +* of 64K. +*/ +/* +* If we have 64K HPTE, we will be using that by default +*/ +if (mmu_psize_defs[MMU_PAGE_64K ].shift && + (mmu_psize_defs[MMU_PAGE_64K ].penc[MMU_PAGE_16M ] ==-1 )) +return 0 ; +/* +* Ok we only have 4K HPTE +*/ +if (mmu_psize_defs[MMU_PAGE_4K ].penc[MMU_PAGE_16M ] ==-1 ) +return 0 ; + +return 1 ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ pmd_t pmdp_get_and_clear(struct mm_struct *mm,
Signature · 1 line
1.7.10
PATCH 27/27 powerpc: Optimize hugepage invalidate
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
Hugepage invalidate involves invalidating multiple hpte entries. Optimize the operation using H_BULK_REMOVE on lpar platforms. On native, reduce the number of tlb flush.
--- arch/powerpc/include/asm/machdep.h | 3 + arch/powerpc/mm/hash_native_64.c | 78 ++++++++++++++++++++ arch/powerpc/mm/pgtable_64.c | 13 +++- arch/powerpc/platforms/pseries/lpar.c | 126 +++++++++++++++++++++++++++++++-- 4 files changed, 210 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/machdep.h +3 -0
@@ -56,6 +56,9 @@ struct machdep_calls {void (*hpte_removebolted)(unsigned long ea,int psize,int ssize);void (*flush_hash_range)(unsigned long number,int local); +void (*hugepage_invalidate)(struct mm_struct *mm, +unsigned char *hpte_slot_array, +unsigned long addr,int psize);/* special for kexec, to be called in real mode, linear mapping is * destroyed as well */
arch/powerpc/mm/hash_native_64.c +78 -0
88 lines not on this page · raw message
arch/powerpc/mm/pgtable_64.c +10 -3
@@ -659,6 +659,7 @@ void hpte_need_hugepage_flush(struct mm_struct *mm, unsigned long addr, {int ssize, i;unsigned long s_addr; +int max_hpte_count;unsigned int psize, valid;unsigned char *hpte_slot_array;unsigned long hidx, vpn, vsid, hash, shift, slot;
@@ -672,12 +673,18 @@ void hpte_need_hugepage_flush(struct mm_struct *mm, unsigned long addr,* second half of the PMD */ hpte_slot_array = *(char **)(pmdp +PTRS_PER_PMD ); -/* get the base page size */ psize =get_slice_psize (mm, s_addr); - shift = mmu_psize_defs[psize].shift; -for (i =0 ; i < (HUGE_PAGE_SIZE >> shift); i++) { +if (ppc_md.hugepage_invalidate) +return ppc_md.hugepage_invalidate (mm, hpte_slot_array, + s_addr, psize); +/* +* No bluk hpte removal support, invalidate each entry +*/ + shift = mmu_psize_defs[psize].shift; + max_hpte_count =HUGE_PAGE_SIZE >> shift; +for (i =0 ; i < max_hpte_count; i++) {/* * 8 bits per each hpte entries * 000| [ secondary group (one bit) | hidx (3 bits) | valid bit]
arch/powerpc/platforms/pseries/lpar.c +119 -7
150 lines not on this page · raw message
Signature · 1 line
1.7.10