Commit 10da66f7 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

fib: avoid false sharing on fib_table_hash

While doing profile analysis, I found fib_hash_table was sometime in a
cache line shared by a possibly often written kernel structure.

(CONFIG_IP_ROUTE_MULTIPATH || !CONFIG_IPV6_MULTIPLE_TABLES)

It's hard to detect because not easily reproductible.

Make sure we allocate a full cache line to keep this shared in all cpus
caches.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 874ffa8f
...@@ -1016,16 +1016,15 @@ static struct notifier_block fib_netdev_notifier = { ...@@ -1016,16 +1016,15 @@ static struct notifier_block fib_netdev_notifier = {
static int __net_init ip_fib_net_init(struct net *net) static int __net_init ip_fib_net_init(struct net *net)
{ {
int err; int err;
unsigned int i; size_t size = sizeof(struct hlist_head) * FIB_TABLE_HASHSZ;
/* Avoid false sharing : Use at least a full cache line */
size = max_t(size_t, size, L1_CACHE_BYTES);
net->ipv4.fib_table_hash = kzalloc( net->ipv4.fib_table_hash = kzalloc(size, GFP_KERNEL);
sizeof(struct hlist_head)*FIB_TABLE_HASHSZ, GFP_KERNEL);
if (net->ipv4.fib_table_hash == NULL) if (net->ipv4.fib_table_hash == NULL)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < FIB_TABLE_HASHSZ; i++)
INIT_HLIST_HEAD(&net->ipv4.fib_table_hash[i]);
err = fib4_rules_init(net); err = fib4_rules_init(net);
if (err < 0) if (err < 0)
goto fail; goto fail;
......
...@@ -1500,15 +1500,18 @@ static void fib6_gc_timer_cb(unsigned long arg) ...@@ -1500,15 +1500,18 @@ static void fib6_gc_timer_cb(unsigned long arg)
static int __net_init fib6_net_init(struct net *net) static int __net_init fib6_net_init(struct net *net)
{ {
size_t size = sizeof(struct hlist_head) * FIB6_TABLE_HASHSZ;
setup_timer(&net->ipv6.ip6_fib_timer, fib6_gc_timer_cb, (unsigned long)net); setup_timer(&net->ipv6.ip6_fib_timer, fib6_gc_timer_cb, (unsigned long)net);
net->ipv6.rt6_stats = kzalloc(sizeof(*net->ipv6.rt6_stats), GFP_KERNEL); net->ipv6.rt6_stats = kzalloc(sizeof(*net->ipv6.rt6_stats), GFP_KERNEL);
if (!net->ipv6.rt6_stats) if (!net->ipv6.rt6_stats)
goto out_timer; goto out_timer;
net->ipv6.fib_table_hash = kcalloc(FIB6_TABLE_HASHSZ, /* Avoid false sharing : Use at least a full cache line */
sizeof(*net->ipv6.fib_table_hash), size = max_t(size_t, size, L1_CACHE_BYTES);
GFP_KERNEL);
net->ipv6.fib_table_hash = kzalloc(size, GFP_KERNEL);
if (!net->ipv6.fib_table_hash) if (!net->ipv6.fib_table_hash)
goto out_rt6_stats; goto out_rt6_stats;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment