diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-08-09 11:57:13 -0400 | 
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-08-09 13:53:11 -0400 | 
| commit | bed7ad8387b9dc99c675cd1e13984a337fecd1c7 (patch) | |
| tree | ec771b68a08e1a408a271644b7568b11634060c1 /lib/hash.h | |
| parent | d1783281630a888a61a24299ae73c973588ff481 (diff) | |
lib: use load factor as hash expansion trigger
Previous strategy was to resize the hash table when the length of any
one bucket exceeded a certain size, with some logic for intelligently
stopping resizes when the gains from doing so weren't sufficient. While
this was a good idea that attempted to optimize both space and lookup
time, unfortunately under transient degenerate conditions this led to
some issues with the tables not resizing when they should have,
harming performance. The resizing restriction was lifted, but this had
the result of exacerbating degenerate behavior and caused out of memory
conditions.
This patch changes the hash expansion criterion to be based on the
number of elements in the table. Once the # of elements in the table
exceeds the number of buckets, the table size is doubled. While the
space efficiency of this method decreases relative to the perfectness of
the hash function, at least this strategy puts the table performance
squarely in the hands of the hash function.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/hash.h')
| -rw-r--r-- | lib/hash.h | 5 | 
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/hash.h b/lib/hash.h index 236abbbd6a..b6fe27e257 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -28,8 +28,9 @@ DECLARE_MTYPE(HASH)  DECLARE_MTYPE(HASH_BACKET)  /* Default hash table size.  */ -#define HASH_INITIAL_SIZE     256	/* initial number of backets. */ -#define HASH_THRESHOLD	      10	/* expand when backet. */ +#define HASH_INITIAL_SIZE 256 +/* Expansion threshold */ +#define HASH_THRESHOLD(used, size) ((used) > (size))  #define HASHWALK_CONTINUE 0  #define HASHWALK_ABORT -1  | 
