From b3c068ccd9125ffdfb6fbb3d2728f16ff8dda2eb Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 29 Aug 2017 00:17:03 +0200 Subject: mem-pool: count allocations done per user-pool Count the active allocations per 'struct mem_pool'. These are the objects that the calling component allocated and free'd in the memory pool for this specific type. Having this count in the statedump will make it easy to find memory leaks. Updates: #307 Change-Id: I797fabab86f104e49338c00e449a7d0b0d270004 Signed-off-by: Niels de Vos Reviewed-on: https://review.gluster.org/18074 Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Jeff Darcy --- libglusterfs/src/mem-pool.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libglusterfs/src/mem-pool.c') diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 66b45c0d669..328c8071e29 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -698,6 +698,7 @@ mem_pool_new_fn (glusterfs_ctx_t *ctx, unsigned long sizeof_type, new->count = count; new->name = name; new->pool = pool; + GF_ATOMIC_INIT (new->active, 0); INIT_LIST_HEAD (&new->owner); LOCK (&ctx->lock); @@ -834,6 +835,8 @@ mem_get (struct mem_pool *mem_pool) retval->pool_list = pool_list; retval->power_of_two = mem_pool->pool->power_of_two; + GF_ATOMIC_INC (mem_pool->active); + return retval + 1; #endif /* GF_DISABLE_MEMPOOL */ } @@ -863,6 +866,8 @@ mem_put (void *ptr) pool_list = hdr->pool_list; pt_pool = &pool_list->pools[hdr->power_of_two-POOL_SMALLEST]; + GF_ATOMIC_DEC (hdr->pool->active); + (void) pthread_spin_lock (&pool_list->lock); hdr->magic = GF_MEM_INVALID_MAGIC; hdr->next = pt_pool->hot_list; -- cgit