[PATCH v5 6/6] loongarch: Enable THP-aligned load segments by default on 64-bit
WANG Rui
wangrui@loongson.cn
Fri Mar 6 13:48:48 GMT 2026
On LoongArch64 Linux, aligning ELF load segments to Transparent Huge Page
(THP) boundaries provides consistent performance benefits for large
binaries by reducing TLB pressure and improving instruction fetch
efficiency.
Enable THP-based load segment alignment by default on LoongArch64 by
setting `glibc.elf.hugetlb=1` during startup. Define the default THP
page size for load segment alignment on LoongArch64 as 32MB.
This allows the dynamic loader to apply THP-friendly alignment without
requiring the `glibc.elf.hugetlb` tunable to be explicitly set.
* sysdeps/unix/sysv/linux/loongarch/cpu-features.c
(init_cpu_features): Set glibc.elf.hugetlb to 1 by default on LoongArch64.
* sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h:
Define DL_MAP_DEFAULT_THP_PAGESIZE as 32MB.
Signed-off-by: WANG Rui <wangrui@loongson.cn>
---
.../unix/sysv/linux/loongarch/cpu-features.c | 6 +++++
.../loongarch/lp64/dl-map-segment-align.h | 22 +++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h
diff --git a/sysdeps/unix/sysv/linux/loongarch/cpu-features.c b/sysdeps/unix/sysv/linux/loongarch/cpu-features.c
index 0c125e64e2b..4da3f1ad4ee 100644
--- a/sysdeps/unix/sysv/linux/loongarch/cpu-features.c
+++ b/sysdeps/unix/sysv/linux/loongarch/cpu-features.c
@@ -27,4 +27,10 @@ init_cpu_features (struct cpu_features *cpu_features)
GLRO(dl_larch_cpu_features).hwcap = GLRO(dl_hwcap);
TUNABLE_GET (glibc, cpu, hwcaps, tunable_val_t *,
TUNABLE_CALLBACK (set_hwcaps));
+
+#ifdef __LP64__
+ /* Enable THP-based load segment alignment by default on LoongArch64. */
+ if (!TUNABLE_IS_INITIALIZED (glibc, elf, hugetlb))
+ TUNABLE_SET (glibc, elf, hugetlb, 1);
+#endif
}
diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h b/sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h
new file mode 100644
index 00000000000..c51ee4ac47e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h
@@ -0,0 +1,22 @@
+/* _dl_map_segment_align. LoongArch64 Linux version.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ Copyright The GNU Toolchain Authors.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define DL_MAP_DEFAULT_THP_PAGESIZE (32 * 1024 * 1024)
+
+#include_next <dl-map-segment-align.h>
--
2.53.0
More information about the Libc-alpha
mailing list