summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2012-03-01 17:25:12 +0530
committerVijay Bellur <vijay@gluster.com>2012-03-14 22:15:25 -0700
commiteb8a9aae19755bc21afe2d8ed4893b788c4e84ff (patch)
tree4bf00b663ea400f583728e4dc9e9c64cbda4c1f8
parentd05708d7976a8340ae7647fd26f38f22f1863b6a (diff)
core: dict allocations through mem-pool
Change-Id: I7401639060957d437808779745a1e46c3f9f4585 Signed-off-by: Amar Tumballi <amarts@redhat.com> BUG: 798503 Reviewed-on: http://review.gluster.com/2851 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
-rw-r--r--cli/src/cli.c12
-rw-r--r--glusterfsd/src/glusterfsd.c12
-rw-r--r--libglusterfs/src/dict.c35
-rw-r--r--libglusterfs/src/glusterfs.h5
4 files changed, 45 insertions, 19 deletions
diff --git a/cli/src/cli.c b/cli/src/cli.c
index f20ea1f1746..c638dc82724 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -179,6 +179,18 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
if (!ctx->stub_mem_pool)
return -1;
+ ctx->dict_pool = mem_pool_new (dict_t, 32);
+ if (!ctx->dict_pool)
+ return -1;
+
+ ctx->dict_pair_pool = mem_pool_new (data_pair_t, 512);
+ if (!ctx->dict_pair_pool)
+ return -1;
+
+ ctx->dict_data_pool = mem_pool_new (data_t, 512);
+ if (!ctx->dict_data_pool)
+ return -1;
+
INIT_LIST_HEAD (&pool->all_frames);
LOCK_INIT (&pool->lock);
ctx->pool = pool;
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index 7d322b0dd71..57b3f0160bd 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -1031,6 +1031,18 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
return -1;
}
+ ctx->dict_pool = mem_pool_new (dict_t, 1024);
+ if (!ctx->dict_pool)
+ return -1;
+
+ ctx->dict_pair_pool = mem_pool_new (data_pair_t, 16 * GF_UNIT_KB);
+ if (!ctx->dict_pair_pool)
+ return -1;
+
+ ctx->dict_data_pool = mem_pool_new (data_t, 8 * GF_UNIT_KB);
+ if (!ctx->dict_data_pool)
+ return -1;
+
INIT_LIST_HEAD (&pool->all_frames);
LOCK_INIT (&pool->lock);
ctx->pool = pool;
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index fd9dd1cd7c6..a9d67ebc7ae 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -36,14 +36,15 @@
#include "logging.h"
#include "compat.h"
#include "byte-order.h"
+#include "globals.h"
data_pair_t *
get_new_data_pair ()
{
data_pair_t *data_pair_ptr = NULL;
- data_pair_ptr = (data_pair_t *) GF_CALLOC (1, sizeof (data_pair_t),
- gf_common_mt_data_pair_t);
+ data_pair_ptr = mem_get0 (THIS->ctx->dict_pair_pool);
+
return data_pair_ptr;
}
@@ -52,7 +53,7 @@ get_new_data ()
{
data_t *data = NULL;
- data = (data_t *) GF_CALLOC (1, sizeof (data_t), gf_common_mt_data_t);
+ data = mem_get0 (THIS->ctx->dict_data_pool);
if (!data) {
return NULL;
}
@@ -64,18 +65,17 @@ get_new_data ()
dict_t *
get_new_dict_full (int size_hint)
{
- dict_t *dict = GF_CALLOC (1, sizeof (dict_t), gf_common_mt_dict_t);
+ dict_t *dict = mem_get0 (THIS->ctx->dict_pool);
if (!dict) {
return NULL;
}
dict->hash_size = size_hint;
- dict->members = GF_CALLOC (size_hint, sizeof (data_pair_t *),
- gf_common_mt_data_pair_t);
+ dict->members = mem_get0 (THIS->ctx->dict_pair_pool);
if (!dict->members) {
- GF_FREE (dict);
+ mem_put (dict);
return NULL;
}
@@ -149,7 +149,7 @@ data_destroy (data_t *data)
data->len = 0xbabababa;
if (!data->is_const)
- GF_FREE (data);
+ mem_put (data);
}
}
@@ -162,9 +162,7 @@ data_copy (data_t *old)
return NULL;
}
- data_t *newdata = (data_t *) GF_CALLOC (1, sizeof (*newdata),
- gf_common_mt_data_t);
-
+ data_t *newdata = mem_get0 (THIS->ctx->dict_data_pool);
if (!newdata) {
return NULL;
}
@@ -193,7 +191,7 @@ err_out:
FREE (newdata->data);
if (newdata->vec)
FREE (newdata->vec);
- GF_FREE (newdata);
+ mem_put (newdata);
return NULL;
}
@@ -272,8 +270,7 @@ _dict_set (dict_t *this,
/* Indicates duplicate key */
return 0;
}
- pair = (data_pair_t *) GF_CALLOC (1, sizeof (*pair),
- gf_common_mt_data_pair_t);
+ pair = mem_get0 (THIS->ctx->dict_pair_pool);
if (!pair) {
return -1;
}
@@ -281,7 +278,7 @@ _dict_set (dict_t *this,
pair->key = (char *) GF_CALLOC (1, strlen (key) + 1,
gf_common_mt_char);
if (!pair->key) {
- GF_FREE (pair);
+ mem_put (pair);
if (key_free)
GF_FREE (key);
@@ -385,7 +382,7 @@ dict_del (dict_t *this, char *key)
pair->next->prev = pair->prev;
GF_FREE (pair->key);
- GF_FREE (pair);
+ mem_put (pair);
this->count--;
break;
}
@@ -416,11 +413,11 @@ dict_destroy (dict_t *this)
pair = pair->next;
data_unref (prev->value);
GF_FREE (prev->key);
- GF_FREE (prev);
+ mem_put (prev);
prev = pair;
}
- GF_FREE (this->members);
+ mem_put (this->members);
if (this->extra_free)
GF_FREE (this->extra_free);
@@ -428,7 +425,7 @@ dict_destroy (dict_t *this)
free (this->extra_stdfree);
if (!this->is_static)
- GF_FREE (this);
+ mem_put (this);
return;
}
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index 0ab5767980f..0d4240a2a6e 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -371,6 +371,11 @@ struct _glusterfs_ctx {
mempools, used to log details of
mempool in statedump */
char *statedump_path;
+
+ struct mem_pool *dict_pool;
+ struct mem_pool *dict_pair_pool;
+ struct mem_pool *dict_data_pool;
+
};
typedef struct _glusterfs_ctx glusterfs_ctx_t;