diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2015-03-18 05:01:16 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-18 12:46:40 -0400 |
commit | c2e213cff701fce71a0aba8de82f2c2a4acf52ae (patch) | |
tree | 5b26d130b31b9a8acea6fca416021c08731d6e81 /lib | |
parent | 6aebd940840a4d3a0a8ffc5883d3892f4bd61e90 (diff) |
rhashtable: Introduce max_size/min_size
This patch adds the parameters max_size and min_size which are
meant to replace max_shift and min_shift.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rhashtable.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 097400362467..c4061bbd0113 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <linux/err.h> | 27 | #include <linux/err.h> |
28 | 28 | ||
29 | #define HASH_DEFAULT_SIZE 64UL | 29 | #define HASH_DEFAULT_SIZE 64UL |
30 | #define HASH_MIN_SIZE 4UL | 30 | #define HASH_MIN_SIZE 4U |
31 | #define BUCKET_LOCKS_PER_CPU 128UL | 31 | #define BUCKET_LOCKS_PER_CPU 128UL |
32 | 32 | ||
33 | /* Base bits plus 1 bit for nulls marker */ | 33 | /* Base bits plus 1 bit for nulls marker */ |
@@ -188,7 +188,8 @@ static bool rht_grow_above_75(const struct rhashtable *ht, | |||
188 | { | 188 | { |
189 | /* Expand table when exceeding 75% load */ | 189 | /* Expand table when exceeding 75% load */ |
190 | return atomic_read(&ht->nelems) > (tbl->size / 4 * 3) && | 190 | return atomic_read(&ht->nelems) > (tbl->size / 4 * 3) && |
191 | (!ht->p.max_shift || tbl->size < (1 << ht->p.max_shift)); | 191 | (!ht->p.max_shift || tbl->size < (1 << ht->p.max_shift)) && |
192 | (!ht->p.max_size || tbl->size < ht->p.max_size); | ||
192 | } | 193 | } |
193 | 194 | ||
194 | /** | 195 | /** |
@@ -201,7 +202,8 @@ static bool rht_shrink_below_30(const struct rhashtable *ht, | |||
201 | { | 202 | { |
202 | /* Shrink table beneath 30% load */ | 203 | /* Shrink table beneath 30% load */ |
203 | return atomic_read(&ht->nelems) < (tbl->size * 3 / 10) && | 204 | return atomic_read(&ht->nelems) < (tbl->size * 3 / 10) && |
204 | tbl->size > (1 << ht->p.min_shift); | 205 | tbl->size > (1 << ht->p.min_shift) && |
206 | tbl->size > ht->p.min_size; | ||
205 | } | 207 | } |
206 | 208 | ||
207 | static int rhashtable_rehash_one(struct rhashtable *ht, unsigned old_hash) | 209 | static int rhashtable_rehash_one(struct rhashtable *ht, unsigned old_hash) |
@@ -873,7 +875,8 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_stop); | |||
873 | static size_t rounded_hashtable_size(struct rhashtable_params *params) | 875 | static size_t rounded_hashtable_size(struct rhashtable_params *params) |
874 | { | 876 | { |
875 | return max(roundup_pow_of_two(params->nelem_hint * 4 / 3), | 877 | return max(roundup_pow_of_two(params->nelem_hint * 4 / 3), |
876 | 1UL << params->min_shift); | 878 | max(1UL << params->min_shift, |
879 | (unsigned long)params->min_size)); | ||
877 | } | 880 | } |
878 | 881 | ||
879 | /** | 882 | /** |
@@ -935,6 +938,7 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params) | |||
935 | 938 | ||
936 | params->min_shift = max_t(size_t, params->min_shift, | 939 | params->min_shift = max_t(size_t, params->min_shift, |
937 | ilog2(HASH_MIN_SIZE)); | 940 | ilog2(HASH_MIN_SIZE)); |
941 | params->min_size = max(params->min_size, HASH_MIN_SIZE); | ||
938 | 942 | ||
939 | if (params->nelem_hint) | 943 | if (params->nelem_hint) |
940 | size = rounded_hashtable_size(params); | 944 | size = rounded_hashtable_size(params); |