mm: Introduce a general RCU get_user_pages_fast.
Subsystems (5)
PATCH 1/2 mm: Introduce a general RCU get_user_pages_fast.
get_user_pages_fast attempts to pin user pages by walking the page tables directly and avoids taking locks. Thus the walker needs to be protected from page table pages being freed from under it, and needs to block any THP splits.
One way to achieve this is to have the walker disable interrupts, and rely on IPIs from the TLB flushing code blocking before the page table pages are freed.
On some platforms we have hardware broadcast of TLB invalidations, thus the TLB flushing code doesn't necessarily need to broadcast IPIs; and spuriously broadcasting IPIs can hurt system performance if done too often.
This problem has been solved on PowerPC and Sparc by batching up page table pages belonging to more than one mm_user, then scheduling an rcu_sched callback to free the pages. This RCU page table free logic has been promoted to core code and is activated when one enables HAVE_RCU_TABLE_FREE. Unfortunately, these architectures implement their own get_user_pages_fast routines.
The RCU page table free logic coupled with a an IPI broadcast on THP split (which is a rare event), allows one to protect a page table walker by merely disabling the interrupts during the walk.
This patch provides a general RCU implementation of get_user_pages_fast that can be used by architectures that perform hardware broadcast of TLB invalidations.
It is based heavily on the PowerPC implementation.
---
NOTE: I kept the description of patch as it is and also retained the documentation. I also dropped the tested-by and other SOB, because i was not sure whether they want to be blamed for the bugs here. Please feel free to update.
include/linux/mm.h | 21 ++++ mm/Kconfig | 3 + mm/gup.c | 349 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 373 insertions(+)
include/linux/mm.h +21 -0
@@ -1198,6 +1198,27 @@ long get_user_pages(struct task_struct *tsk, struct mm_struct *mm, struct vm_area_struct **vmas);int get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages); + +#ifndef is_hugepd +/* +* Some architectures support hugepage directory format that is +* required to support different hugetlbfs sizes. +*/ +typedef struct {unsigned long pd; }hugepd_t ; +#define is_hugepd (hugepd) (0) +#define __hugepd (x) ((hugepd_t) { (x) }) +static inline int gup_hugepd (hugepd_t hugepd,unsigned long addr, +unsigned pdshift,unsigned long end, +int write,struct page **pages,int *nr) +{ +return 0 ; +} +#else +extern int gup_hugepd (hugepd_t hugepd,unsigned long addr, +unsigned pdshift,unsigned long end, +int write,struct page **pages,int *nr); +#endif +struct kvec ;int get_kernel_pages (const struct kvec *iov,int nr_pages,int write,struct page **pages);
mm/Kconfig +3 -0
@@ -137,6 +137,9 @@ config HAVE_MEMBLOCK_NODE_MAP config HAVE_MEMBLOCK_PHYS_MAP boolean +config HAVE_GENERIC_RCU_GUP + boolean + config ARCH_DISCARD_MEMBLOCK boolean
mm/gup.c +349 -0
358 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 2/2 arch/powerpc: Switch to generic RCU get_user_pages_fast
This patch switch the ppc arch to use the generic RCU based gup implementation.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/hugetlb.h | 8 +- arch/powerpc/include/asm/page.h | 3 +- arch/powerpc/include/asm/pgtable-ppc64.h | 1 - arch/powerpc/include/asm/pgtable.h | 5 - arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/gup.c | 235 ------------------------------- arch/powerpc/mm/hugetlbpage.c | 32 +++-- 8 files changed, 26 insertions(+), 261 deletions(-) delete mode 100644 arch/powerpc/mm/gup.c
arch/powerpc/Kconfig +1 -0
@@ -147,6 +147,7 @@ config PPC select ARCH_USE_CMPXCHG_LOCKREF if PPC64 select HAVE_ARCH_AUDITSYSCALL select ARCH_SUPPORTS_ATOMIC_RMW + select HAVE_GENERIC_RCU_GUP config GENERIC_CSUM def_bool CPU_LITTLE_ENDIAN
arch/powerpc/include/asm/hugetlb.h +4 -4
@@ -48,7 +48,7 @@ static inline unsigned int hugepd_shift(hugepd_t hpd)#endif /* CONFIG_PPC_BOOK3S_64 */ -static inline pte_t *hugepte_offset (hugepd_t *hpdp,unsigned long addr, +static inline pte_t *hugepte_offset (hugepd_t hpd,unsigned long addr,unsigned pdshift) {/*
@@ -58,9 +58,9 @@ static inline pte_t *hugepte_offset(hugepd_t *hpdp, unsigned long addr,*/ unsigned long idx =0 ; -pte_t *dir =hugepd_page (*hpdp); +pte_t *dir =hugepd_page (hpd);#ifndef CONFIG_PPC_FSL_BOOK3E - idx = (addr & ((1UL << pdshift) -1 )) >>hugepd_shift (*hpdp); + idx = (addr & ((1UL << pdshift) -1 )) >>hugepd_shift (hpd);#endif return dir + idx;
@@ -193,7 +193,7 @@ static inline void flush_hugetlb_page(struct vm_area_struct *vma, }#define hugepd_shift (x) 0 -static inline pte_t *hugepte_offset (hugepd_t *hpdp,unsigned long addr, +static inline pte_t *hugepte_offset (hugepd_t hpd,unsigned long addr,unsigned pdshift) {return 0 ;
arch/powerpc/include/asm/page.h +2 -1
@@ -379,12 +379,13 @@ static inline int hugepd_ok(hugepd_t hpd) }#endif -#define is_hugepd (pdep) (hugepd_ok(*((hugepd_t *)(pdep)))) +#define is_hugepd (hpd) (hugepd_ok(hpd))int pgd_huge (pgd_t pgd);#else /* CONFIG_HUGETLB_PAGE */ #define is_hugepd (pdep) 0#define pgd_huge (pgd) 0#endif /* CONFIG_HUGETLB_PAGE */ +#define __hugepd (x) ((hugepd_t) { (x) })struct page ;extern void clear_user_page (void *page,unsigned long vaddr,struct page *pg);
arch/powerpc/include/asm/pgtable-ppc64.h +0 -1
@@ -575,6 +575,5 @@ static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,*/ return true; } -#endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */
arch/powerpc/include/asm/pgtable.h +0 -5
@@ -304,11 +304,6 @@ extern void paging_init(void);*/ 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);#ifndef CONFIG_TRANSPARENT_HUGEPAGE #define pmd_large (pmd) 0#define has_transparent_hugepage () 0
arch/powerpc/mm/Makefile +1 -1
@@ -6,7 +6,7 @@ subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) -obj-y := fault.o mem.o pgtable.o gup.o mmap.o \ +obj-y := fault.o mem.o pgtable.o mmap.o \ init_$(CONFIG_WORD_SIZE).o \ pgtable_$(CONFIG_WORD_SIZE).o obj-$(CONFIG_PPC_MMU_NOHASH) += mmu_context_nohash.o tlb_nohash.o \
arch/powerpc/mm/gup.c deleted +0 -235
235 lines not on this page · raw message
arch/powerpc/mm/hugetlbpage.c +18 -14
@@ -230,7 +230,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long szif (hugepd_none (*hpdp) &&__hugepte_alloc (mm, hpdp, addr, pdshift, pshift))return NULL ; - return hugepte_offset(hpdp, addr, pdshift); + return hugepte_offset(*hpdp, addr, pdshift); }#else
@@ -270,7 +270,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long szif (hugepd_none (*hpdp) &&__hugepte_alloc (mm, hpdp, addr, pdshift, pshift))return NULL ; - return hugepte_offset(hpdp, addr, pdshift); + return hugepte_offset(*hpdp, addr, pdshift); }#endif
@@ -538,7 +538,7 @@ static void hugetlb_free_pmd_range(struct mmu_gather *tlb, pud_t *pud, do { pmd = pmd_offset(pud, addr); next = pmd_addr_end(addr, end); - if (!is_hugepd(pmd)) { + if (!is_hugepd(__hugepd(pmd_val(*pmd)))) { /* * if it is not hugepd pointer, we should already find * it cleared.
@@ -587,7 +587,7 @@ static void hugetlb_free_pud_range(struct mmu_gather *tlb, pgd_t *pgd, do { pud = pud_offset(pgd, addr); next = pud_addr_end(addr, end); - if (!is_hugepd(pud)) { + if (!is_hugepd(__hugepd(pud_val(*pud)))) { if (pud_none_or_clear_bad(pud)) continue; hugetlb_free_pmd_range(tlb, pud, addr, next, floor,
@@ -653,7 +653,7 @@ void hugetlb_free_pgd_range(struct mmu_gather *tlb, do { next = pgd_addr_end(addr, end); pgd = pgd_offset(tlb->mm, addr); - if (!is_hugepd(pgd)) { + if (!is_hugepd(__hugepd(pgd_val(*pgd)))) { if (pgd_none_or_clear_bad(pgd)) continue; hugetlb_free_pud_range(tlb, pgd, addr, next, floor, ceiling);
@@ -713,18 +713,22 @@ static unsigned long hugepte_addr_end(unsigned long addr, unsigned long end,return (__boundary -1 < end -1 ) ? __boundary : end; } -int gup_hugepd (hugepd_t *hugepd,unsigned pdshift, -unsigned long addr,unsigned long end, -int write,struct page **pages,int *nr) +extern int gup_huge_pte (pte_t orig,pte_t *ptep,unsigned long addr, +unsigned long size,unsigned long end,int write, +struct page **pages,int *nr); + +int gup_hugepd (hugepd_t hugepd,unsigned long addr,unsigned pdshift, +unsigned long end,int write,struct page **pages,int *nr) {pte_t *ptep; -unsigned long sz =1UL <<hugepd_shift (*hugepd); +unsigned long sz =1UL <<hugepd_shift (hugepd);unsigned long next; ptep =hugepte_offset (hugepd, addr, pdshift);do { next =hugepte_addr_end (addr, end, sz); -if (!gup_hugepte (ptep, sz, addr, end, write, pages, nr)) +if (!gup_huge_pte (ACCESS_ONCE (*ptep), ptep, addr, sz, end, + write, pages, nr))return 0 ; }while (ptep++, addr = next, addr != end);
@@ -961,7 +965,7 @@ pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, unsigned *shiftelse if (pgd_huge (pgd)) { ret_pte = (pte_t *) pgdp; goto out; - }else if (is_hugepd (&pgd)) + }else if (is_hugepd (__hugepd (pgd_val (pgd)))) hpdp = (hugepd_t *)&pgd;else {/*
@@ -978,7 +982,7 @@ pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, unsigned *shiftelse if (pud_huge (pud)) { ret_pte = (pte_t *) pudp; goto out; - }else if (is_hugepd (&pud)) + }else if (is_hugepd (__hugepd (pud_val (pud)))) hpdp = (hugepd_t *)&pud;else { pdshift =PMD_SHIFT ;
@@ -999,7 +1003,7 @@ pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, unsigned *shiftif (pmd_huge (pmd) ||pmd_large (pmd)) { ret_pte = (pte_t *) pmdp; goto out; - }else if (is_hugepd (&pmd)) + }else if (is_hugepd (__hugepd (pmd_val (pmd)))) hpdp = (hugepd_t *)&pmd;else return pte_offset_kernel (&pmd, ea);
@@ -1008,7 +1012,7 @@ pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, unsigned *shiftif (!hpdp)return NULL ; - ret_pte =hugepte_offset (hpdp, ea, pdshift); + ret_pte =hugepte_offset (*hpdp, ea, pdshift); pdshift =hugepd_shift (*hpdp); out:if (shift)
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 29 lines · Aneesh Kumar K.V
get_user_pages_fastattempts to pin user pages by walking the page tables directly and avoids taking locks. Thus the walker needs to be protected from page table pages being freed from under it, and needs to block any THP splits.One way to achieve this is to have the walker disable interrupts, and rely on IPIs from the TLB flushing code blocking before the page table pages are freed.
On some platforms we have hardware broadcast of TLB invalidations, thus the TLB flushing code doesn't necessarily need to broadcast IPIs; and spuriously broadcasting IPIs can hurt system performance if done too often.
This problem has been solved on PowerPC and Sparc by batching up page table pages belonging to more than one
mm_user, then scheduling anrcu_schedcallback to free the pages. This RCU page table free logic has been promoted to core code and is activated when one enablesHAVE_RCU_TABLE_FREE. Unfortunately, these architectures implement their ownget_user_pages_fastroutines.The RCU page table free logic coupled with a an IPI broadcast on THP split (which is a rare event), allows one to protect a page table walker by merely disabling the interrupts during the walk.
This patch provides a general RCU implementation of
get_user_pages_fastthat can be used by architectures that perform hardware broadcast of TLB invalidations.
Quoted 8 lines
It is based heavily on the PowerPC implementation.
Signed-off-by Aneesh Kumar K.V <[email protected]>---
NOTE: I kept the description of patch as it is and also retained the documentation. I also dropped the tested-by and other SOB, because i was not sure whether they want to be blamed for the bugs here. Please feel free to update.
Hi Aneesh,
Thank you for coding this up.
I've compiled and briefly tested this on arm (with and without LPAE), and arm64. I ran a custom futex on THP tail test, and this passed. I'll test this a little more aggressively with ltp.
I think Linus has already pulled in the RCU gup I posted, could you please instead write a patch against?
2667f50 mm: introduce a general RCU get_user_pages_fast()
I had one issue compiling this, pgd_huge was undefined. I think this is only defined for PowerPC? Could a stub definition of pgd_huge be added?
Cheers,
Signature · 7 lines
Steve -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 42 lines · Steve Capper
Quoted 29 lines · Aneesh Kumar K.V
get_user_pages_fastattempts to pin user pages by walking the page tables directly and avoids taking locks. Thus the walker needs to be protected from page table pages being freed from under it, and needs to block any THP splits.One way to achieve this is to have the walker disable interrupts, and rely on IPIs from the TLB flushing code blocking before the page table pages are freed.
On some platforms we have hardware broadcast of TLB invalidations, thus the TLB flushing code doesn't necessarily need to broadcast IPIs; and spuriously broadcasting IPIs can hurt system performance if done too often.
This problem has been solved on PowerPC and Sparc by batching up page table pages belonging to more than one
mm_user, then scheduling anrcu_schedcallback to free the pages. This RCU page table free logic has been promoted to core code and is activated when one enablesHAVE_RCU_TABLE_FREE. Unfortunately, these architectures implement their ownget_user_pages_fastroutines.The RCU page table free logic coupled with a an IPI broadcast on THP split (which is a rare event), allows one to protect a page table walker by merely disabling the interrupts during the walk.
This patch provides a general RCU implementation of
get_user_pages_fastthat can be used by architectures that perform hardware broadcast of TLB invalidations.Quoted 8 lines
It is based heavily on the PowerPC implementation.
Signed-off-by Aneesh Kumar K.V <[email protected]>---
NOTE: I kept the description of patch as it is and also retained the documentation. I also dropped the tested-by and other SOB, because i was not sure whether they want to be blamed for the bugs here. Please feel free to update.
Hi Aneesh,
Thank you for coding this up.
Quoted 6 lines
I've compiled and briefly tested this on arm (with and without LPAE), and arm64. I ran a custom futex on THP tail test, and this passed. I'll test this a little more aggressively with ltp.
I think Linus has already pulled in the RCU gup I posted, could you please instead write a patch against?
Will do that.
Quoted 1 line
2667f50 mm: introduce a general RCU
get_user_pages_fast()
In that patch don't you need to check the _PAGE_PRESENT details in case of gup_huge_pmd ?
-aneesh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 51 lines · Aneesh Kumar K.V
Quoted 42 lines · Steve Capper
Quoted 29 lines · Aneesh Kumar K.V
get_user_pages_fastattempts to pin user pages by walking the page tables directly and avoids taking locks. Thus the walker needs to be protected from page table pages being freed from under it, and needs to block any THP splits.One way to achieve this is to have the walker disable interrupts, and rely on IPIs from the TLB flushing code blocking before the page table pages are freed.
On some platforms we have hardware broadcast of TLB invalidations, thus the TLB flushing code doesn't necessarily need to broadcast IPIs; and spuriously broadcasting IPIs can hurt system performance if done too often.
This problem has been solved on PowerPC and Sparc by batching up page table pages belonging to more than one
mm_user, then scheduling anrcu_schedcallback to free the pages. This RCU page table free logic has been promoted to core code and is activated when one enablesHAVE_RCU_TABLE_FREE. Unfortunately, these architectures implement their ownget_user_pages_fastroutines.The RCU page table free logic coupled with a an IPI broadcast on THP split (which is a rare event), allows one to protect a page table walker by merely disabling the interrupts during the walk.
This patch provides a general RCU implementation of
get_user_pages_fastthat can be used by architectures that perform hardware broadcast of TLB invalidations.Quoted 8 lines
It is based heavily on the PowerPC implementation.
Signed-off-by Aneesh Kumar K.V <[email protected]>---
NOTE: I kept the description of patch as it is and also retained the documentation. I also dropped the tested-by and other SOB, because i was not sure whether they want to be blamed for the bugs here. Please feel free to update.
Hi Aneesh,
Thank you for coding this up.Quoted 6 lines
I've compiled and briefly tested this on arm (with and without LPAE), and arm64. I ran a custom futex on THP tail test, and this passed. I'll test this a little more aggressively with ltp.
I think Linus has already pulled in the RCU gup I posted, could you please instead write a patch against?
Quoted 7 lines
Will do that.
Quoted 1 line
2667f50 mm: introduce a general RCU
get_user_pages_fast()In that patch don't you need to check the
_PAGE_PRESENTdetails in case ofgup_huge_pmd?
Before calling gup_huge_pmd we check for pmd_none. On ARM we have:
#define pmd_none(pmd) (!pmd_val(pmd))
#define pmd_present(pmd) (pmd_val(pmd))
So we know when we enter gup_huge_pmd that "orig" represents a pmd that is present.
On PowerPC I see the definitions are a little different for pgtable-ppc32.h:
#define pmd_present(pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK)
A pmd_present() could be added to the beginning of gup_huge_pmd safely if this is needed for PowerPC.
Cheers,
Signature · 7 lines
Steve -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 67 lines · Steve Capper
Quoted 51 lines · Aneesh Kumar K.V
Quoted 42 lines · Steve Capper
Quoted 29 lines · Aneesh Kumar K.V
get_user_pages_fastattempts to pin user pages by walking the page tables directly and avoids taking locks. Thus the walker needs to be protected from page table pages being freed from under it, and needs to block any THP splits.One way to achieve this is to have the walker disable interrupts, and rely on IPIs from the TLB flushing code blocking before the page table pages are freed.
On some platforms we have hardware broadcast of TLB invalidations, thus the TLB flushing code doesn't necessarily need to broadcast IPIs; and spuriously broadcasting IPIs can hurt system performance if done too often.
This problem has been solved on PowerPC and Sparc by batching up page table pages belonging to more than one
mm_user, then scheduling anrcu_schedcallback to free the pages. This RCU page table free logic has been promoted to core code and is activated when one enablesHAVE_RCU_TABLE_FREE. Unfortunately, these architectures implement their ownget_user_pages_fastroutines.The RCU page table free logic coupled with a an IPI broadcast on THP split (which is a rare event), allows one to protect a page table walker by merely disabling the interrupts during the walk.
This patch provides a general RCU implementation of
get_user_pages_fastthat can be used by architectures that perform hardware broadcast of TLB invalidations.Quoted 8 lines
It is based heavily on the PowerPC implementation.
Signed-off-by Aneesh Kumar K.V <[email protected]>---
NOTE: I kept the description of patch as it is and also retained the documentation. I also dropped the tested-by and other SOB, because i was not sure whether they want to be blamed for the bugs here. Please feel free to update.
Hi Aneesh,
Thank you for coding this up.Quoted 6 lines
I've compiled and briefly tested this on arm (with and without LPAE), and arm64. I ran a custom futex on THP tail test, and this passed. I'll test this a little more aggressively with ltp.
I think Linus has already pulled in the RCU gup I posted, could you please instead write a patch against?
Quoted 7 lines
Will do that.
Quoted 1 line
2667f50 mm: introduce a general RCU
get_user_pages_fast()In that patch don't you need to check the
_PAGE_PRESENTdetails in case ofgup_huge_pmd?Before calling
gup_huge_pmdwe check forpmd_none. On ARM we have:
#definepmd_none(pmd)(!pmd_val(pmd))
#definepmd_present(pmd)(pmd_val(pmd))So we know when we enter
gup_huge_pmdthat "orig" represents a pmd that is present.
Quoted 7 lines
On PowerPC I see the definitions are a little different for
pgtable-ppc32.h:
#definepmd_present(pmd)(pmd_val(pmd)&_PMD_PRESENT_MASK)A
pmd_present()could be added to the beginning ofgup_huge_pmdsafely if this is needed for PowerPC.
for the huge pmd case, that is pte in pmd we may really want to check _PAGE_PRESENT bit right ?
-aneesh