rhashtable: reorganize struct rhashtable layout
authorEric Dumazet <edumazet@google.com>
Thu, 13 Sep 2018 14:58:48 +0000 (07:58 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Sep 2018 20:43:46 +0000 (22:43 +0200)
While under frags DDOS I noticed unfortunate false sharing between
@nelems and @params.automatic_shrinking

Move @nelems at the end of struct rhashtable so that first cache line
is shared between all cpus, because almost never dirtied.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit e5d672a0780d9e7118caad4c171ec88b8299398d)
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/rhashtable.h

index 7fd514f36e74a9dbecd3664ed6c917c41326aee1..a4be6388a98035e49d816886785380336f861ba6 100644 (file)
@@ -152,25 +152,25 @@ struct rhashtable_params {
 /**
  * struct rhashtable - Hash table handle
  * @tbl: Bucket table
- * @nelems: Number of elements in table
  * @key_len: Key length for hashfn
- * @p: Configuration parameters
  * @max_elems: Maximum number of elements in table
+ * @p: Configuration parameters
  * @rhlist: True if this is an rhltable
  * @run_work: Deferred worker to expand/shrink asynchronously
  * @mutex: Mutex to protect current/future table swapping
  * @lock: Spin lock to protect walker list
+ * @nelems: Number of elements in table
  */
 struct rhashtable {
        struct bucket_table __rcu       *tbl;
-       atomic_t                        nelems;
        unsigned int                    key_len;
-       struct rhashtable_params        p;
        unsigned int                    max_elems;
+       struct rhashtable_params        p;
        bool                            rhlist;
        struct work_struct              run_work;
        struct mutex                    mutex;
        spinlock_t                      lock;
+       atomic_t                        nelems;
 };
 
 /**