[PATCH] malloc: remember that thp_mode got probed

Wilco Dijkstra Wilco.Dijkstra@arm.com
Thu Feb 26 15:38:06 GMT 2026


Hi Aurelien,

> On aarch64, following the new 2MB THP default introduced in 321e1fc73f53
> and when /sys/kernel is not accessible (as in some containers [1]),
> /sys/kernel/mm/transparent_hugepage/enabled is probed on every malloc()
> call.

That's strange, does that mean containers don't support THP at all, ever?

> This causes some performance regression, and also sets errno to ENOENT
> on each malloc call. Some programs are not prepared for that (even
> though they arguably should be), causing some regressions [2].

Interestingly that shows you get the exact same failures on any target if you
set glibc.malloc.hugetlb=2. So perhaps we should try to avoid setting errno in
malloc or just force errno=0 when we exit a path that may have used a system
call? Mmap, sbrk and madvise can also set errno, including in cases where we
retry and return a valid block.

> Fix that by introducing a new THP state, malloc_thp_mode_unknown, which
> is distinct from malloc_thp_mode_not_supported. This makes possible to
> record that the THP mode has been probed and found as not supported,
> avoiding repeatedly poking the file. In turns this "fixes" half of the
> regressions found so far.

The patch is OK since it avoids repeated initialization, but we do need to decide
how to handle errno in malloc (as this will still set errno on the first call to malloc
if the THP check fails).

Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>

Cheers,
Wilco


More information about the Libc-alpha mailing list