I have written the module which uses < linux/hashtable.h > at the moment, it works perfectly fine, however I would like to change it from static hash table size to configurable one.
How should I change initialization from this:
DEFINE_HASHTABLE(my_hash_table, 10);
to dynamic one so I can pass the size of hash table when module is loaded as parameter
I have tried with
struct hlist_head* my_hash_table
and its corresponding kmallocs()
but with no success and give me these errors:
include/linux/bug.h:33:45: error: negative width in bit-field ‘<anonymous>’
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
^
include/linux/hashtable.h:27:35: note: in definition of macro ‘hash_min’
(sizeof(val) <= 4 ? hash_32(val, bits) : hash_long(val, bits))
^
include/linux/hashtable.h:23:25: note: in expansion of macro ‘ilog2’
#define HASH_BITS(name) ilog2(HASH_SIZE(name))
^
include/linux/compiler-gcc.h:44:28: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
^
include/linux/kernel.h:54:59: note: in expansion of macro ‘__must_be_array’
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
^
include/linux/hashtable.h:22:26: note: in expansion of macro ‘ARRAY_SIZE’
#define HASH_SIZE(name) (ARRAY_SIZE(name))
^
include/linux/hashtable.h:23:31: note: in expansion of macro ‘HASH_SIZE’
#define HASH_BITS(name) ilog2(HASH_SIZE(name))
^
include/linux/hashtable.h:56:48: note: in expansion of macro ‘HASH_BITS’
hlist_add_head(node, &hashtable[hash_min(key, HASH_BITS(hashtable))])
^
HashTable.c:103:9: note: in expansion of macro ‘hash_add’
hash_add(my_hash_table, &entry->entry, entry->hashed_key);