arch: consolidate existing CONFIG_PAGE_SIZE_*KB definitions
authorArnd Bergmann <arnd@arndb.de>
Fri, 23 Feb 2024 22:18:37 +0000 (23:18 +0100)
committerArnd Bergmann <arnd@arndb.de>
Wed, 6 Mar 2024 18:28:26 +0000 (19:28 +0100)
These four architectures define the same Kconfig symbols for configuring
the page size. Move the logic into a common place where it can be shared
with all other architectures.

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/Kconfig
arch/hexagon/Kconfig
arch/hexagon/include/asm/page.h
arch/loongarch/Kconfig
arch/loongarch/include/asm/page.h
arch/mips/Kconfig
arch/mips/include/asm/page.h
arch/sh/include/asm/page.h
arch/sh/mm/Kconfig

index a5af0edd3eb8f3b64e6e51bffb2ac491cb31bc26..fd18b7db2c777bb1223ffd0a4bcf0d5b11633330 100644 (file)
@@ -1078,17 +1078,107 @@ config HAVE_ARCH_COMPAT_MMAP_BASES
          and vice-versa 32-bit applications to call 64-bit mmap().
          Required for applications doing different bitness syscalls.
 
+config HAVE_PAGE_SIZE_4KB
+       bool
+
+config HAVE_PAGE_SIZE_8KB
+       bool
+
+config HAVE_PAGE_SIZE_16KB
+       bool
+
+config HAVE_PAGE_SIZE_32KB
+       bool
+
+config HAVE_PAGE_SIZE_64KB
+       bool
+
+config HAVE_PAGE_SIZE_256KB
+       bool
+
+choice
+       prompt "MMU page size"
+
+config PAGE_SIZE_4KB
+       bool "4KiB pages"
+       depends on HAVE_PAGE_SIZE_4KB
+       help
+         This option select the standard 4KiB Linux page size and the only
+         available option on many architectures. Using 4KiB page size will
+         minimize memory consumption and is therefore recommended for low
+         memory systems.
+         Some software that is written for x86 systems makes incorrect
+         assumptions about the page size and only runs on 4KiB pages.
+
+config PAGE_SIZE_8KB
+       bool "8KiB pages"
+       depends on HAVE_PAGE_SIZE_8KB
+       help
+         This option is the only supported page size on a few older
+         processors, and can be slightly faster than 4KiB pages.
+
+config PAGE_SIZE_16KB
+       bool "16KiB pages"
+       depends on HAVE_PAGE_SIZE_16KB
+       help
+         This option is usually a good compromise between memory
+         consumption and performance for typical desktop and server
+         workloads, often saving a level of page table lookups compared
+         to 4KB pages as well as reducing TLB pressure and overhead of
+         per-page operations in the kernel at the expense of a larger
+         page cache.
+
+config PAGE_SIZE_32KB
+       bool "32KiB pages"
+       depends on HAVE_PAGE_SIZE_32KB
+       help
+         Using 32KiB page size will result in slightly higher performance
+         kernel at the price of higher memory consumption compared to
+         16KiB pages.  This option is available only on cnMIPS cores.
+         Note that you will need a suitable Linux distribution to
+         support this.
+
+config PAGE_SIZE_64KB
+       bool "64KiB pages"
+       depends on HAVE_PAGE_SIZE_64KB
+       help
+         Using 64KiB page size will result in slightly higher performance
+         kernel at the price of much higher memory consumption compared to
+         4KiB or 16KiB pages.
+         This is not suitable for general-purpose workloads but the
+         better performance may be worth the cost for certain types of
+         supercomputing or database applications that work mostly with
+         large in-memory data rather than small files.
+
+config PAGE_SIZE_256KB
+       bool "256KiB pages"
+       depends on HAVE_PAGE_SIZE_256KB
+       help
+         256KiB pages have little practical value due to their extreme
+         memory usage.  The kernel will only be able to run applications
+         that have been compiled with '-zmax-page-size' set to 256KiB
+         (the default is 64KiB or 4KiB on most architectures).
+
+endchoice
+
 config PAGE_SIZE_LESS_THAN_64KB
        def_bool y
-       depends on !ARM64_64K_PAGES
        depends on !PAGE_SIZE_64KB
-       depends on !PARISC_PAGE_SIZE_64KB
        depends on PAGE_SIZE_LESS_THAN_256KB
 
 config PAGE_SIZE_LESS_THAN_256KB
        def_bool y
        depends on !PAGE_SIZE_256KB
 
+config PAGE_SHIFT
+       int
+       default 12 if PAGE_SIZE_4KB
+       default 13 if PAGE_SIZE_8KB
+       default 14 if PAGE_SIZE_16KB
+       default 15 if PAGE_SIZE_32KB
+       default 16 if PAGE_SIZE_64KB
+       default 18 if PAGE_SIZE_256KB
+
 # This allows to use a set of generic functions to determine mmap base
 # address by giving priority to top-down scheme only if the process
 # is not in legacy mode (compat task, unlimited stack size or
index a880ee067d2ec20c10b7c3c5827b34b7aa8a62a0..1414052e7d6b2ad5c22975d1cb5b002f558ebc1e 100644 (file)
@@ -8,6 +8,10 @@ config HEXAGON
        select ARCH_HAS_SYNC_DMA_FOR_DEVICE
        select ARCH_NO_PREEMPT
        select DMA_GLOBAL_POOL
+       select HAVE_PAGE_SIZE_4KB
+       select HAVE_PAGE_SIZE_16KB
+       select HAVE_PAGE_SIZE_64KB
+       select HAVE_PAGE_SIZE_256KB
        # Other pending projects/to-do items.
        # select HAVE_REGS_AND_STACK_ACCESS_API
        # select HAVE_HW_BREAKPOINT if PERF_EVENTS
@@ -120,26 +124,6 @@ config NR_CPUS
          This is purely to save memory - each supported CPU adds
          approximately eight kilobytes to the kernel image.
 
-choice
-       prompt "Kernel page size"
-       default PAGE_SIZE_4KB
-       help
-         Changes the default page size; use with caution.
-
-config PAGE_SIZE_4KB
-       bool "4KB"
-
-config PAGE_SIZE_16KB
-       bool "16KB"
-
-config PAGE_SIZE_64KB
-       bool "64KB"
-
-config PAGE_SIZE_256KB
-       bool "256KB"
-
-endchoice
-
 source "kernel/Kconfig.hz"
 
 endmenu
index 32394b7e752e6823b3afef47d0cf7ea981e3022a..8a6af57274c2dbc271da1105afa7bf7b5c00f8e3 100644 (file)
 /*  This is probably not the most graceful way to handle this.  */
 
 #ifdef CONFIG_PAGE_SIZE_4KB
-#define PAGE_SHIFT 12
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_16KB
-#define PAGE_SHIFT 14
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_64KB
-#define PAGE_SHIFT 16
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_256KB
-#define PAGE_SHIFT 18
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_256KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_1MB
-#define PAGE_SHIFT 20
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_1MB
 #endif
 
@@ -50,6 +45,7 @@
 #define HVM_HUGEPAGE_SIZE 0x5
 #endif
 
+#define PAGE_SHIFT CONFIG_PAGE_SHIFT
 #define PAGE_SIZE  (1UL << PAGE_SHIFT)
 #define PAGE_MASK  (~((1 << PAGE_SHIFT) - 1))
 
index 929f68926b3432e52a6d7b84a92d402a5d8bc11a..b274784c2e261a0e51369de70e7874b81b87a536 100644 (file)
@@ -227,15 +227,6 @@ config MACH_LOONGSON64
 config FIX_EARLYCON_MEM
        def_bool y
 
-config PAGE_SIZE_4KB
-       bool
-
-config PAGE_SIZE_16KB
-       bool
-
-config PAGE_SIZE_64KB
-       bool
-
 config PGTABLE_2LEVEL
        bool
 
@@ -288,7 +279,7 @@ choice
 
 config 4KB_3LEVEL
        bool "4KB with 3 levels"
-       select PAGE_SIZE_4KB
+       select HAVE_PAGE_SIZE_4KB
        select PGTABLE_3LEVEL
        help
          This option selects 4KB page size with 3 level page tables, which
@@ -296,7 +287,7 @@ config 4KB_3LEVEL
 
 config 4KB_4LEVEL
        bool "4KB with 4 levels"
-       select PAGE_SIZE_4KB
+       select HAVE_PAGE_SIZE_4KB
        select PGTABLE_4LEVEL
        help
          This option selects 4KB page size with 4 level page tables, which
@@ -304,7 +295,7 @@ config 4KB_4LEVEL
 
 config 16KB_2LEVEL
        bool "16KB with 2 levels"
-       select PAGE_SIZE_16KB
+       select HAVE_PAGE_SIZE_16KB
        select PGTABLE_2LEVEL
        help
          This option selects 16KB page size with 2 level page tables, which
@@ -312,7 +303,7 @@ config 16KB_2LEVEL
 
 config 16KB_3LEVEL
        bool "16KB with 3 levels"
-       select PAGE_SIZE_16KB
+       select HAVE_PAGE_SIZE_16KB
        select PGTABLE_3LEVEL
        help
          This option selects 16KB page size with 3 level page tables, which
@@ -320,7 +311,7 @@ config 16KB_3LEVEL
 
 config 64KB_2LEVEL
        bool "64KB with 2 levels"
-       select PAGE_SIZE_64KB
+       select HAVE_PAGE_SIZE_64KB
        select PGTABLE_2LEVEL
        help
          This option selects 64KB page size with 2 level page tables, which
@@ -328,7 +319,7 @@ config 64KB_2LEVEL
 
 config 64KB_3LEVEL
        bool "64KB with 3 levels"
-       select PAGE_SIZE_64KB
+       select HAVE_PAGE_SIZE_64KB
        select PGTABLE_3LEVEL
        help
          This option selects 64KB page size with 3 level page tables, which
index 63f137ce82a41fc4e251f2adceef441e72dcd691..afb6fa16b82636caed29820a118a895f7446ad72 100644 (file)
 /*
  * PAGE_SHIFT determines the page size
  */
-#ifdef CONFIG_PAGE_SIZE_4KB
-#define PAGE_SHIFT     12
-#endif
-#ifdef CONFIG_PAGE_SIZE_16KB
-#define PAGE_SHIFT     14
-#endif
-#ifdef CONFIG_PAGE_SIZE_64KB
-#define PAGE_SHIFT     16
-#endif
+#define PAGE_SHIFT     CONFIG_PAGE_SHIFT
 #define PAGE_SIZE      (_AC(1, UL) << PAGE_SHIFT)
 #define PAGE_MASK      (~(PAGE_SIZE - 1))
 
index 797ae590ebdba505c313b448720c7207b29673f8..24bac93affee940d14c3791a76394c693235b506 100644 (file)
@@ -81,6 +81,9 @@ config MIPS
        select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
        select HAVE_MOD_ARCH_SPECIFIC
        select HAVE_NMI
+       select HAVE_PAGE_SIZE_4KB if !CPU_LOONGSON2EF && !CPU_LOONGSON64
+       select HAVE_PAGE_SIZE_16KB if !CPU_R3000
+       select HAVE_PAGE_SIZE_64KB if !CPU_R3000
        select HAVE_PERF_EVENTS
        select HAVE_PERF_REGS
        select HAVE_PERF_USER_STACK_DUMP
@@ -1608,6 +1611,8 @@ config CPU_CAVIUM_OCTEON
        depends on SYS_HAS_CPU_CAVIUM_OCTEON
        select CPU_HAS_PREFETCH
        select CPU_SUPPORTS_64BIT_KERNEL
+       select HAVE_PAGE_SIZE_8KB if !MIPS_VA_BITS_48
+       select HAVE_PAGE_SIZE_32KB if !MIPS_VA_BITS_48
        select WEAK_ORDERING
        select CPU_SUPPORTS_HIGHMEM
        select CPU_SUPPORTS_HUGEPAGES
@@ -2029,59 +2034,6 @@ config ZBOOT_LOAD_ADDRESS
 
          This is only used if non-zero.
 
-choice
-       prompt "Kernel page size"
-       default PAGE_SIZE_4KB
-
-config PAGE_SIZE_4KB
-       bool "4kB"
-       depends on !CPU_LOONGSON2EF && !CPU_LOONGSON64
-       help
-         This option select the standard 4kB Linux page size.  On some
-         R3000-family processors this is the only available page size.  Using
-         4kB page size will minimize memory consumption and is therefore
-         recommended for low memory systems.
-
-config PAGE_SIZE_8KB
-       bool "8kB"
-       depends on CPU_CAVIUM_OCTEON
-       depends on !MIPS_VA_BITS_48
-       help
-         Using 8kB page size will result in higher performance kernel at
-         the price of higher memory consumption.  This option is available
-         only on cnMIPS processors.  Note that you will need a suitable Linux
-         distribution to support this.
-
-config PAGE_SIZE_16KB
-       bool "16kB"
-       depends on !CPU_R3000
-       help
-         Using 16kB page size will result in higher performance kernel at
-         the price of higher memory consumption.  This option is available on
-         all non-R3000 family processors.  Note that you will need a suitable
-         Linux distribution to support this.
-
-config PAGE_SIZE_32KB
-       bool "32kB"
-       depends on CPU_CAVIUM_OCTEON
-       depends on !MIPS_VA_BITS_48
-       help
-         Using 32kB page size will result in higher performance kernel at
-         the price of higher memory consumption.  This option is available
-         only on cnMIPS cores.  Note that you will need a suitable Linux
-         distribution to support this.
-
-config PAGE_SIZE_64KB
-       bool "64kB"
-       depends on !CPU_R3000
-       help
-         Using 64kB page size will result in higher performance kernel at
-         the price of higher memory consumption.  This option is available on
-         all non-R3000 family processor.  Not that at the time of this
-         writing this option is still high experimental.
-
-endchoice
-
 config ARCH_FORCE_MAX_ORDER
        int "Maximum zone order"
        default "13" if MIPS_HUGE_TLB_SUPPORT && PAGE_SIZE_64KB
index ef9585d96f6b08f2ba6d0edcb5031acdb6ca573d..4609cb0326cf31f18465896d26b23ce0e5fdd553 100644 (file)
 /*
  * PAGE_SHIFT determines the page size
  */
-#ifdef CONFIG_PAGE_SIZE_4KB
-#define PAGE_SHIFT     12
-#endif
-#ifdef CONFIG_PAGE_SIZE_8KB
-#define PAGE_SHIFT     13
-#endif
-#ifdef CONFIG_PAGE_SIZE_16KB
-#define PAGE_SHIFT     14
-#endif
-#ifdef CONFIG_PAGE_SIZE_32KB
-#define PAGE_SHIFT     15
-#endif
-#ifdef CONFIG_PAGE_SIZE_64KB
-#define PAGE_SHIFT     16
-#endif
+#define PAGE_SHIFT     CONFIG_PAGE_SHIFT
 #define PAGE_SIZE      (_AC(1,UL) << PAGE_SHIFT)
 #define PAGE_MASK      (~((1 << PAGE_SHIFT) - 1))
 
index 62f4b9edcb985a3a1ce1b8c572a5763bccd312c3..f780b467e75d7c38316baf1a1beb8707f1fc6d91 100644 (file)
@@ -9,18 +9,7 @@
 #include <linux/const.h>
 
 /* PAGE_SHIFT determines the page size */
-#if defined(CONFIG_PAGE_SIZE_4KB)
-# define PAGE_SHIFT    12
-#elif defined(CONFIG_PAGE_SIZE_8KB)
-# define PAGE_SHIFT    13
-#elif defined(CONFIG_PAGE_SIZE_16KB)
-# define PAGE_SHIFT    14
-#elif defined(CONFIG_PAGE_SIZE_64KB)
-# define PAGE_SHIFT    16
-#else
-# error "Bogus kernel page size?"
-#endif
-
+#define PAGE_SHIFT     CONFIG_PAGE_SHIFT
 #define PAGE_SIZE      (_AC(1, UL) << PAGE_SHIFT)
 #define PAGE_MASK      (~(PAGE_SIZE-1))
 #define PTE_MASK       PAGE_MASK
index 455311d9a5e9c9708753cb1cfac680c5fea5ca03..f32a1963ff0c5693da82fd234ebbc617fd8b27a5 100644 (file)
@@ -4,6 +4,9 @@ menu "Memory management options"
 config MMU
         bool "Support for memory management hardware"
        depends on !CPU_SH2
+       select HAVE_PAGE_SIZE_4KB
+       select HAVE_PAGE_SIZE_8KB if X2TLB
+       select HAVE_PAGE_SIZE_64KB if CPU_SH4
        default y
        help
          Some SH processors (such as SH-2/SH-2A) lack an MMU. In order to
@@ -13,6 +16,15 @@ config MMU
          turning this off will boot the kernel on these machines with the
          MMU implicitly switched off.
 
+config NOMMU
+       def_bool !MMU
+       select HAVE_PAGE_SIZE_4KB
+       select HAVE_PAGE_SIZE_8KB
+       select HAVE_PAGE_SIZE_16KB
+       select HAVE_PAGE_SIZE_64KB
+       help
+         On MMU-less systems, any of these page sizes can be selected
+
 config PAGE_OFFSET
        hex
        default "0x80000000" if MMU
@@ -147,36 +159,6 @@ config HAVE_SRAM_POOL
        bool
        select GENERIC_ALLOCATOR
 
-choice
-       prompt "Kernel page size"
-       default PAGE_SIZE_4KB
-
-config PAGE_SIZE_4KB
-       bool "4kB"
-       help
-         This is the default page size used by all SuperH CPUs.
-
-config PAGE_SIZE_8KB
-       bool "8kB"
-       depends on !MMU || X2TLB
-       help
-         This enables 8kB pages as supported by SH-X2 and later MMUs.
-
-config PAGE_SIZE_16KB
-       bool "16kB"
-       depends on !MMU
-       help
-         This enables 16kB pages on MMU-less SH systems.
-
-config PAGE_SIZE_64KB
-       bool "64kB"
-       depends on !MMU || CPU_SH4
-       help
-         This enables support for 64kB pages, possible on all SH-4
-         CPUs and later.
-
-endchoice
-
 choice
        prompt "HugeTLB page size"
        depends on HUGETLB_PAGE