提交 a998f712 编写于 作者: T Thomas Graf 提交者: David S. Miller

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: NThomas Graf <tgraf@suug.ch>
Acked-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 91a0f930
...@@ -933,8 +933,6 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params) ...@@ -933,8 +933,6 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT)) if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT))
return -EINVAL; return -EINVAL;
params->min_size = max(params->min_size, HASH_MIN_SIZE);
if (params->nelem_hint) if (params->nelem_hint)
size = rounded_hashtable_size(params); size = rounded_hashtable_size(params);
...@@ -942,6 +940,14 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params) ...@@ -942,6 +940,14 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
mutex_init(&ht->mutex); mutex_init(&ht->mutex);
memcpy(&ht->p, params, sizeof(*params)); memcpy(&ht->p, params, sizeof(*params));
if (params->min_size)
ht->p.min_size = roundup_pow_of_two(params->min_size);
if (params->max_size)
ht->p.max_size = rounddown_pow_of_two(params->max_size);
ht->p.min_size = max(params->min_size, HASH_MIN_SIZE);
if (params->locks_mul) if (params->locks_mul)
ht->p.locks_mul = roundup_pow_of_two(params->locks_mul); ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册