Merge pull request #9 from robertbaldyga/better-hash-function
Introduce more uniform hash function
This commit is contained in:
commit
8be3b88360
@ -81,7 +81,8 @@ static ocf_cache_line_t ocf_metadata_hash_get_entires(
|
||||
return cache_lines;
|
||||
|
||||
case metadata_segment_hash:
|
||||
return cache_lines / 4;
|
||||
return DIV_ROUND_UP(cache_lines / 4, OCF_HASH_PRIME) *
|
||||
OCF_HASH_PRIME - 1;
|
||||
|
||||
case metadata_segment_sb_config:
|
||||
return DIV_ROUND_UP(sizeof(struct ocf_superblock_config),
|
||||
|
@ -6,10 +6,20 @@
|
||||
#ifndef __METADATA_MISC_H__
|
||||
#define __METADATA_MISC_H__
|
||||
|
||||
/*
|
||||
* Hash function needs number that has no common factors with both number
|
||||
* of cores and number of entries in metadata hash container (hash lists).
|
||||
* This can be easily achived by picking prime which is bigger than maximum
|
||||
* number of cores and ensuring that count of hash table entries is not
|
||||
* divisible by this number. Let's choose 4099, which is smallest prime
|
||||
* greater than OCF_CORE_MAX (which is 4096).
|
||||
*/
|
||||
#define OCF_HASH_PRIME 4099
|
||||
|
||||
static inline ocf_cache_line_t ocf_metadata_hash_func(ocf_cache_t cache,
|
||||
uint64_t cache_line_num, ocf_core_id_t core_id)
|
||||
uint64_t core_line_num, ocf_core_id_t core_id)
|
||||
{
|
||||
return (ocf_cache_line_t) ((cache_line_num * (core_id + 1)) %
|
||||
return (ocf_cache_line_t) ((core_line_num * OCF_HASH_PRIME + core_id) %
|
||||
cache->device->hash_table_entries);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user