diff options
Diffstat (limited to 'libglusterfs')
| -rw-r--r-- | libglusterfs/src/ctx.c | 2 | ||||
| -rw-r--r-- | libglusterfs/src/glusterfs.h | 2 | ||||
| -rw-r--r-- | libglusterfs/src/mem-pool.c | 18 | ||||
| -rw-r--r-- | libglusterfs/src/mem-pool.h | 16 | ||||
| -rw-r--r-- | libglusterfs/src/rbthash.c | 5 | ||||
| -rw-r--r-- | libglusterfs/src/rbthash.h | 2 | ||||
| -rw-r--r-- | libglusterfs/src/statedump.c | 4 | 
7 files changed, 34 insertions, 15 deletions
diff --git a/libglusterfs/src/ctx.c b/libglusterfs/src/ctx.c index 94c56acdea5..90480d09774 100644 --- a/libglusterfs/src/ctx.c +++ b/libglusterfs/src/ctx.c @@ -31,9 +31,7 @@ glusterfs_ctx_new ()          ctx->mem_acct_enable = gf_global_mem_acct_enable_get();          INIT_LIST_HEAD (&ctx->graphs); -#if defined(OLD_MEM_POOLS)          INIT_LIST_HEAD (&ctx->mempool_list); -#endif          INIT_LIST_HEAD (&ctx->volfile_list);  	ctx->daemon_pipe[0] = -1; diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 8a55d724c6e..37ce5d91a1c 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -502,11 +502,9 @@ struct _glusterfs_ctx {          int                process_mode; /*mode in which process is runninng*/          struct syncenv    *env;          /* The env pointer to the synctasks */ -#if defined(OLD_MEM_POOLS)          struct list_head   mempool_list; /* used to keep a global list of                                              mempools, used to log details of                                              mempool in statedump */ -#endif          char              *statedump_path;          struct mem_pool   *dict_pool; diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 8bd9779ce81..66b45c0d669 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -663,7 +663,7 @@ void mem_pools_fini (void) {}  #endif  struct mem_pool * -mem_pool_new_fn (unsigned long sizeof_type, +mem_pool_new_fn (glusterfs_ctx_t *ctx, unsigned long sizeof_type,                   unsigned long count, char *name)  {          unsigned int            i; @@ -693,10 +693,18 @@ mem_pool_new_fn (unsigned long sizeof_type,          if (!new)                  return NULL; +        new->ctx = ctx;          new->sizeof_type = sizeof_type;          new->count = count;          new->name = name;          new->pool = pool; +        INIT_LIST_HEAD (&new->owner); + +        LOCK (&ctx->lock); +        { +                list_add (&new->owner, &ctx->mempool_list); +        } +        UNLOCK (&ctx->lock);          return new;  } @@ -867,6 +875,14 @@ mem_put (void *ptr)  void  mem_pool_destroy (struct mem_pool *pool)  { +        /* remove this pool from the owner (glusterfs_ctx_t) */ +        LOCK (&pool->ctx->lock); +        { +                list_del (&pool->owner); +        } +        UNLOCK (&pool->ctx->lock); + +        /* free this pool, but keep the mem_pool_shared */          GF_FREE (pool);          /* diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h index cc7df0b77c8..ecf2abe9245 100644 --- a/libglusterfs/src/mem-pool.h +++ b/libglusterfs/src/mem-pool.h @@ -16,6 +16,7 @@  #include "atomic.h"  #include "logging.h"  #include "mem-types.h" +#include "glusterfs.h" /* for glusterfs_ctx_t */  #include <stdlib.h>  #include <inttypes.h>  #include <string.h> @@ -206,11 +207,15 @@ out:  /* 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 { +        /* object size, without pooled_obj_hdr_t */          unsigned long           sizeof_type;          unsigned long           count;          char                    *name; -        struct mem_pool_shared  *pool; +        struct list_head        owner;  /* glusterfs_ctx_t->mempool_list */ +        glusterfs_ctx_t         *ctx;   /* take ctx->lock when updating owner */ + +        struct mem_pool_shared  *pool;  /* the initial pool that was returned */  };  typedef struct pooled_obj_hdr { @@ -275,9 +280,14 @@ void mem_pools_init_late (void);   /* start the pool_sweeper thread */  void mem_pools_fini (void);        /* cleanup memory pools */  struct mem_pool * -mem_pool_new_fn (unsigned long sizeof_type, unsigned long count, char *name); +mem_pool_new_fn (glusterfs_ctx_t *ctx, unsigned long sizeof_type, unsigned long +                 count, char *name); + +#define mem_pool_new(type,count) \ +        mem_pool_new_fn (THIS->ctx, sizeof(type), count, #type) -#define mem_pool_new(type,count) mem_pool_new_fn (sizeof(type), count, #type) +#define mem_pool_new_ctx(ctx,type,count) \ +        mem_pool_new_fn (ctx, sizeof(type), count, #type)  void mem_put (void *ptr);  void *mem_get (struct mem_pool *pool); diff --git a/libglusterfs/src/rbthash.c b/libglusterfs/src/rbthash.c index 52d8a15fd2c..06fc7ee35c8 100644 --- a/libglusterfs/src/rbthash.c +++ b/libglusterfs/src/rbthash.c @@ -83,7 +83,7 @@ err:   */  rbthash_table_t * -rbthash_table_init (int buckets, rbt_hasher_t hfunc, +rbthash_table_init (glusterfs_ctx_t *ctx, int buckets, rbt_hasher_t hfunc,                      rbt_data_destroyer_t dfunc,                      unsigned long expected_entries,                      struct mem_pool *entrypool) @@ -123,7 +123,8 @@ rbthash_table_init (int buckets, rbt_hasher_t hfunc,          if (expected_entries) {                  newtab->entrypool = -                        mem_pool_new (rbthash_entry_t, expected_entries); +                        mem_pool_new_ctx (ctx, rbthash_entry_t, +                                          expected_entries);                  if (!newtab->entrypool) {                          goto free_buckets;                  } diff --git a/libglusterfs/src/rbthash.h b/libglusterfs/src/rbthash.h index b093ce9982d..949b88a4380 100644 --- a/libglusterfs/src/rbthash.h +++ b/libglusterfs/src/rbthash.h @@ -52,7 +52,7 @@ typedef struct rbthash_table {  } rbthash_table_t;  extern rbthash_table_t * -rbthash_table_init (int buckets, rbt_hasher_t hfunc, +rbthash_table_init (glusterfs_ctx_t *ctx, int buckets, rbt_hasher_t hfunc,                      rbt_data_destroyer_t dfunc, unsigned long expected_entries,                      struct mem_pool *entrypool); diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index a2000b158e6..67c46998d63 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -399,14 +399,10 @@ 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);                  }          }  | 
