|
|
887953 |
From bb668d69815209bd7f7f4669142191d4b48bcde8 Mon Sep 17 00:00:00 2001
|
|
|
887953 |
From: Mohit Agrawal <moagrawa@redhat.com>
|
|
|
887953 |
Date: Tue, 18 Dec 2018 19:41:42 +0530
|
|
|
887953 |
Subject: [PATCH 493/493] mem-pool: count allocations done per user-pool
|
|
|
887953 |
|
|
|
887953 |
Count the active allocations per 'struct mem_pool'. These are the
|
|
|
887953 |
objects that the calling component allocated and free'd in the memory
|
|
|
887953 |
pool for this specific type. Having this count in the statedump will
|
|
|
887953 |
make it easy to find memory leaks.
|
|
|
887953 |
|
|
|
887953 |
> Updates: #307
|
|
|
887953 |
> Change-Id: I797fabab86f104e49338c00e449a7d0b0d270004
|
|
|
887953 |
> Signed-off-by: Niels de Vos <ndevos@redhat.com>
|
|
|
887953 |
> Reviewed-on: https://review.gluster.org/18074
|
|
|
887953 |
> Smoke: Gluster Build System <jenkins@build.gluster.org>
|
|
|
887953 |
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
|
|
|
887953 |
> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
|
|
|
887953 |
|
|
|
887953 |
Change-Id: I2e4375fd59f11288f41a36cad131d794bff19fbb
|
|
|
887953 |
BUG: 1648893
|
|
|
887953 |
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
|
|
|
887953 |
Reviewed-on: https://code.engineering.redhat.com/gerrit/158961
|
|
|
887953 |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
887953 |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
887953 |
---
|
|
|
887953 |
libglusterfs/src/mem-pool.c | 4 ++++
|
|
|
887953 |
libglusterfs/src/mem-pool.h | 3 ++-
|
|
|
887953 |
libglusterfs/src/statedump.c | 4 ++++
|
|
|
887953 |
3 files changed, 10 insertions(+), 1 deletion(-)
|
|
|
887953 |
|
|
|
887953 |
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
|
|
|
887953 |
index 999a83f..d82a371 100644
|
|
|
887953 |
--- a/libglusterfs/src/mem-pool.c
|
|
|
887953 |
+++ b/libglusterfs/src/mem-pool.c
|
|
|
887953 |
@@ -711,6 +711,7 @@ mem_pool_new_fn (glusterfs_ctx_t *ctx, unsigned long sizeof_type,
|
|
|
887953 |
new->count = count;
|
|
|
887953 |
new->name = name;
|
|
|
887953 |
new->pool = pool;
|
|
|
887953 |
+ GF_ATOMIC_INIT (new->active, 0);
|
|
|
887953 |
INIT_LIST_HEAD (&new->owner);
|
|
|
887953 |
|
|
|
887953 |
LOCK (&ctx->lock);
|
|
|
887953 |
@@ -864,6 +865,8 @@ mem_get (struct mem_pool *mem_pool)
|
|
|
887953 |
retval->pool_list = pool_list;
|
|
|
887953 |
retval->power_of_two = mem_pool->pool->power_of_two;
|
|
|
887953 |
|
|
|
887953 |
+ GF_ATOMIC_INC (mem_pool->active);
|
|
|
887953 |
+
|
|
|
887953 |
return retval + 1;
|
|
|
887953 |
#endif /* GF_DISABLE_MEMPOOL */
|
|
|
887953 |
}
|
|
|
887953 |
@@ -894,6 +897,7 @@ mem_put (void *ptr)
|
|
|
887953 |
pt_pool = &pool_list->pools[hdr->power_of_two-POOL_SMALLEST];
|
|
|
887953 |
|
|
|
887953 |
hdr->magic = GF_MEM_INVALID_MAGIC;
|
|
|
887953 |
+ GF_ATOMIC_DEC (hdr->pool->active);
|
|
|
887953 |
|
|
|
887953 |
(void) pthread_spin_lock (&pool_list->lock);
|
|
|
887953 |
if (!pool_list->poison) {
|
|
|
887953 |
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
|
|
|
887953 |
index 0ebb63b..aa1d045 100644
|
|
|
887953 |
--- a/libglusterfs/src/mem-pool.h
|
|
|
887953 |
+++ b/libglusterfs/src/mem-pool.h
|
|
|
887953 |
@@ -210,8 +210,9 @@ out:
|
|
|
887953 |
struct mem_pool {
|
|
|
887953 |
/* object size, without pooled_obj_hdr_t */
|
|
|
887953 |
unsigned long sizeof_type;
|
|
|
887953 |
- unsigned long count;
|
|
|
887953 |
+ unsigned long count; /* requested pool size (unused) */
|
|
|
887953 |
char *name;
|
|
|
887953 |
+ gf_atomic_t active; /* current allocations */
|
|
|
887953 |
|
|
|
887953 |
struct list_head owner; /* glusterfs_ctx_t->mempool_list */
|
|
|
887953 |
glusterfs_ctx_t *ctx; /* take ctx->lock when updating owner */
|
|
|
887953 |
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
|
|
|
887953 |
index 4aad014..a04c535 100644
|
|
|
887953 |
--- a/libglusterfs/src/statedump.c
|
|
|
887953 |
+++ b/libglusterfs/src/statedump.c
|
|
|
887953 |
@@ -400,10 +400,14 @@ gf_proc_dump_mempool_info (glusterfs_ctx_t *ctx)
|
|
|
887953 |
LOCK (&ctx->lock);
|
|
|
887953 |
{
|
|
|
887953 |
list_for_each_entry (pool, &ctx->mempool_list, owner) {
|
|
|
887953 |
+ int64_t active = GF_ATOMIC_GET (pool->active);
|
|
|
887953 |
+
|
|
|
887953 |
gf_proc_dump_write ("-----", "-----");
|
|
|
887953 |
gf_proc_dump_write ("pool-name", "%s", pool->name);
|
|
|
887953 |
+ gf_proc_dump_write ("active-count", "%"GF_PRI_ATOMIC, active);
|
|
|
887953 |
gf_proc_dump_write ("sizeof-type", "%lu", pool->sizeof_type);
|
|
|
887953 |
gf_proc_dump_write ("padded-sizeof", "%d", 1 << pool->pool->power_of_two);
|
|
|
887953 |
+ gf_proc_dump_write ("size", "%lu", (1 << pool->pool->power_of_two) * active);
|
|
|
887953 |
gf_proc_dump_write ("shared-pool", "%p", pool->pool);
|
|
|
887953 |
}
|
|
|
887953 |
}
|
|
|
887953 |
--
|
|
|
887953 |
1.8.3.1
|
|
|
887953 |
|