summaryrefslogtreecommitdiff
path: root/lib/talloc/talloc.c
AgeCommit message (Collapse)AuthorFilesLines
2013-09-08talloc: Add talloc_pooled_objectVolker Lendecke1-0/+66
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2013-09-08talloc: Allow nested pools.Volker Lendecke1-22/+25
Signed-off-by: Volker Lendecke <vl@samba.org> Signed-off-by: Jeremy Allison <jra@samba.org>
2013-09-08talloc: Add a separate pool sizeVolker Lendecke1-12/+23
This is necessary to allow talloc pools to be objects on their own. It is an incompatible change in the sense that talloc_get_size(pool) now returns 0 instead of the pool size. When the talloc_pooled_object() call is added, this will start to make sense again. Maybe we should add a talloc_pool_size call? Or is that overkill? Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2013-09-08talloc: Put pool-specific data before the chunkVolker Lendecke1-79/+125
This is a preparation to make talloc pool real objects themselves. Signed-off-by: Volker Lendecke <vl@samba.org> Signed-off-by: Jeremy Allison <jra@samba.org>
2013-09-08talloc: Introduce __talloc_with_prefixVolker Lendecke1-10/+22
This will allow to exchange the extra talloc pool header with the talloc_chunk structure Signed-off-by: Volker Lendecke <vl@samba.org> Signed-off-by: Jeremy Allison <jra@samba.org>
2013-09-08talloc: Decouple the dual use of chunk->poolVolker Lendecke1-25/+23
If we want nested pools, we will have pools that are pool members. So we will have to have a separate "next object" pointer for pools. As we have struct talloc_pool_chunk now, this additional pointer does not affect normal talloc objects. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2013-08-28Fix valgrind errors with memmove and talloc pools.Jeremy Allison1-0/+21
bin/smbtorture //127.0.0.1 local.talloc now runs with no valgrind errors. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Wed Aug 28 02:44:17 CEST 2013 on sn-devel-104
2013-08-27Remove talloc_memlimit_update(). No longer used.Jeremy Allison1-24/+0
Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Inside _talloc_realloc(), keep track of size changes over malloc/realloc/free.Jeremy Allison1-4/+15
Replace the last use of talloc_memlimit_update() with talloc_memlimit_grow()/ talloc_memlimit_shrink(). Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Don't call talloc_memlimit_update() inside _talloc_realloc() when we're just ↵Jeremy Allison1-15/+0
manipulating pool members. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Fix a conditional check. (size - tc->size > 0) is always true if size and ↵Jeremy Allison1-1/+1
tc->size are unsigned. Replace with (size > tc->size). Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27In _talloc_steal_internal(), correctly decrement the memory limit in the ↵Jeremy Allison1-12/+5
source, and increment in the destination. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Inside _talloc_free_internal(), always call talloc_memlimit_update_on_free() ↵Jeremy Allison1-23/+4
before we free the real memory. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Update memory limits when we call free() on a pool.Jeremy Allison1-0/+2
Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Change __talloc() to only call ↵Jeremy Allison1-12/+9
talloc_memlimit_check()/talloc_memlimit_grow() on actual malloc allocation. Don't check the memlimit if the allocation was successful from a pool. We already checked the memory limit when we created the pool. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Change _talloc_total_mem_internal() to ignore memory allocated from a pool ↵Jeremy Allison1-1/+8
when calculating limit size. We must only count normal tallocs, or a talloc pool itself. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Remove magic TC_HDR_SIZE handling inside talloc_memlimit_check().Jeremy Allison1-1/+1
Callers already account for TC_HDR_SIZE, do not add it twice. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-08-27Start to fix talloc memlimits with talloc pools.Jeremy Allison1-0/+72
Add the functions: talloc_memlimit_grow(), talloc_memlimit_shrink(), talloc_memlimit_update_on_free(). as replacements for talloc_memlimit_update(). The interface to talloc_memlimit_update() is very hard to understand and use. The above functions are (to me) much clearer. The goal of these changes is to only update the memlimits on malloc/free/realloc, not on every pool allocation. That way we only count pool creation as allocation from any imposed limits, not allocation from an already created pool. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2013-05-20talloc: Fix a typoVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Kai Blin <kai@samba.org> Autobuild-User(master): Kai Blin <kai@samba.org> Autobuild-Date(master): Mon May 20 18:48:49 CEST 2013 on sn-devel-104
2013-04-18talloc: Simplify _talloc_free_poolmem a bitVolker Lendecke1-2/+14
Early returns are easier to understand than "else if" Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Thu Apr 18 22:50:42 CEST 2013 on sn-devel-104
2013-04-18talloc: Do an early returnVolker Lendecke1-3/+6
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2013-04-18talloc: Avoid some "else" by doing early returnsVolker Lendecke1-4/+8
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2013-04-18talloc: Fix nonblank line endingsVolker Lendecke1-34/+34
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2012-10-05talloc: Convert error cecking macros into fnsSimo Sorce1-37/+74
This will avoid 'surprise returns' and makes the code cleare to readers. These macros were complex enough to warrant a full function anyway not just for readability but also for debuggability. Thanks David for pointing out this issue. Autobuild-User(master): Simo Sorce <idra@samba.org> Autobuild-Date(master): Fri Oct 5 23:24:17 CEST 2012 on sn-devel-104
2012-10-05Add memory limiting capability to tallocSimo Sorce1-39/+238
By calling talloc_set_memlimit() we can now set a max memory limit for a whole talloc hierarchy. ANy attempt to allocate memory beyond the max allowed for the whole hierarchy wil cause an allocation failure. Stealing memory correctly accounts for used memory in the old and the new hierarchy but exceeding the memory limit in the new parent will not cause a failure.
2012-07-18talloc: don't allow a talloc_pool inside a talloc_pool.Rusty Russell1-0/+7
We explicitly call free() on a pool which falls to zero, assuming it's not inside another pool (we crash). Check on creation and explicitly document this case. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2012-07-18talloc: use a struct for pool headers.Rusty Russell1-105/+89
This neatens the code a bit (we should do a similar thing for all the TALLOC_CHUNK macros). Two subtler changes: (1) As a result of the struct, we actually pack object_count into the talloc header on 32-bit platforms (since the header is 40 bytes, but needs to be 16-byte aligned). (2) I avoid VALGRIND_MAKE_MEM_UNDEFINED on memmove when we resize the only entry in a pool; that's done later anyway. With -O2 on my 11.04 Ubuntu 32-bit x86 laptop, the talloc_pool speed as measured by testsuite.c actually increases 10%. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2012-04-24talloc: Fix copy&paste errorsVolker Lendecke1-2/+2
2012-01-02talloc: Slightly simplify talloc_unlinkVolker Lendecke1-8/+7
Nested if's are hard to understand to me. Signed-off-by: Stefan Metzmacher <metze@samba.org> Autobuild-User: Volker Lendecke <vlendec@samba.org> Autobuild-Date: Mon Jan 2 19:07:23 CET 2012 on sn-devel-104
2012-01-02talloc: Fix a typoVolker Lendecke1-3/+3
2011-10-26talloc: fix a comment typoMichael Adam1-1/+1
2011-09-07talloc: Remove an unused variableVolker Lendecke1-1/+0
Autobuild-User: Volker Lendecke <vlendec@samba.org> Autobuild-Date: Wed Sep 7 16:47:26 CEST 2011 on sn-devel-104
2011-08-09talloc: ensure the sibling linked list remains valid during a freeAndrew Tridgell1-15/+3
This ensures that the sibling list of a pointer doesn't become invalid during a free operation. It is an alternative fix to the fix in 6f51a1f45bf4de062cce7a562477e8140630a53d, and avoids the problem of trying to calculate the parent pointer early This should fix the subtle spoolss talloc bug that Simo found Autobuild-User: Andrew Tridgell <tridge@samba.org> Autobuild-Date: Tue Aug 9 01:53:17 CEST 2011 on sn-devel-104
2011-07-29talloc: preserve context name on talloc_free_children()Simo Sorce1-0/+23
Otherwise tc->name will end up pointing to garbage when it is not set to a const but rather to a string allocate as child of the context itself. Signed-off-by: Andrew Tridgell <tridge@samba.org>
2011-05-17talloc: splitout _talloc_free_children_internal()Stefan Metzmacher1-50/+27
metze Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Tue May 17 10:49:13 CEST 2011 on sn-devel-104
2011-05-17talloc: fixed a use after free error in talloc_free_children()Stefan Metzmacher1-1/+16
This is similar to commit 6f51a1f45bf4de062cce7a562477e8140630a53d. metze
2011-05-17talloc: use _talloc_free_internal() in talloc_free_children()Stefan Metzmacher1-1/+1
metze
2011-05-17talloc: setup the new 'tc' before TC_UNDEFINE_GROW_CHUNK() _talloc_realloc()Stefan Metzmacher1-0/+1
metze
2011-05-17talloc: make really sure only optimize realloc if there's only one pool chunkStefan Metzmacher1-1/+6
*talloc_pool_objectcount(pool_tc) == 2 doesn't mean the one of the objects is the pool itself! So we better check for == 1 and calculate the chunk count. metze
2011-05-17talloc: make use of _talloc_free_poolmem() in _talloc_realloc()Stefan Metzmacher1-15/+1
This should follow the same logic... metze
2011-05-17talloc: split the handling of FLAG_POOL/FLAG_POOLMEM in _talloc_free_internalStefan Metzmacher1-32/+66
The optimization of the object_count == 1 case should only happen for when we're not destroying the pool itself. And it should only happen if the pool itself is still valid. If the pool isn't valid (it has TALLOC_FLAG_FREE), object_count == 1 does not mean that the pool is the last object, which can happen if you use talloc_steal/move() on memory from the pool and then free the pool itself. Thanks to Volker for noticing this! metze
2011-05-02talloc: use TC_UNDEFINE_SHRINK_CHUNK() instead of ↵Stefan Metzmacher1-1/+36
TC_INVALIDATE_SHRINK_CHUNK() for realloc path If we optimize on top of raw realloc() we need TC_INVALIDATE_SHRINK_CHUNK together with TC_UNDEFINE_GROW_CHUNK (with was missing and caused false positive valgrind warnings). But that is really slow, as we do a lot of talloc_realloc calls in samba. That's why we only to TC_UNDEFINE_SHRINK_CHUNK() for now. metze
2011-04-13talloc: fix compiler warnings with -Wc++-compatStefan Metzmacher1-5/+5
metze Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Wed Apr 13 14:33:23 CEST 2011 on sn-devel-104
2011-04-08talloc: include valgrind headers if availableStefan Metzmacher1-0/+9
metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08talloc: add TC_INVALIDATE_POOL marcoStefan Metzmacher1-3/+38
metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08talloc: add TC_UNDEFINE_GROW_CHUNK() marcoStefan Metzmacher1-0/+21
metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08talloc: add TC_INVALIDATE_SHRINK_CHUNK() marcoStefan Metzmacher1-0/+28
This invalidates the unused bytes if we shrink memory. metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08talloc: add TC_INVALIDATE_FULL_CHUNK() macroStefan Metzmacher1-12/+36
This makes it easier to mark a talloc pointer as invalid. metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08talloc: use VALGRIND_MAKE_MEM_UNDEFINED() before memmove()Stefan Metzmacher1-0/+12
metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08talloc: optimize talloc_free() and talloc_realloc() for talloc poolsStefan Metzmacher1-22/+138
metze Signed-off-By: Andrew Tridgell <tridge@samba.org>