fib: introduce fib_alias_accessed() helper
authorEric Dumazet <eric.dumazet@gmail.com>
Wed, 20 Oct 2010 22:03:38 +0000 (22:03 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 21 Oct 2010 10:09:41 +0000 (03:09 -0700)
Perf tools session at NFWS 2010 pointed out a false sharing on struct
fib_alias that can be avoided pretty easily, if we set FA_S_ACCESSED bit
only if needed (ie : not already set)

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/fib_hash.c
net/ipv4/fib_lookup.h
net/ipv4/fib_semantics.c
net/ipv4/fib_trie.c

index 4f1aafd3ba89f92a65d01488a37591c35b0f669c..43e1c594ce8f38aeae59dbf32dd6dfac747d2c46 100644 (file)
@@ -335,7 +335,8 @@ void fib_table_select_default(struct fib_table *tb,
                        if (!next_fi->fib_nh[0].nh_gw ||
                            next_fi->fib_nh[0].nh_scope != RT_SCOPE_LINK)
                                continue;
-                       fa->fa_state |= FA_S_ACCESSED;
+
+                       fib_alias_accessed(fa);
 
                        if (fi == NULL) {
                                if (next_fi != res->fi)
index 5072d8effd5d21a75a6b63494f3630bfb48de921..a29edf2219c8437b811bcce27fdd2cd9fca0a9fc 100644 (file)
@@ -17,6 +17,13 @@ struct fib_alias {
 
 #define FA_S_ACCESSED  0x01
 
+/* Dont write on fa_state unless needed, to keep it shared on all cpus */
+static inline void fib_alias_accessed(struct fib_alias *fa)
+{
+       if (!(fa->fa_state & FA_S_ACCESSED))
+               fa->fa_state |= FA_S_ACCESSED;
+}
+
 /* Exported by fib_semantics.c */
 extern int fib_semantic_match(struct list_head *head,
                              const struct flowi *flp,
index 6734c9cab24852330a838b3154314bafb3e03a6c..3e0da3ef6116df8b9b4fa6a70272ddeac8cac0d4 100644 (file)
@@ -901,7 +901,7 @@ int fib_semantic_match(struct list_head *head, const struct flowi *flp,
                if (fa->fa_scope < flp->fl4_scope)
                        continue;
 
-               fa->fa_state |= FA_S_ACCESSED;
+               fib_alias_accessed(fa);
 
                err = fib_props[fa->fa_type].error;
                if (err == 0) {
index 31494f33568638a4d540a90bc5541ee3977f9911..cd5e13aee7d5b689b76c834673d70dd7c334361e 100644 (file)
@@ -1838,7 +1838,8 @@ void fib_table_select_default(struct fib_table *tb,
                if (!next_fi->fib_nh[0].nh_gw ||
                    next_fi->fib_nh[0].nh_scope != RT_SCOPE_LINK)
                        continue;
-               fa->fa_state |= FA_S_ACCESSED;
+
+               fib_alias_accessed(fa);
 
                if (fi == NULL) {
                        if (next_fi != res->fi)