diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-12-23 19:08:05 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-12-23 19:08:05 +0000 |
commit | af417271a47e88d47cc3dc25f93f56d74864c3dd (patch) | |
tree | 49ce8f5dcb846a11434f0c773eae2844359b10e1 /src/libutil | |
parent | 580873ff0beb7222ae015da5060cfa8b1c8884c0 (diff) | |
download | rspamd-af417271a47e88d47cc3dc25f93f56d74864c3dd.tar.gz rspamd-af417271a47e88d47cc3dc25f93f56d74864c3dd.zip |
[Project] Add rspamd_mempool_notify_alloc function
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/mem_pool.c | 35 | ||||
-rw-r--r-- | src/libutil/mem_pool.h | 10 |
2 files changed, 32 insertions, 13 deletions
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 5e4d1fe1a..f2272fa7c 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -441,6 +441,27 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size, const gchar *loc) RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; + +void +rspamd_mempool_notify_alloc_ (rspamd_mempool_t *pool, gsize size, const gchar *loc) +{ + GHashTable *debug_tbl = *(GHashTable **)(((guchar *)pool + sizeof (*pool))); + gpointer ptr; + + if (G_UNLIKELY (pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) { + ptr = g_hash_table_lookup (debug_tbl, loc); + + if (ptr) { + ptr = GSIZE_TO_POINTER (GPOINTER_TO_SIZE (ptr) + size); + } + else { + ptr = GSIZE_TO_POINTER (size); + } + + g_hash_table_insert (debug_tbl, (gpointer) loc, ptr); + } +} + static void * memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size, enum rspamd_mempool_chain_type pool_type, const gchar *loc) @@ -454,19 +475,7 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size, pool->priv->used_memory += size; if (G_UNLIKELY (pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) { - GHashTable *debug_tbl = *(GHashTable **)(((guchar *)pool + sizeof (*pool))); - gpointer ptr; - - ptr = g_hash_table_lookup (debug_tbl, loc); - - if (ptr) { - ptr = GSIZE_TO_POINTER (GPOINTER_TO_SIZE (ptr) + size); - } - else { - ptr = GSIZE_TO_POINTER (size); - } - - g_hash_table_insert (debug_tbl, (gpointer)loc, ptr); + rspamd_mempool_notify_alloc_ (pool, size, loc); } if (always_malloc && pool_type != RSPAMD_MEMPOOL_SHARED) { diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 773be33d3..1554edbd2 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -155,6 +155,16 @@ RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR rspamd_mempool_alloc_((pool), (size), G_STRLOC) /** + * Notify external memory usage for memory pool + * @param pool + * @param size + * @param loc + */ +void rspamd_mempool_notify_alloc_ (rspamd_mempool_t *pool, gsize size, const gchar *loc); +#define rspamd_mempool_notify_alloc(pool, size) \ + rspamd_mempool_notify_alloc_((pool), (size), G_STRLOC) + +/** * Get memory and set it to zero * @param pool memory pool object * @param size bytes to allocate |