aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rhashtable.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2015-03-19 18:31:13 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-19 21:02:23 -0400
commita998f712f77ea4892d3fcf24e0a67603e63da128 (patch)
tree784c021c158fe38467363f023401520872c4ab30 /lib/rhashtable.c
parent91a0f930560171e5d45465d05fd4e66a5ee3a745 (diff)
rhashtable: Round up/down min/max_size to ensure we respect limit
Round up min_size respectively round down max_size to the next power of two to make sure we always respect the limit specified by the user. This is required because we compare the table size against the limit before we expand or shrink. Also fixes a minor bug where we modified min_size in the params provided instead of the copy stored in struct rhashtable. Signed-off-by: Thomas Graf <tgraf@suug.ch> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/rhashtable.c')
-rw-r--r--lib/rhashtable.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 5f8fe3e88219..e75c48d9d82f 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -933,8 +933,6 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
933 if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT)) 933 if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT))
934 return -EINVAL; 934 return -EINVAL;
935 935
936 params->min_size = max(params->min_size, HASH_MIN_SIZE);
937
938 if (params->nelem_hint) 936 if (params->nelem_hint)
939 size = rounded_hashtable_size(params); 937 size = rounded_hashtable_size(params);
940 938
@@ -942,6 +940,14 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
942 mutex_init(&ht->mutex); 940 mutex_init(&ht->mutex);
943 memcpy(&ht->p, params, sizeof(*params)); 941 memcpy(&ht->p, params, sizeof(*params));
944 942
943 if (params->min_size)
944 ht->p.min_size = roundup_pow_of_two(params->min_size);
945
946 if (params->max_size)
947 ht->p.max_size = rounddown_pow_of_two(params->max_size);
948
949 ht->p.min_size = max(params->min_size, HASH_MIN_SIZE);
950
945 if (params->locks_mul) 951 if (params->locks_mul)
946 ht->p.locks_mul = roundup_pow_of_two(params->locks_mul); 952 ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);
947 else 953 else