aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-01-15 02:11:54 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:02:14 -0500
commitd717a9a62049a03e85c3c2dd3399416eeb34a8be (patch)
tree1b83623666eb232ac97586c5188304d76dbdbe59 /net/ipv4
parent28d36e3702fcbed73c38e877bcf2a8f8946b7f3d (diff)
[IPV4] fib_trie: size and statistics
Show number of entries in trie, the size field was being set but never used, but it only counted leaves, not all entries. Refactor the two cases in fib_triestat_seq_show into a single routine. Note: the stat structure was being malloc'd but the stack usage isn't so high (288 bytes) that it is worth the additional complexity. Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/fib_trie.c55
1 files changed, 20 insertions, 35 deletions
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 72c78c2209d5..a15cb0d2e113 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -148,10 +148,10 @@ struct trie_stat {
148 148
149struct trie { 149struct trie {
150 struct node *trie; 150 struct node *trie;
151 unsigned int size;
151#ifdef CONFIG_IP_FIB_TRIE_STATS 152#ifdef CONFIG_IP_FIB_TRIE_STATS
152 struct trie_use_stats stats; 153 struct trie_use_stats stats;
153#endif 154#endif
154 int size;
155}; 155};
156 156
157static void put_child(struct trie *t, struct tnode *tn, int i, struct node *n); 157static void put_child(struct trie *t, struct tnode *tn, int i, struct node *n);
@@ -1045,7 +1045,6 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)
1045 insert_leaf_info(&l->list, li); 1045 insert_leaf_info(&l->list, li);
1046 goto done; 1046 goto done;
1047 } 1047 }
1048 t->size++;
1049 l = leaf_new(); 1048 l = leaf_new();
1050 1049
1051 if (!l) 1050 if (!l)
@@ -1261,6 +1260,8 @@ static int fn_trie_insert(struct fib_table *tb, struct fib_config *cfg)
1261 list_add_tail_rcu(&new_fa->fa_list, 1260 list_add_tail_rcu(&new_fa->fa_list,
1262 (fa ? &fa->fa_list : fa_head)); 1261 (fa ? &fa->fa_list : fa_head));
1263 1262
1263 t->size++;
1264
1264 rt_cache_flush(-1); 1265 rt_cache_flush(-1);
1265 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id, 1266 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id,
1266 &cfg->fc_nlinfo, 0); 1267 &cfg->fc_nlinfo, 0);
@@ -2131,50 +2132,34 @@ static void trie_show_usage(struct seq_file *seq,
2131} 2132}
2132#endif /* CONFIG_IP_FIB_TRIE_STATS */ 2133#endif /* CONFIG_IP_FIB_TRIE_STATS */
2133 2134
2135static void fib_trie_show(struct seq_file *seq, const char *name, struct trie *trie)
2136{
2137 struct trie_stat stat;
2138
2139 seq_printf(seq, "%s: %d\n", name, trie->size);
2140 trie_collect_stats(trie, &stat);
2141 trie_show_stats(seq, &stat);
2142#ifdef CONFIG_IP_FIB_TRIE_STATS
2143 trie_show_usage(seq, &trie->stats);
2144#endif
2145}
2134 2146
2135static int fib_triestat_seq_show(struct seq_file *seq, void *v) 2147static int fib_triestat_seq_show(struct seq_file *seq, void *v)
2136{ 2148{
2137 struct net *net = (struct net *)seq->private; 2149 struct net *net = (struct net *)seq->private;
2138 struct trie *trie_local, *trie_main;
2139 struct trie_stat *stat;
2140 struct fib_table *tb; 2150 struct fib_table *tb;
2141 2151
2142 trie_local = NULL; 2152 seq_printf(seq,
2153 "Basic info: size of leaf: %Zd bytes, size of tnode: %Zd bytes.\n",
2154 sizeof(struct leaf), sizeof(struct tnode));
2155
2143 tb = fib_get_table(net, RT_TABLE_LOCAL); 2156 tb = fib_get_table(net, RT_TABLE_LOCAL);
2144 if (tb) 2157 if (tb)
2145 trie_local = (struct trie *) tb->tb_data; 2158 fib_trie_show(seq, "Local", (struct trie *) tb->tb_data);
2146 2159
2147 trie_main = NULL;
2148 tb = fib_get_table(net, RT_TABLE_MAIN); 2160 tb = fib_get_table(net, RT_TABLE_MAIN);
2149 if (tb) 2161 if (tb)
2150 trie_main = (struct trie *) tb->tb_data; 2162 fib_trie_show(seq, "Main", (struct trie *) tb->tb_data);
2151
2152
2153 stat = kmalloc(sizeof(*stat), GFP_KERNEL);
2154 if (!stat)
2155 return -ENOMEM;
2156
2157 seq_printf(seq, "Basic info: size of leaf: %Zd bytes, size of tnode: %Zd bytes.\n",
2158 sizeof(struct leaf), sizeof(struct tnode));
2159
2160 if (trie_local) {
2161 seq_printf(seq, "Local:\n");
2162 trie_collect_stats(trie_local, stat);
2163 trie_show_stats(seq, stat);
2164#ifdef CONFIG_IP_FIB_TRIE_STATS
2165 trie_show_usage(seq, &trie_local->stats);
2166#endif
2167 }
2168
2169 if (trie_main) {
2170 seq_printf(seq, "Main:\n");
2171 trie_collect_stats(trie_main, stat);
2172 trie_show_stats(seq, stat);
2173#ifdef CONFIG_IP_FIB_TRIE_STATS
2174 trie_show_usage(seq, &trie_main->stats);
2175#endif
2176 }
2177 kfree(stat);
2178 2163
2179 return 0; 2164 return 0;
2180} 2165}