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

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 <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

+13 -17
+4 -6
include/linux/rhashtable.h
··· 51 51 * @size: Number of hash buckets 52 52 * @rehash: Current bucket being rehashed 53 53 * @hash_rnd: Random seed to fold into hash 54 - * @shift: Current size (1 << shift) 55 54 * @locks_mask: Mask to apply before accessing locks[] 56 55 * @locks: Array of spinlocks protecting individual buckets 57 56 * @walkers: List of active walkers ··· 62 63 unsigned int size; 63 64 unsigned int rehash; 64 65 u32 hash_rnd; 65 - u32 shift; 66 66 unsigned int locks_mask; 67 67 spinlock_t *locks; 68 68 struct list_head walkers; ··· 83 85 * @key_len: Length of key 84 86 * @key_offset: Offset of key in struct to be hashed 85 87 * @head_offset: Offset of rhash_head in struct to be hashed 86 - * @max_shift: Maximum number of shifts while expanding 87 - * @min_shift: Minimum number of shifts while shrinking 88 + * @max_size: Maximum size while expanding 89 + * @min_size: Minimum size while shrinking 88 90 * @nulls_base: Base value to generate nulls marker 89 91 * @locks_mul: Number of bucket locks to allocate per cpu (default: 128) 90 92 * @hashfn: Function to hash key ··· 95 97 size_t key_len; 96 98 size_t key_offset; 97 99 size_t head_offset; 98 - size_t max_shift; 99 - size_t min_shift; 100 + unsigned int max_size; 101 + unsigned int min_size; 100 102 u32 nulls_base; 101 103 size_t locks_mul; 102 104 rht_hashfn_t hashfn;
+5 -7
lib/rhashtable.c
··· 27 27 #include <linux/err.h> 28 28 29 29 #define HASH_DEFAULT_SIZE 64UL 30 - #define HASH_MIN_SIZE 4UL 30 + #define HASH_MIN_SIZE 4U 31 31 #define BUCKET_LOCKS_PER_CPU 128UL 32 32 33 33 /* Base bits plus 1 bit for nulls marker */ ··· 162 162 return NULL; 163 163 164 164 tbl->size = nbuckets; 165 - tbl->shift = ilog2(nbuckets); 166 165 167 166 if (alloc_bucket_locks(ht, tbl) < 0) { 168 167 bucket_table_free(tbl); ··· 188 189 { 189 190 /* Expand table when exceeding 75% load */ 190 191 return atomic_read(&ht->nelems) > (tbl->size / 4 * 3) && 191 - (!ht->p.max_shift || tbl->shift < ht->p.max_shift); 192 + (!ht->p.max_size || tbl->size < ht->p.max_size); 192 193 } 193 194 194 195 /** ··· 201 202 { 202 203 /* Shrink table beneath 30% load */ 203 204 return atomic_read(&ht->nelems) < (tbl->size * 3 / 10) && 204 - tbl->shift > ht->p.min_shift; 205 + tbl->size > ht->p.min_size; 205 206 } 206 207 207 208 static int rhashtable_rehash_one(struct rhashtable *ht, unsigned old_hash) ··· 873 874 static size_t rounded_hashtable_size(struct rhashtable_params *params) 874 875 { 875 876 return max(roundup_pow_of_two(params->nelem_hint * 4 / 3), 876 - 1UL << params->min_shift); 877 + (unsigned long)params->min_size); 877 878 } 878 879 879 880 /** ··· 933 934 if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT)) 934 935 return -EINVAL; 935 936 936 - params->min_shift = max_t(size_t, params->min_shift, 937 - ilog2(HASH_MIN_SIZE)); 937 + params->min_size = max(params->min_size, HASH_MIN_SIZE); 938 938 939 939 if (params->nelem_hint) 940 940 size = rounded_hashtable_size(params);
+1 -1
lib/test_rhashtable.c
··· 201 201 .key_offset = offsetof(struct test_obj, value), 202 202 .key_len = sizeof(int), 203 203 .hashfn = jhash, 204 - .max_shift = 1, /* we expand/shrink manually here */ 204 + .max_size = 2, /* we expand/shrink manually here */ 205 205 .nulls_base = (3U << RHT_BASE_SHIFT), 206 206 }; 207 207 int err;
+1 -1
net/netlink/af_netlink.c
··· 3123 3123 .key_offset = offsetof(struct netlink_sock, portid), 3124 3124 .key_len = sizeof(u32), /* portid */ 3125 3125 .hashfn = jhash, 3126 - .max_shift = 16, /* 64K */ 3126 + .max_size = 65536, 3127 3127 }; 3128 3128 3129 3129 if (err != 0)
+2 -2
net/tipc/socket.c
··· 2286 2286 .key_offset = offsetof(struct tipc_sock, portid), 2287 2287 .key_len = sizeof(u32), /* portid */ 2288 2288 .hashfn = jhash, 2289 - .max_shift = 20, /* 1M */ 2290 - .min_shift = 8, /* 256 */ 2289 + .max_size = 1048576, 2290 + .min_size = 256, 2291 2291 }; 2292 2292 2293 2293 return rhashtable_init(&tn->sk_rht, &rht_params);