glusterfs/0493-mem-pool-count-allocations-done-per-user-pool.patch
Milind Changire 1f2f23ddef autobuild v3.12.2-33
Resolves: bz#1350745 bz#1362129 bz#1541568 bz#1597252 bz#1599220
Resolves: bz#1633177 bz#1637564 bz#1639476 bz#1639568 bz#1643370
Resolves: bz#1645480 bz#1648296 bz#1648893 bz#1651040 bz#1651460
Resolves: bz#1652466 bz#1652537 bz#1653224 bz#1653613 bz#1654103
Resolves: bz#1654161 bz#1655385 bz#1655578 bz#1656357 bz#1659439
Signed-off-by: Milind Changire <mchangir@redhat.com>
2018-12-18 11:23:13 -05:00

97 lines
4.0 KiB
Diff

From bb668d69815209bd7f7f4669142191d4b48bcde8 Mon Sep 17 00:00:00 2001
From: Mohit Agrawal <moagrawa@redhat.com>
Date: Tue, 18 Dec 2018 19:41:42 +0530
Subject: [PATCH 493/493] 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>
Change-Id: I2e4375fd59f11288f41a36cad131d794bff19fbb
BUG: 1648893
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/158961
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
libglusterfs/src/mem-pool.c | 4 ++++
libglusterfs/src/mem-pool.h | 3 ++-
libglusterfs/src/statedump.c | 4 ++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 999a83f..d82a371 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -711,6 +711,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);
@@ -864,6 +865,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 */
}
@@ -894,6 +897,7 @@ mem_put (void *ptr)
pt_pool = &pool_list->pools[hdr->power_of_two-POOL_SMALLEST];
hdr->magic = GF_MEM_INVALID_MAGIC;
+ GF_ATOMIC_DEC (hdr->pool->active);
(void) pthread_spin_lock (&pool_list->lock);
if (!pool_list->poison) {
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
index 0ebb63b..aa1d045 100644
--- a/libglusterfs/src/mem-pool.h
+++ b/libglusterfs/src/mem-pool.h
@@ -210,8 +210,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 4aad014..a04c535 100644
--- a/libglusterfs/src/statedump.c
+++ b/libglusterfs/src/statedump.c
@@ -400,10 +400,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", "%lu", pool->sizeof_type);
gf_proc_dump_write ("padded-sizeof", "%d", 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);
}
}
--
1.8.3.1