Skip to content

Commit b65885d

Browse files
committed
Merge branch 'rhashtable_remove_shift'
Herbert Xu says: ==================== rhashtable: Kill redundant shift parameter I was trying to squeeze bucket_table->rehash in by downsizing bucket_table->size, only to find that my spot had been taken over by bucket_table->shift. These patches kill shift and makes me feel better :) v2 corrects the typo in the test_rhashtable changelog and also notes the min_shift parameter in the tipc patch changelog. ==================== Acked-by: Thomas Graf <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents a61bfa6 + e2e21c1 commit b65885d

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

include/linux/rhashtable.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ struct rhash_head {
5151
* @size: Number of hash buckets
5252
* @rehash: Current bucket being rehashed
5353
* @hash_rnd: Random seed to fold into hash
54-
* @shift: Current size (1 << shift)
5554
* @locks_mask: Mask to apply before accessing locks[]
5655
* @locks: Array of spinlocks protecting individual buckets
5756
* @walkers: List of active walkers
@@ -63,7 +62,6 @@ struct bucket_table {
6362
unsigned int size;
6463
unsigned int rehash;
6564
u32 hash_rnd;
66-
u32 shift;
6765
unsigned int locks_mask;
6866
spinlock_t *locks;
6967
struct list_head walkers;
@@ -85,8 +83,8 @@ struct rhashtable;
8583
* @key_len: Length of key
8684
* @key_offset: Offset of key in struct to be hashed
8785
* @head_offset: Offset of rhash_head in struct to be hashed
88-
* @max_shift: Maximum number of shifts while expanding
89-
* @min_shift: Minimum number of shifts while shrinking
86+
* @max_size: Maximum size while expanding
87+
* @min_size: Minimum size while shrinking
9088
* @nulls_base: Base value to generate nulls marker
9189
* @locks_mul: Number of bucket locks to allocate per cpu (default: 128)
9290
* @hashfn: Function to hash key
@@ -97,8 +95,8 @@ struct rhashtable_params {
9795
size_t key_len;
9896
size_t key_offset;
9997
size_t head_offset;
100-
size_t max_shift;
101-
size_t min_shift;
98+
unsigned int max_size;
99+
unsigned int min_size;
102100
u32 nulls_base;
103101
size_t locks_mul;
104102
rht_hashfn_t hashfn;

lib/rhashtable.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <linux/err.h>
2828

2929
#define HASH_DEFAULT_SIZE 64UL
30-
#define HASH_MIN_SIZE 4UL
30+
#define HASH_MIN_SIZE 4U
3131
#define BUCKET_LOCKS_PER_CPU 128UL
3232

3333
/* Base bits plus 1 bit for nulls marker */
@@ -162,7 +162,6 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
162162
return NULL;
163163

164164
tbl->size = nbuckets;
165-
tbl->shift = ilog2(nbuckets);
166165

167166
if (alloc_bucket_locks(ht, tbl) < 0) {
168167
bucket_table_free(tbl);
@@ -189,7 +188,7 @@ static bool rht_grow_above_75(const struct rhashtable *ht,
189188
{
190189
/* Expand table when exceeding 75% load */
191190
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);
193192
}
194193

195194
/**
@@ -202,7 +201,7 @@ static bool rht_shrink_below_30(const struct rhashtable *ht,
202201
{
203202
/* Shrink table beneath 30% load */
204203
return atomic_read(&ht->nelems) < (tbl->size * 3 / 10) &&
205-
tbl->shift > ht->p.min_shift;
204+
tbl->size > ht->p.min_size;
206205
}
207206

208207
static int rhashtable_rehash_one(struct rhashtable *ht, unsigned old_hash)
@@ -874,7 +873,7 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_stop);
874873
static size_t rounded_hashtable_size(struct rhashtable_params *params)
875874
{
876875
return max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
877-
1UL << params->min_shift);
876+
(unsigned long)params->min_size);
878877
}
879878

880879
/**
@@ -934,8 +933,7 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
934933
if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT))
935934
return -EINVAL;
936935

937-
params->min_shift = max_t(size_t, params->min_shift,
938-
ilog2(HASH_MIN_SIZE));
936+
params->min_size = max(params->min_size, HASH_MIN_SIZE);
939937

940938
if (params->nelem_hint)
941939
size = rounded_hashtable_size(params);

lib/test_rhashtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int __init test_rht_init(void)
201201
.key_offset = offsetof(struct test_obj, value),
202202
.key_len = sizeof(int),
203203
.hashfn = jhash,
204-
.max_shift = 1, /* we expand/shrink manually here */
204+
.max_size = 2, /* we expand/shrink manually here */
205205
.nulls_base = (3U << RHT_BASE_SHIFT),
206206
};
207207
int err;

net/netlink/af_netlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,7 @@ static int __init netlink_proto_init(void)
31233123
.key_offset = offsetof(struct netlink_sock, portid),
31243124
.key_len = sizeof(u32), /* portid */
31253125
.hashfn = jhash,
3126-
.max_shift = 16, /* 64K */
3126+
.max_size = 65536,
31273127
};
31283128

31293129
if (err != 0)

net/tipc/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,8 +2286,8 @@ int tipc_sk_rht_init(struct net *net)
22862286
.key_offset = offsetof(struct tipc_sock, portid),
22872287
.key_len = sizeof(u32), /* portid */
22882288
.hashfn = jhash,
2289-
.max_shift = 20, /* 1M */
2290-
.min_shift = 8, /* 256 */
2289+
.max_size = 1048576,
2290+
.min_size = 256,
22912291
};
22922292

22932293
return rhashtable_init(&tn->sk_rht, &rht_params);

0 commit comments

Comments
 (0)