arm: support get_user_pages_fast
cover arm: support get_user_pages_fast
Recently, I got a report get_user_pages_fast helps app's launching time due to reducing uninterruptible sleep time because it could reduce mmap_sem lock contentions when app is launching.
To support gupf in ARM-non-LPAE, first patch reorders memory type table to use 5th bit of the page table. It seems we don't use the bit in ARMv6+ but it needs double check from maintainers.
Second patch introduces L_PTE_SPECIAL for arm so that last patch can support get_user_pags_fast.
I would greatly appreciate if guys review that I screw up something, especially, architecture stuffs.
Thanks.
Minchan Kim (3):
arm: mm: reordering memory type table
arm: mm: introduce L_PTE_SPECIAL
arm: mm: support get_user_pages_fast
arch/arm/Kconfig | 2 +- arch/arm/include/asm/pgtable-2level.h | 16 +- arch/arm/include/asm/pgtable-3level.h | 6 - arch/arm/include/asm/pgtable.h | 13 ++ arch/arm/mm/Makefile | 6 + arch/arm/mm/gup.c | 221 ++++++++++++++++++++++++++ arch/arm/mm/proc-macros.S | 16 +- 7 files changed, 261 insertions(+), 19 deletions(-) create mode 100644 arch/arm/mm/gup.c
Signature · 1 line
2.19.0.rc1.350.ge57e33dbd1-goog
RFC 1/3 arm: mm: reordering memory type table
To use bit 5th in page table, we need a room for that and it seems we don't need 4 bits for the memory type with ARMv6+. If so, let's reorder bits to make bit 5 free.
We will use the bit for L_PTE_SPECIAL in next patch.
--- arch/arm/include/asm/pgtable-2level.h | 13 +++++++++++-- arch/arm/mm/proc-macros.S | 16 ++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-)
arch/arm/include/asm/pgtable-2level.h +11 -2
@@ -164,14 +164,23 @@#define L_PTE_MT_BUFFERABLE (_AT(pteval_t, 0x01) << 2)/* 0001 */ #define L_PTE_MT_WRITETHROUGH (_AT(pteval_t, 0x02) << 2)/* 0010 */ #define L_PTE_MT_WRITEBACK (_AT(pteval_t, 0x03) << 2)/* 0011 */ +#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2)/* 0100 */ #define L_PTE_MT_MINICACHE (_AT(pteval_t, 0x06) << 2)/* 0110 (sa1100, xscale) */ #define L_PTE_MT_WRITEALLOC (_AT(pteval_t, 0x07) << 2)/* 0111 */ -#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2)/* 0100 */ -#define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2)/* 1100 */ +#if defined(CONFIG_CPU_V7 ) || defined(CONFIG_CPU_V7M ) || \ + defined (CONFIG_CPU_V6 ) || defined(CONFIG_CPU_V6K ) +#define L_PTE_MT_DEV_WC L_PTE_MT_BUFFERABLE +#define L_PTE_MT_DEV_CACHED L_PTE_MT_WRITEBACK +#define L_PTE_MT_DEV_NONSHARED L_PTE_MT_MINICACHE +#define L_PTE_MT_VECTORS (_AT(pteval_t, 0x05) << 2)/* 0101 */ +#define L_PTE_MT_MASK (_AT(pteval_t, 0x07) << 2) +#else #define L_PTE_MT_DEV_WC (_AT(pteval_t, 0x09) << 2)/* 1001 */ #define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 0x0b) << 2)/* 1011 */ +#define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2)/* 1100 */ #define L_PTE_MT_VECTORS (_AT(pteval_t, 0x0f) << 2)/* 1111 */ #define L_PTE_MT_MASK (_AT(pteval_t, 0x0f) << 2) +#endif #ifndef __ASSEMBLY__
arch/arm/mm/proc-macros.S +8 -8
@@ -134,21 +134,21 @@ .macro armv6_mt_table pfx \pfx\()_mt_table: .long 0x00 @ L_PTE_MT_UNCACHED - .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE + .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE(L_PTE_MT_DEV_WC) .long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH - .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK + .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK(L_PTE_MT_DEV_CACHED) .long PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED - .long 0x00 @ unused - .long 0x00 @ L_PTE_MT_MINICACHE (not present) + .long PTE_CACHEABLE | PTE_BUFFERABLE | PTE_EXT_APX @ L_PTE_MT_VECTORS + .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED .long PTE_EXT_TEX(1) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC .long 0x00 @ unused - .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC .long 0x00 @ unused - .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED - .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED .long 0x00 @ unused .long 0x00 @ unused - .long PTE_CACHEABLE | PTE_BUFFERABLE | PTE_EXT_APX @ L_PTE_MT_VECTORS + .long 0x00 @ unused + .long 0x00 @ unused + .long 0x00 @ unused + .long 0x00 @ unused .endm .macro armv6_set_pte_ext pfx
Signature · 1 line
2.19.0.rc1.350.ge57e33dbd1-goog
Re: [RFC 1/3] arm: mm: reordering memory type table
Quoted 8 lines · Minchan Kim
arch/arm/include/asm/pgtable-2level.h +0
-0@@ -164,14 +164,23 @@#define L_PTE_MT_BUFFERABLE (_AT(pteval_t, 0x01) << 2)/* 0001 */ #define L_PTE_MT_WRITETHROUGH (_AT(pteval_t, 0x02) << 2)/* 0010 */ #define L_PTE_MT_WRITEBACK (_AT(pteval_t, 0x03) << 2)/* 0011 */
arch/arm/include/asm/pgtable-2level.h line 174
Quoted 10 lines
arch/arm/include/asm/pgtable-2level.h +6
-2+#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2)/* 0100 */ #define L_PTE_MT_MINICACHE (_AT(pteval_t, 0x06) << 2)/* 0110 (sa1100, xscale) */ #define L_PTE_MT_WRITEALLOC (_AT(pteval_t, 0x07) << 2)/* 0111 */ -#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2)/* 0100 */ -#define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2)/* 1100 */ +#if defined(CONFIG_CPU_V7 ) || defined(CONFIG_CPU_V7M ) || \ + defined (CONFIG_CPU_V6 ) || defined(CONFIG_CPU_V6K ) +#define L_PTE_MT_DEV_WC L_PTE_MT_BUFFERABLE +#define L_PTE_MT_DEV_CACHED L_PTE_MT_WRITEBACK +#define L_PTE_MT_DEV_NONSHARED L_PTE_MT_MINICACHE
I think you can just ignore v7M here, it doesn't have an MMU.
You are defining L_PTE_MT_DEV_NONSHARED to L_PTE_MT_MINICACHE but what I think you just meant is index 6 in the cpu_v6_mt_table which I would use explicitly to avoid confusion.
Anyway, on ARMv7 or ARMv6+LPAE, the non-shared device gets mapped to shared device in hardware. Looking through the arm32 code, it seems that MT_DEVICE_NONSHARED is used by arch/arm/mach-shmobile/setup-r8a7779.c and IIUC that's a v7 platform (R-Car H1, Cortex-A9). I think the above should be defined to L_PTE_MT_DEV_SHARED, unless I miss any place where DEV_NONSHARED is relevant on ARMv6 (adding Simon to confirm on shmobile).
arch/arm/mm/proc-macros.S line 135
Quoted 7 lines
arch/arm/mm/proc-macros.S +0
-0@@ -134,21 +134,21 @@ .macro armv6_mt_table pfx \pfx\()_mt_table:
Since you changed the MT index, you'd have to fix proc-v7-*levels.S as well. If you define DEV_NONSHARED to SHARED, I think you only need to update the index for L_PTE_MT_VECTORS.
Signature · 1 line
Catalin
Re: [RFC 1/3] arm: mm: reordering memory type table
Quoted 13 lines · Catalin Marinas
Quoted 12 lines · Minchan Kim
arch/arm/include/asm/pgtable-2level.h +1
-1@@ -164,14 +164,23 @@#define L_PTE_MT_BUFFERABLE (_AT(pteval_t, 0x01) << 2)/* 0001 */ #define L_PTE_MT_WRITETHROUGH (_AT(pteval_t, 0x02) << 2)/* 0010 */ #define L_PTE_MT_WRITEBACK (_AT(pteval_t, 0x03) << 2)/* 0011 */ +#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2)/* 0100 */ #define L_PTE_MT_MINICACHE (_AT(pteval_t, 0x06) << 2)/* 0110 (sa1100, xscale) */ #define L_PTE_MT_WRITEALLOC (_AT(pteval_t, 0x07) << 2)/* 0111 */ -#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2)/* 0100 */
Quoted 8 lines
arch/arm/include/asm/pgtable-2level.h line 174
Quoted 6 lines
arch/arm/include/asm/pgtable-2level.h +5
-1-#define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2)/* 1100 */ +#if defined(CONFIG_CPU_V7 ) || defined(CONFIG_CPU_V7M ) || \ + defined (CONFIG_CPU_V6 ) || defined(CONFIG_CPU_V6K ) +#define L_PTE_MT_DEV_WC L_PTE_MT_BUFFERABLE +#define L_PTE_MT_DEV_CACHED L_PTE_MT_WRITEBACK +#define L_PTE_MT_DEV_NONSHARED L_PTE_MT_MINICACHEI think you can just ignore v7M here, it doesn't have an MMU.
I didn't know that. Will fix.
Quoted 7 lines
You are defining
L_PTE_MT_DEV_NONSHAREDtoL_PTE_MT_MINICACHEbut what I think you just meant is index 6 in thecpu_v6_mt_tablewhich I would use explicitly to avoid confusion.Anyway, on ARMv7 or ARMv6+LPAE, the non-shared device gets mapped to shared device in hardware. Looking through the arm32 code, it seems that
Thanks for the information. I didn't know that.
Quoted 5 lines
MT_DEVICE_NONSHAREDis used byarch/arm/mach-shmobile/setup-r8a7779.cand IIUC that's a v7 platform (R-Car H1, Cortex-A9). I think the above should be defined toL_PTE_MT_DEV_SHARED, unless I miss any place whereDEV_NONSHAREDis relevant on ARMv6 (adding Simon to confirm on shmobile).
Simon, could you confirm this?
Quoted 12 lines
arch/arm/mm/proc-macros.S line 135
Quoted 8 lines
arch/arm/mm/proc-macros.S +0
-0@@ -134,21 +134,21 @@ .macro armv6_mt_table pfx \pfx\()_mt_table:Since you changed the MT index, you'd have to fix proc-v7-*levels.S as well. If you define
DEV_NONSHAREDto SHARED, I think you only need to update the index forL_PTE_MT_VECTORS.
Good idea. I will try it on.
Thanks for the review, Catalin.
RFC 2/3 arm: mm: introduce L_PTE_SPECIAL
In reply to Minchan KimThis patch introduces L_PTE_SPECIAL and pte functions for supporting get_user_pages_fast.
--- arch/arm/Kconfig | 2 +- arch/arm/include/asm/pgtable-2level.h | 3 +-- arch/arm/include/asm/pgtable-3level.h | 6 ------ arch/arm/include/asm/pgtable.h | 13 +++++++++++++ 4 files changed, 15 insertions(+), 9 deletions(-)
arch/arm/Kconfig +1 -1
@@ -10,7 +10,7 @@ config ARM select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_KCOV select ARCH_HAS_MEMBARRIER_SYNC_CORE - select ARCH_HAS_PTE_SPECIAL if ARM_LPAE + select ARCH_HAS_PTE_SPECIAL if (ARM_LPAE || CPU_V7 || CPU_V7M || CPU_V6 || CPUV6K) select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_SET_MEMORY select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
arch/arm/include/asm/pgtable-2level.h +1 -2
@@ -120,6 +120,7 @@#define L_PTE_VALID (_AT(pteval_t, 1) << 0)/* Valid */ #define L_PTE_PRESENT (_AT(pteval_t, 1) << 0)#define L_PTE_YOUNG (_AT(pteval_t, 1) << 1) +#define L_PTE_SPECIAL (_AT(pteval_t, 1) << 5)#define L_PTE_DIRTY (_AT(pteval_t, 1) << 6)#define L_PTE_RDONLY (_AT(pteval_t, 1) << 7)#define L_PTE_USER (_AT(pteval_t, 1) << 8)
@@ -222,8 +223,6 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)#define pmd_addr_end (addr,end) (end)#define set_pte_ext (ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext) -#define pte_special (pte) (0) -static inline pte_t pte_mkspecial (pte_t pte) {return pte; }/* * We don't have huge page support for short descriptors, for the moment
arch/arm/include/asm/pgtable-3level.h +0 -6
@@ -213,12 +213,6 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)#define pmd_present (pmd) (pmd_isset((pmd), L_PMD_SECT_VALID))#define pmd_young (pmd) (pmd_isset((pmd), PMD_SECT_AF)) -#define pte_special (pte) (pte_isset((pte), L_PTE_SPECIAL)) -static inline pte_t pte_mkspecial (pte_t pte) -{ -pte_val (pte) |=L_PTE_SPECIAL ; -return pte; -}#define pmd_write (pmd) (pmd_isclear((pmd), L_PMD_SECT_RDONLY))#define pmd_dirty (pmd) (pmd_isset((pmd), L_PMD_SECT_DIRTY))
arch/arm/include/asm/pgtable.h +13 -0
@@ -228,6 +228,11 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)#define pte_dirty (pte) (pte_isset((pte), L_PTE_DIRTY))#define pte_young (pte) (pte_isset((pte), L_PTE_YOUNG))#define pte_exec (pte) (pte_isclear((pte), L_PTE_XN)) +#ifdef CONFIG_ARCH_HAS_PTE_SPECIAL +#define pte_special (pte) (pte_isset((pte), L_PTE_SPECIAL)) +#else +#define pte_special (pte) (0) +#endif #define pte_valid_user (pte) \ (pte_valid(pte) && pte_isset((pte), L_PTE_USER) && pte_young(pte))
@@ -318,6 +323,14 @@ static inline pte_t pte_mknexec(pte_t pte)return set_pte_bit (pte,__pgprot (L_PTE_XN )); } +#ifdef CONFIG_ARCH_HAS_PTE_SPECIAL +static inline pte_t pte_mkspecial (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (L_PTE_SPECIAL )); +} +#else +static inline pte_t pte_mkspecial (pte_t pte) {return pte; } +#endif static inline pte_t pte_modify (pte_t pte,pgprot_t newprot) { const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
Signature · 1 line
2.19.0.rc1.350.ge57e33dbd1-goog
RFC 3/3 arm: mm: support get_user_pages_fast
In reply to Minchan KimRecently, there was a report get_user_pages_fast helps app launching speed due to reducing uninterruptible sleep time because we don't need to contend for mmap_sem, I believe.
With get_user_pages_fast, that uniterruptible sleep time is reduced about 5~10% by testing.
--- arch/arm/mm/Makefile | 6 ++ arch/arm/mm/gup.c | 221 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 arch/arm/mm/gup.c
arch/arm/mm/Makefile +6 -0
@@ -13,6 +13,12 @@ obj-y += nommu.o obj-$(CONFIG_ARM_MPU) += pmsa-v7.o pmsa-v8.o endif +ifneq ($(CONFIG_ARM_LPAE),y) +ifeq ($(CONFIG_ARCH_HAS_PTE_SPECIAL),y) +obj-$(CONFIG_MMU) += gup.o +endif +endif + obj-$(CONFIG_ARM_PTDUMP_CORE) += dump.o obj-$(CONFIG_ARM_PTDUMP_DEBUGFS) += ptdump_debugfs.o obj-$(CONFIG_MODULES) += proc-syms.o
arch/arm/mm/gup.c new file +221 -0
221 lines not on this page · raw message
Signature · 1 line
2.19.0.rc1.350.ge57e33dbd1-goog