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
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.
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.
18 size net/ipv4/fib_trie.o
20 text data bss dec hex filename
21 15506 376 8 15890 3e12 net/ipv4/fib_trie.o
24 text data bss dec hex filename
25 14827 376 8 15211 3b6b net/ipv4/fib_trie.o
27 Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
28 Signed-off-by: David S. Miller <davem@davemloft.net>
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,
37 - BUG_ON(i >= tnode_child_length(tn));
39 return rtnl_dereference(tn->child[i]);
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,
46 - BUG_ON(i >= tnode_child_length(tn));
48 return rcu_dereference_rtnl(tn->child[i]);
51 @@ -371,7 +367,7 @@ static inline int tnode_full(const struc
53 static void put_child(struct tnode *tn, unsigned long i, struct tnode *n)
55 - struct tnode *chi = rtnl_dereference(tn->child[i]);
56 + struct tnode *chi = tnode_get_child(tn, i);
59 BUG_ON(i >= tnode_child_length(tn));
60 @@ -867,7 +863,7 @@ static struct tnode *fib_find_node(struc
64 - n = rcu_dereference_rtnl(n->child[index]);
65 + n = tnode_get_child_rcu(n, index);
69 @@ -934,7 +930,7 @@ static struct list_head *fib_insert_node
73 - n = rcu_dereference_rtnl(n->child[index]);
74 + n = tnode_get_child_rcu(n, index);
78 @@ -1215,7 +1211,7 @@ int fib_table_lookup(struct fib_table *t
82 - n = rcu_dereference(n->child[index]);
83 + n = tnode_get_child_rcu(n, index);
87 @@ -1835,7 +1831,7 @@ static void trie_collect_stats(struct tr
88 if (n->bits < MAX_STAT_DEPTH)
89 s->nodesizes[n->bits]++;
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]))