elf: Only build THP tests for ABIs that define THP-PAGE-SIZE
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
| redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
Commit Message
The THP tests added by 3d909a283085c82bdcc71e1cf06c0899506b664 only
make sense for ABIs that support THP. Also, some ABIs have a strict
limit for the PT_LOAD alignment value. For instance, on arc, the
large alignment makes the R_ARC_S25W_PCREL branch from __start to
__libc_start_mainn in the static tests exceed its +-16 6MB range.
Instead of using a default THP page size for all ABIs, only build and
run the THP tests for ABIs that define THP-PAGE-SIZE in their sysdeps
Makefile, and define THP-PAGE-SIZE for all ABIs whose kernel supports
transparent huge pages (HAVE_ARCH_TRANSPARENT_HUGEPAGE).
The value is the largest PMD transparent huge page size supported by
the ABI that does not exceed MAX_THP_PAGESIZE (larger THP page sizes
make the tests exit as unsupported at runtime):
* aarch64: 32MB (16KB base pages; 4KB uses 2MB, 64KB uses 512MB which
is larger than MAX_THP_PAGESIZE).
* arc: 2MB (MMUv4 only; the kernel supports 2MB and 16MB super pages,
but a 16MB PT_LOAD alignment can not be linked on arc).
* arm: 2MB (LPAE only).
* i386: 4MB (non-PAE PGD level huge page; PAE and 64-bit kernels use
2MB).
* loongarch: 32MB (default 16KB base pages; 4KB uses 2MB, 64KB uses
512MB which is larger than MAX_THP_PAGESIZE).
* mips: 32MB (16KB base pages on 64-bit and 32-bit huge TLB layouts;
4KB uses 2MB, 64KB uses 512MB which is larger than MAX_THP_PAGESIZE).
* powerpc: 16MB (book3s64 only; hash MMU with 64KB base pages uses
16MB, radix uses 2MB).
* riscv: 2MB (64-bit only).
* s390: 1MB (segment size).
* sparc: 8MB (sparc64 only, unchanged).
* x86_64: 2MB (also for x32).
The remaining Linux ABIs (alpha, csky, hppa, m68k, microblaze, or1k,
and sh) do not support transparent huge pages and no longer build the
THP tests.
Tested with a 'make check run-built-tests=no' on all affected ABIs
and checked on x86_64-linux-gnu and aarch64-linux-gnu.
---
sysdeps/unix/sysv/linux/Makefile | 34 ++++++++++++++--------
sysdeps/unix/sysv/linux/aarch64/Makefile | 8 +++++
sysdeps/unix/sysv/linux/arc/Makefile | 10 +++++++
sysdeps/unix/sysv/linux/arm/Makefile | 4 +++
sysdeps/unix/sysv/linux/i386/Makefile | 6 ++++
sysdeps/unix/sysv/linux/loongarch/Makefile | 10 ++++++-
sysdeps/unix/sysv/linux/mips/Makefile | 8 +++++
sysdeps/unix/sysv/linux/powerpc/Makefile | 5 ++++
sysdeps/unix/sysv/linux/riscv/Makefile | 6 ++++
sysdeps/unix/sysv/linux/s390/Makefile | 3 ++
sysdeps/unix/sysv/linux/x86_64/Makefile | 3 ++
11 files changed, 84 insertions(+), 13 deletions(-)
Comments
* Adhemerval Zanella:
> +# The THP tests are only built and run for ABIs that define THP-PAGE-SIZE
> +# in their sysdeps Makefile. THP-PAGE-SIZE is the largest PMD transparent
> +# huge page size the ABI supports that does not exceed MAX_THP_PAGESIZE
> +# (from sysdeps/generic/hugepages.h); PT_LOAD segments in the THP tests
> +# are aligned to it so that the kernel can map them to addresses aligned
> +# to the THP page size. Larger THP page sizes make the tests exit as
> +# unsupported at runtime.
> +ifneq (,$(THP-PAGE-SIZE))
> +
> +tests += \
> + tst-thp-1 \
> + tst-thp-1-pde \
> + tst-thp-1-static \
> + tst-thp-align \
> +# tests
> +tests-static += \
> + tst-thp-1-static \
> +# tests-static
> +modules-names += \
> + tst-thp-size-mod \
> +# modules-names
>
> THP-PAGE-SIZE-CFLAGS = -DTHP_PAGE_SIZE=$(THP-PAGE-SIZE)
> THP-PAGE-SIZE-LDFLAGS = -Wl,-z,max-page-size=$(THP-PAGE-SIZE)
> @@ -919,6 +928,7 @@ $(objpfx)strace-tst-thp-align-disabled.out: \
> $(evaluate-test)
> endif # [madvise]
> endif # $(cross-compiling)
> +endif # $(THP-PAGE-SIZE)
> endif # $(subdir) == elf
I think this makes it likely that we don't test THP on new
architectures. I suggest to set the default to 0x200000 and use 0 for
the opt-out on unsupported architectures.
Thanks,
Florian
@@ -697,19 +697,13 @@ $(objpfx)pldd: $(objpfx)xmalloc.o
tests += \
tst-rseq-tls-range \
tst-rseq-tls-range-4096 \
- tst-thp-1 \
- tst-thp-1-pde \
- tst-thp-1-static \
- tst-thp-align \
# tests
tests-static += \
tst-rseq-tls-range-4096-static \
tst-rseq-tls-range-static \
- tst-thp-1-static \
# tests-static
modules-names += \
tst-rseq-tls-range-mod \
- tst-thp-size-mod \
# modules-names
CFLAGS-tst-rseq-tls-range.c += -DMAIN_TLS_ALIGN=4
CFLAGS-tst-rseq-tls-range-4096.c += -DMAIN_TLS_ALIGN=4096
@@ -730,12 +724,27 @@ tests-special += \
# tests-special
endif
-ifndef THP-PAGE-SIZE
-# Align PT_LOAD segments in THP tests to THP page size so that kernel will
-# map PIE to the address aligned to THP page size. Default THP page size
-# to 2MB which can be overridden in Makefile in subdirectories.
-THP-PAGE-SIZE = 0x200000
-endif
+# The THP tests are only built and run for ABIs that define THP-PAGE-SIZE
+# in their sysdeps Makefile. THP-PAGE-SIZE is the largest PMD transparent
+# huge page size the ABI supports that does not exceed MAX_THP_PAGESIZE
+# (from sysdeps/generic/hugepages.h); PT_LOAD segments in the THP tests
+# are aligned to it so that the kernel can map them to addresses aligned
+# to the THP page size. Larger THP page sizes make the tests exit as
+# unsupported at runtime.
+ifneq (,$(THP-PAGE-SIZE))
+
+tests += \
+ tst-thp-1 \
+ tst-thp-1-pde \
+ tst-thp-1-static \
+ tst-thp-align \
+# tests
+tests-static += \
+ tst-thp-1-static \
+# tests-static
+modules-names += \
+ tst-thp-size-mod \
+# modules-names
THP-PAGE-SIZE-CFLAGS = -DTHP_PAGE_SIZE=$(THP-PAGE-SIZE)
THP-PAGE-SIZE-LDFLAGS = -Wl,-z,max-page-size=$(THP-PAGE-SIZE)
@@ -919,6 +928,7 @@ $(objpfx)strace-tst-thp-align-disabled.out: \
$(evaluate-test)
endif # [madvise]
endif # $(cross-compiling)
+endif # $(THP-PAGE-SIZE)
endif # $(subdir) == elf
ifeq ($(subdir),rt)
@@ -1,4 +1,12 @@
ifeq ($(subdir),elf)
+# The PMD transparent huge page size depends of the page size:
+# * 4Kb -> 2MB
+# * 16Kb -> 32MB
+# * 64Kb -> 512MB
+# Use 32MB for now. The 512MB is larger than MAX_THP_PAGESIZE, and
+# the THP tests are marked as unsupported at runtime.
+THP-PAGE-SIZE = 0x2000000
+
tests += \
tst-tlsdesc-pac \
# tests
@@ -11,3 +11,13 @@ ifeq ($(subdir),misc)
sysdep_headers += sys/cachectl.h
sysdep_routines += cacheflush
endif
+
+ifeq ($(subdir),elf)
+# Only MMUv4 supports transparent huge pages. The huge page size is a
+# kernel configuration choice (ARC_HUGEPAGE_2M or ARC_HUGEPAGE_16M) which
+# pegs the page table layout to a 2MB or 16MB super page. Only the
+# default 2MB is supported: a 16MB PT_LOAD alignment can not be linked
+# on arc because the R_ARC_S25W_PCREL branch from __start to
+# __libc_start_main in static tests has a +-16MB range.
+THP-PAGE-SIZE = 0x200000
+endif
@@ -8,6 +8,10 @@ CFLAGS-tst-nolink-libc.c += -marm
# https://sourceware.org/bugzilla/show_bug.cgi?id=34096
test-xfail-tst-thp-1-no-s-code-static = yes
test-xfail-tst-thp-1-static = yes
+
+# Only LPAE kernels support transparent huge pages, with a 2MB PMD huge
+# page.
+THP-PAGE-SIZE = 0x200000
endif
ifeq ($(subdir),misc)
@@ -28,3 +28,9 @@ ifeq ($(subdir),rt)
librt-routines += sysdep
librt-shared-only-routines += sysdep
endif
+
+ifeq ($(subdir),elf)
+# Non-PAE kernels map the transparent huge page at the PGD level (4MB),
+# while PAE and 64-bit kernels use a 2MB PMD huge page.
+THP-PAGE-SIZE = 0x400000
+endif
@@ -13,5 +13,13 @@ abi-ilp32d-condition := __WORDSIZE == 32 && defined __loongarch_double_float
abi-lp64s-condition := __WORDSIZE == 64 && defined __loongarch_soft_float
abi-lp64d-condition := __WORDSIZE == 64 && defined __loongarch_double_float
-# Align THP tests to 32MB.
+ifeq ($(subdir),elf)
+# The PMD transparent huge page size depends of the page size:
+# * 4KB -> 2MB
+# * 16KB -> 32MB
+# * 64KB -> 512MB
+# Use 32MB for now, which is also de default. The 512MB is larger
+# than MAX_THP_PAGESIZE, and the THP tests are marked as unsupported
+# at runtime.
THP-PAGE-SIZE = 0x2000000
+endif
@@ -63,6 +63,14 @@ ifneq ($(mips-has-gnustack),yes)
test-xfail-check-execstack = yes
CFLAGS-tst-execstack.c += -DDEFAULT_RWX_STACK=1
endif
+
+# The PMD transparent huge page size depends of the page size:
+# * 4KB -> 2MB
+# * 16KB -> 32MB
+# * 64KB -> 512MB
+# Use 32MB for now. The 512MB is larger than MAX_THP_PAGESIZE, and
+# the THP tests are marked as unsupported at runtime.
+THP-PAGE-SIZE = 0x2000000
endif
ifeq ($(subdir),stdlib)
@@ -17,6 +17,11 @@ dl-routines += \
dl-hwcap-info \
# dl-routines
+# Only book3s64 supports transparent huge pages. The radix MMU uses a 2MB
+# PMD huge page, while the hash MMU (with 64KB base pages) uses a 16MB
+# huge page.
+THP-PAGE-SIZE = 0x1000000
+
# Otherwise tst-tls-dlinfo fails due to tst-tlsmod2.so using static tls.
ifeq ($(have-tls-get-addr-optimize),yes)
LDFLAGS-tst-tlsmod2.so += -Wl,--no-tls-get-addr-optimize
@@ -15,6 +15,12 @@ ifeq ($(subdir),stdlib)
gen-as-const-headers += ucontext_i.sym
endif
+ifeq ($(subdir),elf)
+# Only 64-bit kernels support transparent huge pages, with a 2MB PMD huge
+# page.
+THP-PAGE-SIZE = 0x200000
+endif
+
abi-variants := ilp32 ilp32d lp64 lp64d
ifeq (,$(filter $(default-abi),$(abi-variants)))
@@ -1,4 +1,7 @@
ifeq ($(subdir),elf)
+# The segment (PMD) transparent huge page size is 1MB.
+THP-PAGE-SIZE = 0x100000
+
ifeq (yes,$(build-shared))
# This is needed to support g++ v2 and v3.
sysdep_routines += \
@@ -17,6 +17,9 @@ gen-as-const-headers += sigaltstack-offsets.sym
endif
ifeq ($(subdir),elf)
+# The PMD transparent huge page size is 2MB.
+THP-PAGE-SIZE = 0x200000
+
ifeq (yes,$(enable-x86-isa-level))
tests += \
tst-glibc-hwcaps-2 \