talloc vs malloc speed

Florian Weimer fweimer at redhat.com
Mon Apr 17 19:15:23 UTC 2023


* Andreas Schneider:

> On Monday, 17 April 2023 13:07:59 CEST Florian Weimer via samba-technical 
> wrote:
>> * 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.
>
> I've started to look into them, thanks!
>
> The returns_nonnull did recognizable improvements to talloc pool().

The question is if it's true, it's only appropriate for xmalloc-style
interfaces.  How does talloc deal with OOM errors?

> Using alloc_size leads to a lot of reports. As soon we access the talloc 
> header it detects out of bounds access :-)

Yeah, especially with recent GCC and Clang.

> The malloc attribute can be set to a few functions, that helps. I use
> the attribute with the deallocator to avoid issue on free with
> destructors.

I *think* that should be safe, but I'm not entirely sure.  Maybe ask on
the GCC list?

> The documentation for nothrow is a bit short. What is an exception in C?

Same as in C++ on GNU/Linux, but you can't define your own exception
types.  It's used for pthread_cancel, among other things.  The advantage
is that there's no function pointer (equivalent) on the stack, unlike
with setjmp/longjmp-based pthread_cleanup_push.pthread_cleanup_pop.

Thanks,
Florian




More information about the samba-technical mailing list