[PATCH] malloc: retire mechanism for older non used tcached chunks

Florian Weimer fweimer@redhat.com
Thu Nov 13 14:43:39 GMT 2025


* Cupertino Miranda:

> +      /* Move chunk to retire bin if chunk is beyond tcache capacity.
> +       * We should always do (alloc_size_state - cached_at) before attempting
> +       * any comparissons.  This is a requirement to keep the comparisson valid
> +       * in the cases where one of the values has wraparound.  */

Our usual comment style does not use “*” at the beginning of lines.

> +      if (tcache->alloc_size_state - te->cached_at > mp_.tcache_retire_size)
> +        {
> +          uint16_t not_used = 1;
> +          tcache_entry *e = tcache_get_n (tep, num_slots, *mangled);
> +	  tcache_put_n (mem2chunk (e), &tcache->return_to_arena, &not_used,
> +			false);
> +          te = *mangled == false ? *tep : REVEAL_PTR (*tep);
> +          continue;
> +        }

It's not entirely clear to me way return_to_arena is used.

> +      while (tcache_tmp->return_to_arena)
> +	{
> +	  tcache_entry *e = tcache_tmp->return_to_arena;
> +	  if (__glibc_unlikely (misaligned_mem (e)))
> +	    malloc_printerr ("tcache_thread_shutdown(): "
> +			     "unaligned tcache chunk detected");
> +	  tcache_tmp->return_to_arena = REVEAL_PTR (e->next);
> +	  __libc_free (e);

These needs a comment why this actually returns allocations to the
arena.  And if it doesn't why this isn't necessary.

Thanks,
Florian



More information about the Libc-alpha mailing list