diff options
author | David S. Miller <davem@davemloft.net> | 2011-04-14 17:49:37 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-04-14 18:05:22 -0400 |
commit | 21d8c49e01a0c1c6eb6c750cd04110db4a539284 (patch) | |
tree | 03e19c4f6f24fd67da407463508c0ee27f6f9785 | |
parent | 8849b720e9632acef139a349f9ec62e63ce7e497 (diff) |
ipv4: Call fib_select_default() only when actually necessary.
fib_select_default() is a complete NOP, and completely pointless
to invoke, when we have no more than 1 default route installed.
And this is far and away the common case.
So remember how many prefixlen==0 routes we have in the routing
table, and elide the call when we have no more than one of those.
This cuts output route creation time by 157 cycles on Niagara2+.
In order to add the new int to fib_table, we have to correct the type
of ->tb_data[] to unsigned long, otherwise the private area will be
unaligned on 64-bit systems.
Signed-off-by: David S. Miller <davem@davemloft.net>
Reviewed-by: Eric Dumazet <eric.dumazet@gmail.com>
-rw-r--r-- | include/net/ip_fib.h | 3 | ||||
-rw-r--r-- | net/ipv4/fib_trie.c | 7 | ||||
-rw-r--r-- | net/ipv4/route.c | 4 |
3 files changed, 12 insertions, 2 deletions
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 514627f56339..10422ef14e28 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h | |||
@@ -160,7 +160,8 @@ struct fib_table { | |||
160 | struct hlist_node tb_hlist; | 160 | struct hlist_node tb_hlist; |
161 | u32 tb_id; | 161 | u32 tb_id; |
162 | int tb_default; | 162 | int tb_default; |
163 | unsigned char tb_data[0]; | 163 | int tb_num_default; |
164 | unsigned long tb_data[0]; | ||
164 | }; | 165 | }; |
165 | 166 | ||
166 | extern int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, | 167 | extern int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, |
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index bde80c450b52..9ac481a10d37 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c | |||
@@ -1332,6 +1332,9 @@ int fib_table_insert(struct fib_table *tb, struct fib_config *cfg) | |||
1332 | } | 1332 | } |
1333 | } | 1333 | } |
1334 | 1334 | ||
1335 | if (!plen) | ||
1336 | tb->tb_num_default++; | ||
1337 | |||
1335 | list_add_tail_rcu(&new_fa->fa_list, | 1338 | list_add_tail_rcu(&new_fa->fa_list, |
1336 | (fa ? &fa->fa_list : fa_head)); | 1339 | (fa ? &fa->fa_list : fa_head)); |
1337 | 1340 | ||
@@ -1697,6 +1700,9 @@ int fib_table_delete(struct fib_table *tb, struct fib_config *cfg) | |||
1697 | 1700 | ||
1698 | list_del_rcu(&fa->fa_list); | 1701 | list_del_rcu(&fa->fa_list); |
1699 | 1702 | ||
1703 | if (!plen) | ||
1704 | tb->tb_num_default--; | ||
1705 | |||
1700 | if (list_empty(fa_head)) { | 1706 | if (list_empty(fa_head)) { |
1701 | hlist_del_rcu(&li->hlist); | 1707 | hlist_del_rcu(&li->hlist); |
1702 | free_leaf_info(li); | 1708 | free_leaf_info(li); |
@@ -1987,6 +1993,7 @@ struct fib_table *fib_trie_table(u32 id) | |||
1987 | 1993 | ||
1988 | tb->tb_id = id; | 1994 | tb->tb_id = id; |
1989 | tb->tb_default = -1; | 1995 | tb->tb_default = -1; |
1996 | tb->tb_num_default = 0; | ||
1990 | 1997 | ||
1991 | t = (struct trie *) tb->tb_data; | 1998 | t = (struct trie *) tb->tb_data; |
1992 | memset(t, 0, sizeof(*t)); | 1999 | memset(t, 0, sizeof(*t)); |
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 0e7430c327a7..e9aee81de3e3 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -2615,7 +2615,9 @@ static struct rtable *ip_route_output_slow(struct net *net, | |||
2615 | fib_select_multipath(&res); | 2615 | fib_select_multipath(&res); |
2616 | else | 2616 | else |
2617 | #endif | 2617 | #endif |
2618 | if (!res.prefixlen && res.type == RTN_UNICAST && !fl4.flowi4_oif) | 2618 | if (!res.prefixlen && |
2619 | res.table->tb_num_default > 1 && | ||
2620 | res.type == RTN_UNICAST && !fl4.flowi4_oif) | ||
2619 | fib_select_default(&res); | 2621 | fib_select_default(&res); |
2620 | 2622 | ||
2621 | if (!fl4.saddr) | 2623 | if (!fl4.saddr) |