diff options
Diffstat (limited to 'libglusterfs/src/mem-pool.c')
| -rw-r--r-- | libglusterfs/src/mem-pool.c | 77 |
1 files changed, 20 insertions, 57 deletions
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 3e8100c64..b901dd7a8 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -30,40 +30,16 @@ #define GLUSTERFS_ENV_MEM_ACCT_STR "GLUSTERFS_DISABLE_MEM_ACCT" -static int gf_mem_acct_enable = 0; - -int -gf_mem_acct_is_enabled () -{ - return gf_mem_acct_enable; -} - void -gf_mem_acct_enable_set () +gf_mem_acct_enable_set (void *data) { -#ifdef DEBUG - gf_mem_acct_enable = 1; - return; -#endif glusterfs_ctx_t *ctx = NULL; - char *opt = NULL; - long val = -1; - gf_mem_acct_enable = 0; + ctx = data; - ctx = glusterfs_ctx_get (); + GF_ASSERT (ctx); - if (ctx->mem_accounting) { - gf_mem_acct_enable = 1; - return; - } - - opt = getenv (GLUSTERFS_ENV_MEM_ACCT_STR); - if (opt) { - val = strtol (opt, NULL, 0); - if (val) - gf_mem_acct_enable = 1; - } + ctx->mem_acct_enable = 1; return; } @@ -80,17 +56,11 @@ gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr, ptr = (char *) (*alloc_ptr); - if (!xl) { - GF_ASSERT (0); - } + GF_ASSERT (xl != NULL); - if (!(xl->mem_acct.rec)) { - GF_ASSERT (0); - } + GF_ASSERT (xl->mem_acct.rec != NULL); - if (type > xl->mem_acct.num_types) { - GF_ASSERT (0); - } + GF_ASSERT (type <= xl->mem_acct.num_types); LOCK(&xl->mem_acct.rec[type].lock); { @@ -130,7 +100,7 @@ __gf_calloc (size_t nmemb, size_t size, uint32_t type) char *ptr = NULL; xlator_t *xl = NULL; - if (!gf_mem_acct_enable) + if (!THIS->ctx->mem_acct_enable) return CALLOC (nmemb, size); xl = THIS; @@ -156,7 +126,7 @@ __gf_malloc (size_t size, uint32_t type) char *ptr = NULL; xlator_t *xl = NULL; - if (!gf_mem_acct_enable) + if (!THIS->ctx->mem_acct_enable) return MALLOC (size); xl = THIS; @@ -181,7 +151,7 @@ __gf_realloc (void *ptr, size_t size) xlator_t *xl = NULL; uint32_t type = 0; - if (!gf_mem_acct_enable) + if (!THIS->ctx->mem_acct_enable) return REALLOC (ptr, size); tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; @@ -254,7 +224,7 @@ __gf_free (void *free_ptr) uint32_t type = 0; xlator_t *xl = NULL; - if (!gf_mem_acct_enable) { + if (!THIS->ctx->mem_acct_enable) { FREE (free_ptr); return; } @@ -264,20 +234,16 @@ __gf_free (void *free_ptr) ptr = (char *)free_ptr - 8 - 4; - if (GF_MEM_HEADER_MAGIC != *(uint32_t *)ptr) { - //Possible corruption, assert here - GF_ASSERT (0); - } + //Possible corruption, assert here + GF_ASSERT (GF_MEM_HEADER_MAGIC == *(uint32_t *)ptr); *(uint32_t *)ptr = 0; ptr = ptr - sizeof(xlator_t *); memcpy (&xl, ptr, sizeof(xlator_t *)); - if (!xl) { - //gf_free expects xl to be available - GF_ASSERT (0); - } + //gf_free expects xl to be available + GF_ASSERT (xl != NULL); if (!xl->mem_acct.rec) { ptr = (char *)free_ptr - GF_MEM_HEADER_SIZE; @@ -290,11 +256,10 @@ __gf_free (void *free_ptr) ptr = ptr - 4; type = *(uint32_t *)ptr; - if (GF_MEM_TRAILER_MAGIC != *(uint32_t *) - ((char *)free_ptr + req_size)) { - // This points to a memory overrun - GF_ASSERT (0); - } + // This points to a memory overrun + GF_ASSERT (GF_MEM_TRAILER_MAGIC == + *(uint32_t *)((char *)free_ptr + req_size)); + *(uint32_t *) ((char *)free_ptr + req_size) = 0; LOCK (&xl->mem_acct.rec[type].lock); @@ -365,7 +330,7 @@ mem_pool_new_fn (unsigned long sizeof_type, mem_pool->pool_end = pool + (count * (padded_sizeof_type)); /* add this pool to the global list */ - ctx = glusterfs_ctx_get (); + ctx = THIS->ctx; if (!ctx) goto out; @@ -453,8 +418,6 @@ mem_get (struct mem_pool *mem_pool) mem_pool->max_stdalloc = mem_pool->curr_stdalloc; ptr = GF_CALLOC (1, mem_pool->padded_sizeof_type, gf_common_mt_mem_pool); - gf_log_callingfn ("mem-pool", GF_LOG_DEBUG, "Mem pool is full. " - "Callocing mem"); /* Memory coming from the heap need not be transformed from a * chunkhead to a usable pointer since it is not coming from |
