[RFC] Making talloc_parent faster

Andrew Bartlett abartlet at samba.org
Sat Jun 26 04:07:33 MDT 2010

On Fri, 2010-06-25 at 22:17 -0700, Kenneth Graunke wrote:
> Hello!
> I'm working on a project using talloc, and have run into a serious performance
> issue.  

> The attached patch removes such traversals, making parent lookups O(1) - which
> seems appropriate for seemingly simple lookup functions.  Each talloc chunk's 
> parent pointer is now valid (non-NULL).  The tradeoff is that talloc_realloc
> must now walk the list and update those parent pointers, so it will be slower.
> This seems reasonable, however; I already expect reallocating to be a somewhat
> expensive operation, especially if there are lots of children.

So, in short, this changes the O(n) from talloc_parent to

While I am by far no expert in talloc (and as Volker has said, Tridge is
the talloc maintainer), my understanding of the talloc_reference()
discussion was that talloc_parent() should be avoided were at all
possible, as it breaks the multi-parent abstraction (parents and
references combined into multiple parents).

In Samba, we have generally avoided using talloc_parent() except it was
impossible to rework the code to do otherwise.  Is it not possible to
pass the parent along with the context in your application?

(I would generally prefer not to slow down talloc_realloc())

Andrew Bartlett
Andrew Bartlett                                http://samba.org/~abartlet/
Authentication Developer, Samba Team           http://samba.org
Samba Developer, Cisco Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20100626/fcd320bd/attachment.pgp>

More information about the samba-technical mailing list