kernel: backport fib_trie improvements/fixes from 4.0-rc
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.18 / 080-17-fib_trie-Remove-checks-for-index-tnode_child_length-.patch
1 From: Alexander Duyck <alexander.h.duyck@redhat.com>
2 Date: Wed, 31 Dec 2014 10:57:02 -0800
3 Subject: [PATCH] fib_trie: Remove checks for index >= tnode_child_length
4 from tnode_get_child
5
6 For some reason the compiler doesn't seem to understand that when we are in
7 a loop that runs from tnode_child_length - 1 to 0 we don't expect the value
8 of tn->bits to change. As such every call to tnode_get_child was rerunning
9 tnode_chile_length which ended up consuming quite a bit of space in the
10 resultant assembly code.
11
12 I have gone though and verified that in all cases where tnode_get_child
13 is used we are either winding though a fixed loop from tnode_child_length -
14 1 to 0, or are in a fastpath case where we are verifying the value by
15 either checking for any remaining bits after shifting index by bits and
16 testing for leaf, or by using tnode_child_length.
17
18 size net/ipv4/fib_trie.o
19 Before:
20 text data bss dec hex filename
21 15506 376 8 15890 3e12 net/ipv4/fib_trie.o
22
23 After:
24 text data bss dec hex filename
25 14827 376 8 15211 3b6b net/ipv4/fib_trie.o
26
27 Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
28 Signed-off-by: David S. Miller <davem@davemloft.net>
29 ---
30
31 --- a/net/ipv4/fib_trie.c
32 +++ b/net/ipv4/fib_trie.c
33 @@ -186,8 +186,6 @@ static inline unsigned long tnode_child_
34 static inline struct tnode *tnode_get_child(const struct tnode *tn,
35 unsigned long i)
36 {
37 - BUG_ON(i >= tnode_child_length(tn));
38 -
39 return rtnl_dereference(tn->child[i]);
40 }
41
42 @@ -195,8 +193,6 @@ static inline struct tnode *tnode_get_ch
43 static inline struct tnode *tnode_get_child_rcu(const struct tnode *tn,
44 unsigned long i)
45 {
46 - BUG_ON(i >= tnode_child_length(tn));
47 -
48 return rcu_dereference_rtnl(tn->child[i]);
49 }
50
51 @@ -371,7 +367,7 @@ static inline int tnode_full(const struc
52 */
53 static void put_child(struct tnode *tn, unsigned long i, struct tnode *n)
54 {
55 - struct tnode *chi = rtnl_dereference(tn->child[i]);
56 + struct tnode *chi = tnode_get_child(tn, i);
57 int isfull, wasfull;
58
59 BUG_ON(i >= tnode_child_length(tn));
60 @@ -867,7 +863,7 @@ static struct tnode *fib_find_node(struc
61 if (IS_LEAF(n))
62 break;
63
64 - n = rcu_dereference_rtnl(n->child[index]);
65 + n = tnode_get_child_rcu(n, index);
66 }
67
68 return n;
69 @@ -934,7 +930,7 @@ static struct list_head *fib_insert_node
70 }
71
72 tp = n;
73 - n = rcu_dereference_rtnl(n->child[index]);
74 + n = tnode_get_child_rcu(n, index);
75 }
76
77 l = leaf_new(key);
78 @@ -1215,7 +1211,7 @@ int fib_table_lookup(struct fib_table *t
79 cindex = index;
80 }
81
82 - n = rcu_dereference(n->child[index]);
83 + n = tnode_get_child_rcu(n, index);
84 if (unlikely(!n))
85 goto backtrace;
86 }
87 @@ -1835,7 +1831,7 @@ static void trie_collect_stats(struct tr
88 if (n->bits < MAX_STAT_DEPTH)
89 s->nodesizes[n->bits]++;
90
91 - for (i = 0; i < tnode_child_length(n); i++) {
92 + for (i = tnode_child_length(n); i--;) {
93 if (!rcu_access_pointer(n->child[i]))
94 s->nullpointers++;
95 }