talloc vs malloc speed

Florian Weimer fweimer at redhat.com
Fri Apr 14 21:02:43 UTC 2023


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

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.

Thanks,
Florian




More information about the samba-technical mailing list