[PATCH] malloc: Avoid accessing /sys/kernel/mm files

Aurelien Jarno aurelien@aurel32.net
Sun Mar 1 21:37:33 GMT 2026


Hi Wilco,

On 2026-02-27 21:03, Wilco Dijkstra wrote:
> 
> On AArch64 malloc always checks /sys/kernel/mm/transparent_hugepage/enabled to set
> the THP mode. However this check is quite expensive and the file may not be accessible
> in containers. If DEFAULT_THP_PAGESIZE is non-zero, use malloc_thp_mode_madvise so that
> we take advantage of THP in all cases. Since madvise is a fast systemcall, it adds only
> a small overhead compared to the cost of mmap and populating the pages.
> 
> Passes regress, OK for commit?

The strategy sounds good if you confirm it does not have performance 
impact. Not having to probe a file in /sys is definitely way better. 

I have tested this patch. The apparmor warnings are gone. And among all 
the issues I have found with 2MB THP, it seems that only rumur is still 
failing in its testsuite, but in a different way than before. I'll try 
to debug and report back.

Otherwise the patch looks good to me. I still believe the patch I sent 
("malloc: remember that thp_mode got probed") is needed for the case 
where the glibc.malloc.hugetlb tunable is set to 2 (especially if the 
system-wide default tunable get accepted). But it's a minor issue, and 
I'll just resend a v2 after your patch is committed.

Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net


More information about the Libc-alpha mailing list