talloc vs malloc speed

Andreas Schneider asn at samba.org
Tue Apr 18 05:52:30 UTC 2023


On Monday, 17 April 2023 21:15:23 CEST Florian Weimer wrote:
> * 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?

Oh, then it might be some other side effect.

> > 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.

I think I should just define them for public interfaces so users of talloc 
will get better diagnostics.

> > 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.

pthread isn't involved here, so we are fine. Thanks for the explanation.


	Andreas

-- 
Andreas Schneider                      asn at samba.org
Samba Team                             www.samba.org
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D





More information about the samba-technical mailing list