From 2645e730b79b44fc035170657e43bb52f3e855c5 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 4 Aug 2017 16:29:51 +0200 Subject: mem-pool: add tracking of mem_pool that requested the allocation This renames the current 'struct mem_pool' to 'struct mem_pool_shared'. The mem_pool_shared is globally allocated and not specific for particular objects. A new 'struct mem_pool' gets allocated when mem_pool_new() is called. It points to the mem_pool_shared that handles the actual allocation requests. The 'struct mem_pool' is only used for accounting of the objects that the caller requested and free'd. All of these changes will be used to collect all the memory pools a glusterfs_ctx_t is consuming, so that statedumps can be collected per context. Updates: #307 Change-Id: I6355d3f0251c928e0bbfc71be3431307c6f3a3da Signed-off-by: Niels de Vos Reviewed-on: https://review.gluster.org/18073 Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Amar Tumballi Reviewed-by: Jeff Darcy --- libglusterfs/src/mem-pool.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'libglusterfs/src/mem-pool.h') diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h index 1272ad4d5fc..cc7df0b77c8 100644 --- a/libglusterfs/src/mem-pool.h +++ b/libglusterfs/src/mem-pool.h @@ -203,18 +203,31 @@ out: return dup_mem; } +/* kind of 'header' for the actual mem_pool_shared structure, this might make + * it possible to dump some more details in a statedump */ +struct mem_pool { + unsigned long sizeof_type; + unsigned long count; + char *name; + + struct mem_pool_shared *pool; +}; + typedef struct pooled_obj_hdr { unsigned long magic; struct pooled_obj_hdr *next; struct per_thread_pool_list *pool_list; unsigned int power_of_two; + + /* track the pool that was used to request this object */ + struct mem_pool *pool; } pooled_obj_hdr_t; #define AVAILABLE_SIZE(p2) ((1 << (p2)) - sizeof(pooled_obj_hdr_t)) typedef struct per_thread_pool { - /* This never changes, so doesn't need a lock. */ - struct mem_pool *parent; + /* the pool that was used to request this allocation */ + struct mem_pool_shared *parent; /* Everything else is protected by our own lock. */ pooled_obj_hdr_t *hot_list; pooled_obj_hdr_t *cold_list; @@ -242,7 +255,8 @@ typedef struct per_thread_pool_list { per_thread_pool_t pools[1]; } per_thread_pool_list_t; -struct mem_pool { +/* actual pool structure, shared between different mem_pools */ +struct mem_pool_shared { unsigned int power_of_two; /* * Updates to these are *not* protected by a global lock, so races -- cgit