[PATCH] malloc: Show hugetlb tunable default in --list-tunables
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Wed Mar 11 14:19:04 GMT 2026
On 10/03/26 16:31, Wilco Dijkstra wrote:
>
> Explicitly set the hugetlb tunable value in aarch64/cpu-features.c so it
> is shown as 1 with /lib/ld-linux-aarch64.so.1 --list-tunables.
> Move the intitialization of thp_mode/thp_pagesize to do_set_hugetlb() and
> avoid accessing /sys/kernel/mm if DEFAULT_THP_PAGESIZE > 0.
>
> Passes regress, OK for commit?
>
> ---
>
> diff --git a/malloc/arena.c b/malloc/arena.c
> index 75f2f32b5f61a33a06dc285ca9899a708c78cf10..d2ed6279226856d630cfdf734303c4b936512f58 100644
> --- a/malloc/arena.c
> +++ b/malloc/arena.c
> @@ -275,15 +275,6 @@ __ptmalloc_init (void)
> __always_fail_morecore = true;
> #endif
>
> - /* Enable THP if DEFAULT_THP_PAGESIZE is non-zero. Avoid quering the THP
> - page size or mode since accessing /sys/kernel/mm is relatively slow and
> - might not be accessible in containers. */
> - if (DEFAULT_THP_PAGESIZE > 0)
> - {
> - mp_.thp_mode = malloc_thp_mode_madvise;
> - mp_.thp_pagesize = DEFAULT_THP_PAGESIZE;
> - }
> -
> thread_arena = &main_arena;
>
> malloc_init_state (&main_arena);
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 4aac196533d896353e3a32e34fa143d03eb82627..7241a79a936999ab5c3ac989133ad4c7919eec31 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -5026,13 +5026,25 @@ do_set_mxfast (size_t value)
> static __always_inline int
> do_set_hugetlb (size_t value)
> {
> + /* Enable THP if DEFAULT_THP_PAGESIZE is non-zero. */
> + if (DEFAULT_THP_PAGESIZE > 0)
> + {
> + mp_.thp_mode = malloc_thp_mode_madvise;
> + mp_.thp_pagesize = DEFAULT_THP_PAGESIZE;
> + }
> +
> if (value == 0)
> mp_.thp_mode = malloc_thp_mode_never;
> else if (value == 1)
> {
> + /* Avoid querying the THP page size/mode since accessing /sys/kernel/mm
> + is relatively slow and might not be accessible in containers. */
> + if (DEFAULT_THP_PAGESIZE > 0)
> + return 0;
> +
> mp_.thp_mode = __malloc_thp_mode ();
> if (mp_.thp_mode == malloc_thp_mode_madvise
> - || mp_.thp_mode == malloc_thp_mode_always)
> + || mp_.thp_mode == malloc_thp_mode_always)
This seems an spurious indentation change.
> mp_.thp_pagesize = __malloc_default_thp_pagesize ();
> }
> else if (value >= 2)
> diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
> index 70d3272772f5f36a3435d0ae8919d781a1e2412e..af502eff82e05efbe0a2e9418a71473e5c7ec8b9 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
> +++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
> @@ -179,4 +179,8 @@ init_cpu_features (struct cpu_features *cpu_features)
> if (GLRO (dl_hwcap) & HWCAP_GCS)
> /* GCS status may be updated later by binary compatibility checks. */
> GL (dl_aarch64_gcs) = TUNABLE_GET (glibc, cpu, aarch64_gcs, uint64_t, 0);
> +
> + /* Default to glibc.malloc.hugetlb=1 if the tunable is not set. */
> + if (!TUNABLE_IS_INITIALIZED (glibc, malloc, hugetlb))
> + TUNABLE_SET (glibc, malloc, hugetlb, 1);
> }
>
Since DEFAULT_THP_PAGESIZE logic could be used by other ABIs, I think we should
make the glibc.malloc.hugetlb change done in dl-tunables.c. I would avoid
requiring each ABIs to add this logic if it defines DEFAULT_THP_PAGESIZE.
More information about the Libc-alpha
mailing list