aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2015-02-25 10:31:53 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-27 16:06:02 -0500
commit8331de75cb13fc907ceba78e698c42150e61dda9 (patch)
tree5732e31d9694fa924ee1460b363801bcbfce2304 /lib
parent0d79a493e507437a2135e5ac1a447d4d503488d8 (diff)
rhashtable: unconditionally grow when max_shift is not specified
While commit c0c09bfdc415 ("rhashtable: avoid unnecessary wakeup for worker queue") rightfully moved part of the decision making of whether we should expand or shrink from the expand/shrink functions themselves into insert/delete functions in order to avoid unnecessary worker wake-ups, it however introduced a regression by doing so. Before that change, if no max_shift was specified (= 0) on rhashtable initialization, rhashtable_expand() would just grow unconditionally and lets the available memory be the limiting factor. After that change, if no max_shift was specified, there would be _no_ expansion step at all. Given that netlink and tipc have a max_shift specified, it was not visible there, but Josh Hunt reported that if nft that starts out with a default element hint of 3 if not otherwise provided, would slow i.e. inserts down trememdously as it cannot grow larger to relax table occupancy. Given that the test case verifies shrinks/expands manually, we also must remove pointer to the helper functions to explicitly avoid parallel resizing on insertions/deletions. test_bucket_stats() and test_rht_lookup() could also be wrapped around rhashtable mutex to explicitly synchronize a walk from resizing, but I think that defeats the actual test case which intended to have explicit test steps, i.e. 1) inserts, 2) expands, 3) shrinks, 4) deletions, with object verification after each stage. Reported-by: Josh Hunt <johunt@akamai.com> Fixes: c0c09bfdc415 ("rhashtable: avoid unnecessary wakeup for worker queue") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Ying Xue <ying.xue@windriver.com> Cc: Josh Hunt <johunt@akamai.com> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/rhashtable.c2
-rw-r--r--lib/test_rhashtable.c2
2 files changed, 1 insertions, 3 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index e3a04e4b3ec5..bcf119bfdef4 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -251,7 +251,7 @@ bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size)
251{ 251{
252 /* Expand table when exceeding 75% load */ 252 /* Expand table when exceeding 75% load */
253 return atomic_read(&ht->nelems) > (new_size / 4 * 3) && 253 return atomic_read(&ht->nelems) > (new_size / 4 * 3) &&
254 (ht->p.max_shift && atomic_read(&ht->shift) < ht->p.max_shift); 254 (!ht->p.max_shift || atomic_read(&ht->shift) < ht->p.max_shift);
255} 255}
256EXPORT_SYMBOL_GPL(rht_grow_above_75); 256EXPORT_SYMBOL_GPL(rht_grow_above_75);
257 257
diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
index 58b995323c44..f9e9d734446a 100644
--- a/lib/test_rhashtable.c
+++ b/lib/test_rhashtable.c
@@ -202,8 +202,6 @@ static int __init test_rht_init(void)
202 .key_len = sizeof(int), 202 .key_len = sizeof(int),
203 .hashfn = jhash, 203 .hashfn = jhash,
204 .nulls_base = (3U << RHT_BASE_SHIFT), 204 .nulls_base = (3U << RHT_BASE_SHIFT),
205 .grow_decision = rht_grow_above_75,
206 .shrink_decision = rht_shrink_below_30,
207 }; 205 };
208 int err; 206 int err;
209 207