talloc vs malloc speed

Florian Weimer fweimer at redhat.com
Mon Apr 17 11:07:59 UTC 2023


* Andreas Schneider:

> Yes, we have support for destructor callbacks. Can you point me to the 
> attributes which might help talloc?

I think of those listed here

  <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html>

alloc_align, alloc_size, malloc, nothrow, returns_nonnull are relevant,
but not all them might be appropriate due to the way talloc works.

These attributes are mostly about improving diagnostics, I think, not so
much for performance.

>> If talloc is layered on top of system malloc, using its own allocator
>> geared to its particular metadata requirements could reduce memory
>> overhead and make certain things go faster, but it's also a lot of work.
>
> talloc is basically a bunch of pointer arithmetic around malloc()/free() call.
>
> It has desctructors and also keeps track of the hierarchy. So you can free a 
> an allocated pointer with all its children.
>
> Interesting that those few pointer calculations make it so much slower.

That's indeed surprising (especially if talloc doesn't take locks around
allocations and frees).  Maybe the working set size exceeds the CPU
cache size due to the metadata size increase?

Thanks,
Florian




More information about the samba-technical mailing list