]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Track memory usage in mempool
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 12 Dec 2019 19:50:20 +0000 (19:50 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 12 Dec 2019 19:50:20 +0000 (19:50 +0000)
src/libutil/mem_pool.c
src/libutil/mem_pool.h

index c01ce0c2cc819f03b931d4937a889be5e26c5cba..ed3a6b73d8e407fd11e1c296362a587121aa82d7 100644 (file)
@@ -393,6 +393,8 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
 
        if (pool) {
                POOL_MTX_LOCK ();
+               pool->used_memory += size;
+
                if (always_malloc && pool_type != RSPAMD_MEMPOOL_SHARED) {
                        void *ptr;
 
@@ -416,6 +418,10 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
                }
 
                if (cur == NULL || free < size) {
+                       if (free < size) {
+                               pool->wasted_memory += free;
+                       }
+
                        /* Allocate new chain element */
                        if (pool->elt_len >= size + MIN_MEM_ALIGNMENT) {
                                pool->entry->elts[pool->entry->cur_elts].fragmentation += size;
index 5a663e35fa9afc8de02169c690f3c7d1bd09e6ff..a32aa0597612ab73ff5aa7ef501489ba8f4254c0 100644 (file)
@@ -127,6 +127,8 @@ typedef struct memory_pool_s {
        GPtrArray *trash_stack;
        GHashTable *variables;                  /**< private memory pool variables                      */
        gsize elt_len;                            /**< size of an element                                               */
+       gsize used_memory;
+       gsize wasted_memory;
        struct rspamd_mempool_entry_point *entry;
        struct rspamd_mempool_tag tag;          /**< memory pool tag                                            */
 } rspamd_mempool_t;