[PATCH v4 1/3] malloc: Avoid func call for tcache quick path in free()
H.J. Lu
hjl.tools@gmail.com
Tue Nov 26 22:09:18 GMT 2024
On Tue, Nov 26, 2024 at 3:37 PM Wangyang Guo <wangyang.guo@intel.com> wrote:
>
> Tcache is an important optimzation to accelerate memory free(), things
> within this code path should be kept as simple as possible. This commit
> try to remove the function call when free() invokes tcache code path by
> inlining _int_free().
>
> Result of bench-malloc-thread benchmark
>
> Test Platform: Xeon-8380
> Ratio: New / Original time_per_iteration (Lower is Better)
>
> Threads# | Ratio
> -----------|------
> 1 thread | 0.879
> 4 threads | 0.874
>
> The performance data shows it can improve bench-malloc-thread benchmark
> by ~12% in both single thread and multi-thread scenario.
>
> ---
> Changes in v4:
> - inline _int_free instead of manual inlining.
> - Link to v3: https://sourceware.org/pipermail/libc-alpha/2024-August/159505.html
> No Changes in v3
> Changes in v2:
> - _int_free_check() should be put outside of USE_TCACHE.
> - Link to v1: https://sourceware.org/pipermail/libc-alpha/2024-August/159359.html
> ---
> malloc/malloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 32dbc272a8..81ddd2c3a8 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -4677,7 +4677,7 @@ _int_free_chunk (mstate av, mchunkptr p, INTERNAL_SIZE_T size, int have_lock)
> P has already been locked. It will perform sanity check, then try the
> fast path to free into tcache. If the attempt not success, free the
> chunk to arena. */
> -static void
> +static inline void
> _int_free (mstate av, mchunkptr p, int have_lock)
> {
> INTERNAL_SIZE_T size; /* its size */
> --
> 2.43.5
>
LGTM.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Do you have the commit access?
Thanks.
--
H.J.
More information about the Libc-alpha
mailing list