aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/rhashtable.h10
-rw-r--r--lib/rhashtable.c12
-rw-r--r--lib/test_rhashtable.c2
-rw-r--r--net/netlink/af_netlink.c2
-rw-r--r--net/tipc/socket.c4
5 files changed, 13 insertions, 17 deletions
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 1695378b3c5b..99425f2be708 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -51,7 +51,6 @@ struct rhash_head {
51 * @size: Number of hash buckets 51 * @size: Number of hash buckets
52 * @rehash: Current bucket being rehashed 52 * @rehash: Current bucket being rehashed
53 * @hash_rnd: Random seed to fold into hash 53 * @hash_rnd: Random seed to fold into hash
54 * @shift: Current size (1 << shift)
55 * @locks_mask: Mask to apply before accessing locks[] 54 * @locks_mask: Mask to apply before accessing locks[]
56 * @locks: Array of spinlocks protecting individual buckets 55 * @locks: Array of spinlocks protecting individual buckets
57 * @walkers: List of active walkers 56 * @walkers: List of active walkers
@@ -63,7 +62,6 @@ struct bucket_table {
63 unsigned int size; 62 unsigned int size;
64 unsigned int rehash; 63 unsigned int rehash;
65 u32 hash_rnd; 64 u32 hash_rnd;
66 u32 shift;
67 unsigned int locks_mask; 65 unsigned int locks_mask;
68 spinlock_t *locks; 66 spinlock_t *locks;
69 struct list_head walkers; 67 struct list_head walkers;
@@ -85,8 +83,8 @@ struct rhashtable;
85 * @key_len: Length of key 83 * @key_len: Length of key
86 * @key_offset: Offset of key in struct to be hashed 84 * @key_offset: Offset of key in struct to be hashed
87 * @head_offset: Offset of rhash_head in struct to be hashed 85 * @head_offset: Offset of rhash_head in struct to be hashed
88 * @max_shift: Maximum number of shifts while expanding 86 * @max_size: Maximum size while expanding
89 * @min_shift: Minimum number of shifts while shrinking 87 * @min_size: Minimum size while shrinking
90 * @nulls_base: Base value to generate nulls marker 88 * @nulls_base: Base value to generate nulls marker
91 * @locks_mul: Number of bucket locks to allocate per cpu (default: 128) 89 * @locks_mul: Number of bucket locks to allocate per cpu (default: 128)
92 * @hashfn: Function to hash key 90 * @hashfn: Function to hash key
@@ -97,8 +95,8 @@ struct rhashtable_params {
97 size_t key_len; 95 size_t key_len;
98 size_t key_offset; 96 size_t key_offset;
99 size_t head_offset; 97 size_t head_offset;
100 size_t max_shift; 98 unsigned int max_size;
101 size_t min_shift; 99 unsigned int min_size;
102 u32 nulls_base; 100 u32 nulls_base;
103 size_t locks_mul; 101 size_t locks_mul;
104 rht_hashfn_t hashfn; 102 rht_hashfn_t hashfn;
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 09a7ada89ade..5f8fe3e88219 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 */
@@ -162,7 +162,6 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
162 return NULL; 162 return NULL;
163 163
164 tbl->size = nbuckets; 164 tbl->size = nbuckets;
165 tbl->shift = ilog2(nbuckets);
166 165
167 if (alloc_bucket_locks(ht, tbl) < 0) { 166 if (alloc_bucket_locks(ht, tbl) < 0) {
168 bucket_table_free(tbl); 167 bucket_table_free(tbl);
@@ -189,7 +188,7 @@ static bool rht_grow_above_75(const struct rhashtable *ht,
189{ 188{
190 /* Expand table when exceeding 75% load */ 189 /* Expand table when exceeding 75% load */
191 return atomic_read(&ht->nelems) > (tbl->size / 4 * 3) && 190 return atomic_read(&ht->nelems) > (tbl->size / 4 * 3) &&
192 (!ht->p.max_shift || tbl->shift < ht->p.max_shift); 191 (!ht->p.max_size || tbl->size < ht->p.max_size);
193} 192}
194 193
195/** 194/**
@@ -202,7 +201,7 @@ static bool rht_shrink_below_30(const struct rhashtable *ht,
202{ 201{
203 /* Shrink table beneath 30% load */ 202 /* Shrink table beneath 30% load */
204 return atomic_read(&ht->nelems) < (tbl->size * 3 / 10) && 203 return atomic_read(&ht->nelems) < (tbl->size * 3 / 10) &&
205 tbl->shift > ht->p.min_shift; 204 tbl->size > ht->p.min_size;
206} 205}
207 206
208static int rhashtable_rehash_one(struct rhashtable *ht, unsigned old_hash) 207static int rhashtable_rehash_one(struct rhashtable *ht, unsigned old_hash)
@@ -874,7 +873,7 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_stop);
874static size_t rounded_hashtable_size(struct rhashtable_params *params) 873static size_t rounded_hashtable_size(struct rhashtable_params *params)
875{ 874{
876 return max(roundup_pow_of_two(params->nelem_hint * 4 / 3), 875 return max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
877 1UL << params->min_shift); 876 (unsigned long)params->min_size);
878} 877}
879 878
880/** 879/**
@@ -934,8 +933,7 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
934 if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT)) 933 if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT))
935 return -EINVAL; 934 return -EINVAL;
936 935
937 params->min_shift = max_t(size_t, params->min_shift, 936 params->min_size = max(params->min_size, HASH_MIN_SIZE);
938 ilog2(HASH_MIN_SIZE));
939 937
940 if (params->nelem_hint) 938 if (params->nelem_hint)
941 size = rounded_hashtable_size(params); 939 size = rounded_hashtable_size(params);
diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
index 16974fd89e4e..2bc403d8f9ee 100644
--- a/lib/test_rhashtable.c
+++ b/lib/test_rhashtable.c
@@ -201,7 +201,7 @@ static int __init test_rht_init(void)
201 .key_offset = offsetof(struct test_obj, value), 201 .key_offset = offsetof(struct test_obj, value),
202 .key_len = sizeof(int), 202 .key_len = sizeof(int),
203 .hashfn = jhash, 203 .hashfn = jhash,
204 .max_shift = 1, /* we expand/shrink manually here */ 204 .max_size = 2, /* we expand/shrink manually here */
205 .nulls_base = (3U << RHT_BASE_SHIFT), 205 .nulls_base = (3U << RHT_BASE_SHIFT),
206 }; 206 };
207 int err; 207 int err;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 6b0f21950e09..d97aed628bda 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -3123,7 +3123,7 @@ static int __init netlink_proto_init(void)
3123 .key_offset = offsetof(struct netlink_sock, portid), 3123 .key_offset = offsetof(struct netlink_sock, portid),
3124 .key_len = sizeof(u32), /* portid */ 3124 .key_len = sizeof(u32), /* portid */
3125 .hashfn = jhash, 3125 .hashfn = jhash,
3126 .max_shift = 16, /* 64K */ 3126 .max_size = 65536,
3127 }; 3127 };
3128 3128
3129 if (err != 0) 3129 if (err != 0)
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 813847d25a49..d7a6c10202e9 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -2286,8 +2286,8 @@ int tipc_sk_rht_init(struct net *net)
2286 .key_offset = offsetof(struct tipc_sock, portid), 2286 .key_offset = offsetof(struct tipc_sock, portid),
2287 .key_len = sizeof(u32), /* portid */ 2287 .key_len = sizeof(u32), /* portid */
2288 .hashfn = jhash, 2288 .hashfn = jhash,
2289 .max_shift = 20, /* 1M */ 2289 .max_size = 1048576,
2290 .min_shift = 8, /* 256 */ 2290 .min_size = 256,
2291 }; 2291 };
2292 2292
2293 return rhashtable_init(&tn->sk_rht, &rht_params); 2293 return rhashtable_init(&tn->sk_rht, &rht_params);