talloc vs malloc speed
Andreas Schneider
asn at samba.org
Mon Apr 17 10:34:47 UTC 2023
On Friday, 14 April 2023 23:02:43 CEST Florian Weimer wrote:
> * Andreas Schneider via samba-technical:
> > I wonder if it would be possible to give the optimizer more hints. Maybe
> > Florian has some ideas :-)
>
> You need to check that with optimization, the compiler does not elide
> malloc/free calls completely. That might give malloc an unfair
> advantage. GCC knows that malloc/free have no observable side effect,
> so if it can see the whole program, it sometimes can turn heap
> allocations into stack allocations. GCC also knows that memory returned
> by malloc cannot alias anything, and that writes to the object before
> free can be eliminated. The latter might be meaningful for
> microbenchmarks.
>
> Some of these behaviors can be enabled through function attributes,
> however I'm not sure how much of that would be correct for talloc. If I
> recall correctly, it has destructor callbacks, which means that
> arbitrary code can run on free, and that rules out dead store
> elimination.
Yes, we have support for destructor callbacks. Can you point me to the
attributes which might help talloc?
> 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.
Andreas
--
Andreas Schneider asn at samba.org
Samba Team www.samba.org
GPG-ID: 8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D
More information about the samba-technical
mailing list