summaryrefslogtreecommitdiff
path: root/lib/talloc/talloc.h
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2012-09-22 16:15:47 -0400
committerSimo Sorce <idra@samba.org>2012-10-05 05:57:17 +0200
commita33a78c302fde61fdb7a6e71669f19be2cf5c836 (patch)
treec6b06de88fe07acf5999be3f1d24884827a44fb1 /lib/talloc/talloc.h
parent78594909b8b22bd07978922b1c85dfd6f6456963 (diff)
downloadsamba-a33a78c302fde61fdb7a6e71669f19be2cf5c836.tar.gz
samba-a33a78c302fde61fdb7a6e71669f19be2cf5c836.tar.bz2
samba-a33a78c302fde61fdb7a6e71669f19be2cf5c836.zip
Add memory limiting capability to talloc
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.
Diffstat (limited to 'lib/talloc/talloc.h')
-rw-r--r--lib/talloc/talloc.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/talloc/talloc.h b/lib/talloc/talloc.h
index e48dc09a40..f3cbcd0e7c 100644
--- a/lib/talloc/talloc.h
+++ b/lib/talloc/talloc.h
@@ -1842,6 +1842,25 @@ void talloc_set_log_fn(void (*log_fn)(const char *message));
*/
void talloc_set_log_stderr(void);
+/**
+ * @brief Set a max memory limit for the current context hierarchy
+ * This affects all children of this context and constrain any
+ * allocation in the hierarchy to never exceed the limit set.
+ * The limit can be removed by setting 0 (unlimited) as the
+ * max_size by calling the funciton again on the sam context.
+ * Memory limits can also be nested, meaning a hild can have
+ * a stricter memory limit than a parent.
+ * Memory limits are enforced only at memory allocation time.
+ * Stealing a context into a 'limited' hierarchy properly
+ * updates memory usage but does *not* cause failure if the
+ * move causes the new parent to exceed its limits. However
+ * any further allocation on that hierarchy will then fail.
+ *
+ * @param[in] ctx The talloc context to set the limit on
+ * @param[in] max_size The (new) max_size
+ */
+int talloc_set_memlimit(const void *ctx, size_t max_size);
+
/* @} ******************************************************************/
#if TALLOC_DEPRECATED