[PATCH v2 0/5] malloc: TCACHE improvement for free and calloc
Florian Weimer
fweimer@redhat.com
Tue Aug 27 16:17:56 GMT 2024
* Wilco Dijkstra:
> Hi Wangyang,
>
> So overall this looks a good improvement to me. I'm wondering whether you're
> planning further speedups? libc_malloc/free still do a lot of unnecessary work,
> initialization checks, errno save/restore etc, all of which are redundant in the fast path.
>
> For example, ignoring tagging/checking, libc_free should look like:
>
> void
> __libc_free (void *mem)
> {
> mstate ar_ptr;
> mchunkptr p; /* chunk corresponding to mem */
>
> if (mem == 0) /* free(0) has no effect */
> return;
>
> p = mem2chunk (mem);
> INTERNAL_SIZE_T size = chunksize (p);
>
> // no need for init check if we do it in slow path or always init at thread startup
> // no need for mmap check (blocks never fit in tcache)
> // no need for errno saving (no system calls in tcache path)
> if (tcache_free (p, size))
> return;
We can skip the mmap check only if we refuse to mmap small chunks, even
on fallback paths. It's not an unreasonable change, though.
Thanks,
Florian
More information about the Libc-alpha
mailing list