Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Thomas Graf and committed by
David S. Miller
a998f712 91a0f930

+8 -2
+8 -2
lib/rhashtable.c
··· 933 933 if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT)) 934 934 return -EINVAL; 935 935 936 - params->min_size = max(params->min_size, HASH_MIN_SIZE); 937 - 938 936 if (params->nelem_hint) 939 937 size = rounded_hashtable_size(params); 940 938 941 939 memset(ht, 0, sizeof(*ht)); 942 940 mutex_init(&ht->mutex); 943 941 memcpy(&ht->p, params, sizeof(*params)); 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); 944 950 945 951 if (params->locks_mul) 946 952 ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);