]> git.karo-electronics.de Git - linux-beck.git/commitdiff
rhashtable: Disable automatic shrinking by default
authorThomas Graf <tgraf@suug.ch>
Tue, 24 Mar 2015 20:42:19 +0000 (20:42 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 24 Mar 2015 21:48:40 +0000 (17:48 -0400)
Introduce a new bool automatic_shrinking to require the
user to explicitly opt-in to automatic shrinking of tables.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/rhashtable.h
lib/rhashtable.c
net/netfilter/nft_hash.c
net/netlink/af_netlink.c
net/tipc/socket.c

index 0e1f975ad101ba721ce25577170aa4f347162f4b..ae26c494e2302f9d3c3fe6b04be713d2d53e2a16 100644 (file)
@@ -2,7 +2,7 @@
  * Resizable, Scalable, Concurrent Hash Table
  *
  * Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au>
- * Copyright (c) 2014 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2014-2015 Thomas Graf <tgraf@suug.ch>
  * Copyright (c) 2008-2014 Patrick McHardy <kaber@trash.net>
  *
  * Code partially derived from nft_hash
@@ -104,6 +104,7 @@ struct rhashtable;
  * @min_size: Minimum size while shrinking
  * @nulls_base: Base value to generate nulls marker
  * @insecure_elasticity: Set to true to disable chain length checks
+ * @automatic_shrinking: Enable automatic shrinking of tables
  * @locks_mul: Number of bucket locks to allocate per cpu (default: 128)
  * @hashfn: Hash function (default: jhash2 if !(key_len % 4), or jhash)
  * @obj_hashfn: Function to hash object
@@ -118,6 +119,7 @@ struct rhashtable_params {
        unsigned int            min_size;
        u32                     nulls_base;
        bool                    insecure_elasticity;
+       bool                    automatic_shrinking;
        size_t                  locks_mul;
        rht_hashfn_t            hashfn;
        rht_obj_hashfn_t        obj_hashfn;
@@ -784,7 +786,8 @@ static inline int rhashtable_remove_fast(
                goto out;
 
        atomic_dec(&ht->nelems);
-       if (rht_shrink_below_30(ht, tbl))
+       if (unlikely(ht->p.automatic_shrinking &&
+                    rht_shrink_below_30(ht, tbl)))
                schedule_work(&ht->run_work);
 
 out:
index 50abe4fec4b8e87bb6d2870577a19f8f4445e6a0..50374d181148ed2979f551097ae0953dd02e75c4 100644 (file)
@@ -367,7 +367,7 @@ static void rht_deferred_worker(struct work_struct *work)
 
        if (rht_grow_above_75(ht, tbl))
                rhashtable_expand(ht);
-       else if (rht_shrink_below_30(ht, tbl))
+       else if (ht->p.automatic_shrinking && rht_shrink_below_30(ht, tbl))
                rhashtable_shrink(ht);
 
        err = rhashtable_rehash_table(ht);
index ad3966976cf598572653c7a030281d148c1a7698..8577a37af18b214a668e111e55a6360a709e4d37 100644 (file)
@@ -172,6 +172,7 @@ static const struct rhashtable_params nft_hash_params = {
        .head_offset = offsetof(struct nft_hash_elem, node),
        .key_offset = offsetof(struct nft_hash_elem, key),
        .hashfn = jhash,
+       .automatic_shrinking = true,
 };
 
 static int nft_hash_init(const struct nft_set *set,
index e2f7f28148e00b54fe9c237533633e97a78fb8b1..4caa809dbbe0332ca32b7b0279e61289b01574e3 100644 (file)
@@ -3142,6 +3142,7 @@ static const struct rhashtable_params netlink_rhashtable_params = {
        .obj_hashfn = netlink_hash,
        .obj_cmpfn = netlink_compare,
        .max_size = 65536,
+       .automatic_shrinking = true,
 };
 
 static int __init netlink_proto_init(void)
index 09471051947768eed472f3049e3da54229aadb91..ee90d74d7516e93af0587f5898d81e41f870e267 100644 (file)
@@ -2297,6 +2297,7 @@ static const struct rhashtable_params tsk_rht_params = {
        .key_len = sizeof(u32), /* portid */
        .max_size = 1048576,
        .min_size = 256,
+       .automatic_shrinking = true,
 };
 
 int tipc_sk_rht_init(struct net *net)