summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2017-08-29 00:17:03 +0200
committerJeff Darcy <jeff@pl.atyp.us>2017-08-29 19:14:04 +0000
commitb3c068ccd9125ffdfb6fbb3d2728f16ff8dda2eb (patch)
tree26a8d50c4d470c9324e934c6e589d7fa2bb8c1fa /libglusterfs
parent3b5f4de6926780b34570731ad34992a4735dd410 (diff)
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 <ndevos@redhat.com> Reviewed-on: https://review.gluster.org/18074 Smoke: Gluster Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/mem-pool.c5
-rw-r--r--libglusterfs/src/mem-pool.h3
-rw-r--r--libglusterfs/src/statedump.c4
3 files changed, 11 insertions, 1 deletions
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;
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
index ecf2abe9245..ff5d183b16d 100644
--- a/libglusterfs/src/mem-pool.h
+++ b/libglusterfs/src/mem-pool.h
@@ -209,8 +209,9 @@ out:
struct mem_pool {
/* object size, without pooled_obj_hdr_t */
unsigned long sizeof_type;
- unsigned long count;
+ unsigned long count; /* requested pool size (unused) */
char *name;
+ gf_atomic_t active; /* current allocations */
struct list_head owner; /* glusterfs_ctx_t->mempool_list */
glusterfs_ctx_t *ctx; /* take ctx->lock when updating owner */
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
index 67c46998d63..a2000b158e6 100644
--- a/libglusterfs/src/statedump.c
+++ b/libglusterfs/src/statedump.c
@@ -399,10 +399,14 @@ gf_proc_dump_mempool_info (glusterfs_ctx_t *ctx)
LOCK (&ctx->lock);
{
list_for_each_entry (pool, &ctx->mempool_list, owner) {
+ int64_t active = GF_ATOMIC_GET (pool->active);
+
gf_proc_dump_write ("-----", "-----");
gf_proc_dump_write ("pool-name", "%s", pool->name);
+ gf_proc_dump_write ("active-count", "%"GF_PRI_ATOMIC, active);
gf_proc_dump_write ("sizeof-type", "%d", pool->sizeof_type);
gf_proc_dump_write ("padded-sizeof", "%lu", 1 << pool->pool->power_of_two);
+ gf_proc_dump_write ("size", "%lu", (1 << pool->pool->power_of_two) * active);
gf_proc_dump_write ("shared-pool", "%p", pool->pool);
}
}