[PATCH v5 2/7] malloc: optimize initialization

Wilco Dijkstra Wilco.Dijkstra@arm.com
Fri Mar 21 15:59:51 GMT 2025


Hi Cupertino,

> This patch adds __glibc_unlikely to all conditions related to the call
> to ptmalloc_init which check if __malloc_initialized variable is set.

> -  if (!__malloc_initialized)
> +  if (__glibc_unlikely (!__malloc_initialized))
>     ptmalloc_init ();

What difference did you see as a result (not sure whether it is in your graph)?
I benchmarked it against current trunk, and there is no difference in generated
code of all the key malloc/free functions. There are some improvements in less
frequently used functions, so it looks worthwhile, but I'd like to understand the
reasoning behind it.

Note in my __libc_malloc patch I moved this initialization after the tcache code.
The same could be done in several other cases. Moving it gives large gains
since you avoid doing unnecessary work before the tcache code.

Cheers,
Wilco


More information about the Libc-alpha mailing list