From 63f963700f0c89292092047ec2423e8d8ab1f955 Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Thu, 26 Nov 2009 06:37:30 +0000 Subject: Changed rbthash_table_init() to take a mem-pool argument. Changes in libglusterfs/rbthash: rbthash_table_init() now takes a mem-pool argument. The mem-pool argument would be mutually exclusive to expected_entries. If expected_entries is provided, mem-pool would be ignored and vice-versa. Changes in io-cache: 1) Moved rbthash creation to readv. 2) rbthash makes use of 1 rbt instead of 4096 3) A global mem-pool is being used in place of a mem-pool per rbt. Signed-off-by: Vijay Bellur Signed-off-by: Anand V. Avati BUG: 335 (Io-cache optimization) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=335 --- libglusterfs/src/rbthash.c | 55 +++++++++++++++++++++++++++++++++++++--------- libglusterfs/src/rbthash.h | 5 ++++- 2 files changed, 49 insertions(+), 11 deletions(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/rbthash.c b/libglusterfs/src/rbthash.c index c2cbf99b4a1..63d08385883 100644 --- a/libglusterfs/src/rbthash.c +++ b/libglusterfs/src/rbthash.c @@ -79,9 +79,21 @@ err: } +/* + * rbthash_table_init - Initialize a RBT based hash table + * @buckets - Number of buckets in the hash table + * @hfunc - hashing function + * @dfunc - destroyer for data in the RBT + * @expected_entries - Number of entries expected in RBT. Mutually exclusive + * with entrypool. + * @entrypool - Memory pool in lieu of expected_entries. + */ + rbthash_table_t * -rbthash_table_init (int buckets, rbt_hasher_t hfunc, rbt_data_destroyer_t dfunc, - unsigned long expected_entries) +rbthash_table_init (int buckets, rbt_hasher_t hfunc, + rbt_data_destroyer_t dfunc, + unsigned long expected_entries, + struct mem_pool *entrypool) { rbthash_table_t *newtab = NULL; int ret = -1; @@ -91,6 +103,19 @@ rbthash_table_init (int buckets, rbt_hasher_t hfunc, rbt_data_destroyer_t dfunc, return NULL; } + if (!entrypool && !expected_entries) { + gf_log (GF_RBTHASH, GF_LOG_ERROR, + "Both mem-pool and expected entries not provided"); + return NULL; + } + + if (entrypool && expected_entries) { + gf_log (GF_RBTHASH, GF_LOG_ERROR, + "Both mem-pool and expected entries are provided"); + return NULL; + } + + newtab = CALLOC (1, sizeof (*newtab)); if (!newtab) return NULL; @@ -101,10 +126,17 @@ rbthash_table_init (int buckets, rbt_hasher_t hfunc, rbt_data_destroyer_t dfunc, goto free_newtab; } - newtab->entrypool = mem_pool_new (rbthash_entry_t, expected_entries); - if (!newtab->entrypool) { - gf_log (GF_RBTHASH, GF_LOG_ERROR,"Failed to allocate mem-pool"); - goto free_buckets; + if (expected_entries) { + newtab->entrypool = + mem_pool_new (rbthash_entry_t, expected_entries); + if (!newtab->entrypool) { + gf_log (GF_RBTHASH, GF_LOG_ERROR, + "Failed to allocate mem-pool"); + goto free_buckets; + } + newtab->pool_alloced = _gf_true; + } else { + newtab->entrypool = entrypool; } LOCK_INIT (&newtab->tablelock); @@ -113,13 +145,16 @@ rbthash_table_init (int buckets, rbt_hasher_t hfunc, rbt_data_destroyer_t dfunc, if (ret == -1) { gf_log (GF_RBTHASH, GF_LOG_ERROR, "Failed to init buckets"); - mem_pool_destroy (newtab->entrypool); - } else + if (newtab->pool_alloced) + mem_pool_destroy (newtab->entrypool); + } else { gf_log (GF_RBTHASH, GF_LOG_TRACE, "Inited hash table: buckets:" " %d", buckets); + } newtab->hashfunc = hfunc; newtab->dfunc = dfunc; + free_buckets: if (ret == -1) FREE (newtab->buckets); @@ -133,7 +168,6 @@ free_newtab: return newtab; } - rbthash_entry_t * rbthash_init_entry (rbthash_table_t *tbl, void *data, void *key, int keylen) { @@ -381,7 +415,8 @@ rbthash_table_destroy (rbthash_table_t *tbl) return; rbthash_table_destroy_buckets (tbl); - mem_pool_destroy (tbl->entrypool); + if (tbl->pool_alloced) + mem_pool_destroy (tbl->entrypool); FREE (tbl->buckets); FREE (tbl); diff --git a/libglusterfs/src/rbthash.h b/libglusterfs/src/rbthash.h index f2200f8957c..535dccad926 100644 --- a/libglusterfs/src/rbthash.h +++ b/libglusterfs/src/rbthash.h @@ -23,6 +23,7 @@ #include "locking.h" #include "mem-pool.h" #include "logging.h" +#include "common-utils.h" #include @@ -52,11 +53,13 @@ typedef struct rbthash_table { struct rbthash_bucket *buckets; rbt_hasher_t hashfunc; rbt_data_destroyer_t dfunc; + gf_boolean_t pool_alloced; } rbthash_table_t; extern rbthash_table_t * rbthash_table_init (int buckets, rbt_hasher_t hfunc, - rbt_data_destroyer_t dfunc, unsigned long expected_entries); + rbt_data_destroyer_t dfunc, unsigned long expected_entries, + struct mem_pool *entrypool); extern int rbthash_insert (rbthash_table_t *tbl, void *data, void *key, int keylen); -- cgit