[PATCH 3/6] Add hash support in cache mngr

Roopa Prabhu roopa at cumulusnetworks.com
Mon Nov 5 19:43:44 EST 2012


On 11/5/12 4:17 AM, Thomas Graf wrote:
> On 11/04/12 at 09:13pm, roopa at cumulusnetworks.com wrote:
>> @@ -190,6 +191,22 @@ struct nl_cache *nl_cache_alloc(struct nl_cache_ops *ops)
>>   	nl_init_list_head(&cache->c_items);
>>   	cache->c_ops = ops;
>>
>> +	/*
>> +	 * If object type provides a hash keygen
>> +	 * functions, allocate a hash table for the
>> +	 * cache objects for faster lookups
>> +	 */
>> +	if (ops->co_obj_ops->oo_keygen) {
>> +		int hashtable_size;
>> +
>> +		if (ops->co_hash_size)
>> +			hashtable_size = ops->co_hash_size;
>> +		else
>> +			hashtable_size = NL_MAX_HASH_ENTRIES;
>
> NL_MAX_HASH_ENTRIES is 16K which is _huge_. Is this intentional?
> It doesn't make sense to default to such a giant hash table size.

We think route and neigh caches in some cases might grow to that size.
The patch sets a smaller value to something like a link cache.
It can be flipped too. Smaller common default size and something like 
route cache gets a larger default value.

But agreed, I would rather make this user configurable. Which i did try 
to do first time around. But this value should
be specified at cache allocation time since hash table is allocated 
then. I did not find a clean way to do that. Its possible if we add a 
new cache alloc api or add a new api to add hashtable to an existing 
cache immediately after cache alloc.

Let me know if you have any preferences.

Any suggestions on the default hash size ?.

I will submit a patch.

thanks.



More information about the libnl mailing list