diff options
author | Raghavendra G <raghavendra@gluster.com> | 2009-10-28 18:42:35 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-10-28 23:00:39 -0700 |
commit | 53ff4f0299cf14c6c413d3e49991a6f05f9cda19 (patch) | |
tree | 62d74188e56d23d4076aa7da7df151e39067f7bd | |
parent | 07e8d8a37713d39f63713d8c05dd99a0610a3c35 (diff) |
libglusterfs/rbtree: change rbthash_init_table to take no of expected entries in the hash table as argument.
- the expected number of entries is used to create the memory pool of the hash
table. Having constant macro for this purpose is not suitable since different
users of rbtree based hash table store different number of entries in the
table.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 335 (Io-cache optimization)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=335
-rw-r--r-- | libglusterfs/src/rbthash.c | 5 | ||||
-rw-r--r-- | libglusterfs/src/rbthash.h | 4 | ||||
-rw-r--r-- | xlators/performance/io-cache/src/ioc-inode.c | 13 | ||||
-rw-r--r-- | xlators/performance/stat-prefetch/src/stat-prefetch.c | 7 |
4 files changed, 19 insertions, 10 deletions
diff --git a/libglusterfs/src/rbthash.c b/libglusterfs/src/rbthash.c index 829257448ea..c2cbf99b4a1 100644 --- a/libglusterfs/src/rbthash.c +++ b/libglusterfs/src/rbthash.c @@ -80,7 +80,8 @@ err: rbthash_table_t * -rbthash_table_init (int buckets, rbt_hasher_t hfunc, rbt_data_destroyer_t dfunc) +rbthash_table_init (int buckets, rbt_hasher_t hfunc, rbt_data_destroyer_t dfunc, + unsigned long expected_entries) { rbthash_table_t *newtab = NULL; int ret = -1; @@ -100,7 +101,7 @@ 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, GF_RBTHASH_MEMPOOL); + 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; diff --git a/libglusterfs/src/rbthash.h b/libglusterfs/src/rbthash.h index 5bfa6afd0ef..f2200f8957c 100644 --- a/libglusterfs/src/rbthash.h +++ b/libglusterfs/src/rbthash.h @@ -26,7 +26,7 @@ #include <pthread.h> -#define GF_RBTHASH_MEMPOOL 1048576 +#define GF_RBTHASH_MEMPOOL 16384 //1048576 #define GF_RBTHASH "rbthash" struct rbthash_bucket { @@ -56,7 +56,7 @@ typedef struct rbthash_table { extern rbthash_table_t * rbthash_table_init (int buckets, rbt_hasher_t hfunc, - rbt_data_destroyer_t dfunc); + rbt_data_destroyer_t dfunc, unsigned long expected_entries); extern int rbthash_insert (rbthash_table_t *tbl, void *data, void *key, int keylen); diff --git a/xlators/performance/io-cache/src/ioc-inode.c b/xlators/performance/io-cache/src/ioc-inode.c index 356afc583b9..e647b318342 100644 --- a/xlators/performance/io-cache/src/ioc-inode.c +++ b/xlators/performance/io-cache/src/ioc-inode.c @@ -166,18 +166,23 @@ ioc_inode_wakeup (call_frame_t *frame, ioc_inode_t *ioc_inode, ioc_inode_t * ioc_inode_update (ioc_table_t *table, inode_t *inode, uint32_t weight) { - ioc_inode_t *ioc_inode = NULL; - + ioc_inode_t *ioc_inode = NULL; + unsigned long no_of_pages = 0; + ioc_inode = CALLOC (1, sizeof (ioc_inode_t)); if (ioc_inode == NULL) { goto out; } ioc_inode->table = table; - + + no_of_pages = (table->cache_size / table->page_size) + + ((table->cache_size % table->page_size) ? 1 : 0); + /* initialize the list for pages */ ioc_inode->cache.page_table = rbthash_table_init (IOC_PAGE_TABLE_BUCKET_COUNT, - ioc_hashfn, NULL); + ioc_hashfn, NULL, + no_of_pages); if (ioc_inode->cache.page_table == NULL) { FREE (ioc_inode); ioc_inode = NULL; diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c index fe81b3e0848..d6e8bad1e1e 100644 --- a/xlators/performance/stat-prefetch/src/stat-prefetch.c +++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c @@ -20,6 +20,7 @@ #include "stat-prefetch.h" #define GF_SP_CACHE_BUCKETS 4096 +#define GF_SP_CACHE_ENTRIES_EXPECTED 1048576 int32_t sp_process_inode_ctx (call_frame_t *frame, xlator_t *this, loc_t *loc, @@ -129,7 +130,8 @@ sp_cache_init (void) if (cache) { cache->table = rbthash_table_init (GF_SP_CACHE_BUCKETS, sp_hashfn, - free); + free, + GF_SP_CACHE_ENTRIES_EXPECTED); if (cache->table == NULL) { FREE (cache); cache = NULL; @@ -170,7 +172,8 @@ sp_cache_remove_entry (sp_cache_t *cache, char *name, char remove_all) table = cache->table; cache->table = rbthash_table_init (GF_SP_CACHE_BUCKETS, sp_hashfn, - free); + free, + GF_SP_CACHE_ENTRIES_EXPECTED); if (cache->table == NULL) { cache->table = table; } else { |