From: Eric Dumazet <dada1@cosmosbay.com>
To: Stephen Hemminger <shemminger@linux-foundation.org>
Cc: David Miller <davem@davemloft.net>,
robert.olsson@its.uu.se, netdev@vger.kernel.org,
stephen.hemminger@vyatta.com
Subject: Re: [PATCH] [IPV4] fib_trie: size and statistics
Date: Tue, 15 Jan 2008 07:55:57 +0100 [thread overview]
Message-ID: <478C58FD.9030407@cosmosbay.com> (raw)
In-Reply-To: <20080114125755.6157a3bf@deepthought>
Stephen Hemminger a écrit :
> 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>
> ---
> Patch against current net-2.6.25
>
> --- a/net/ipv4/fib_trie.c 2008-01-14 10:16:06.000000000 -0800
> +++ b/net/ipv4/fib_trie.c 2008-01-14 10:30:11.000000000 -0800
> @@ -148,10 +148,10 @@ struct trie_stat {
>
> struct trie {
> struct node *trie;
> + unsigned int size;
> #ifdef CONFIG_IP_FIB_TRIE_STATS
> struct trie_use_stats stats;
> #endif
> - int size;
> };
>
> static 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
> insert_leaf_info(&l->list, li);
> goto done;
> }
> - t->size++;
> l = leaf_new();
>
> if (!l)
> @@ -1258,6 +1257,8 @@ static int fn_trie_insert(struct fib_tab
> list_add_tail_rcu(&new_fa->fa_list,
> (fa ? &fa->fa_list : fa_head));
>
> + t->size++;
> +
> rt_cache_flush(-1);
> rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id,
> &cfg->fc_nlinfo, 0);
> @@ -2128,50 +2129,34 @@ static void trie_show_usage(struct seq_f
> }
> #endif /* CONFIG_IP_FIB_TRIE_STATS */
>
> +static void fib_trie_show(struct seq_file *seq, const char *name, struct trie *trie)
> +{
> + struct trie_stat stat;
> +
> + seq_printf(seq, "%s: %d\n", name, trie->size);
> + trie_collect_stats(trie, &stat);
> + trie_show_stats(seq, &stat);
> +#ifdef CONFIG_IP_FIB_TRIE_STATS
> + trie_show_usage(seq, &trie->stats);
> +#endif
> +}
>
> static int fib_triestat_seq_show(struct seq_file *seq, void *v)
> {
> struct net *net = (struct net *)seq->private;
> - struct trie *trie_local, *trie_main;
> - struct trie_stat *stat;
> struct fib_table *tb;
>
> - trie_local = NULL;
> + seq_printf(seq,
> + "Basic info: size of leaf: %Zd bytes, size of tnode: %Zd bytes.\n",
> + sizeof(struct leaf), sizeof(struct tnode));
> +
> tb = fib_get_table(net, RT_TABLE_LOCAL);
> if (tb)
> - trie_local = (struct trie *) tb->tb_data;
> -
> - trie_main = NULL;
> + fib_trie_show(seq, "Local", (struct trie *) tb->tb_data);
> +
> tb = fib_get_table(net, RT_TABLE_MAIN);
> if (tb)
> - trie_main = (struct trie *) tb->tb_data;
> -
> -
> - stat = kmalloc(sizeof(*stat), GFP_KERNEL);
> - if (!stat)
> - return -ENOMEM;
> -
> - seq_printf(seq, "Basic info: size of leaf: %Zd bytes, size of tnode: %Zd bytes.\n",
> - sizeof(struct leaf), sizeof(struct tnode));
> -
> - if (trie_local) {
> - seq_printf(seq, "Local:\n");
> - trie_collect_stats(trie_local, stat);
> - trie_show_stats(seq, stat);
> -#ifdef CONFIG_IP_FIB_TRIE_STATS
> - trie_show_usage(seq, &trie_local->stats);
> -#endif
> - }
> -
> - if (trie_main) {
> - seq_printf(seq, "Main:\n");
> - trie_collect_stats(trie_main, stat);
> - trie_show_stats(seq, stat);
> -#ifdef CONFIG_IP_FIB_TRIE_STATS
> - trie_show_usage(seq, &trie_main->stats);
> -#endif
> - }
> - kfree(stat);
> + fib_trie_show(seq, "Main", (struct trie *) tb->tb_data);
>
> return 0;
> }
Keeping a 'size' counter is not necessary, since trie_collect_stats() must go
through all the tree and get this information for free.
This 'size' field only slows down inserts/deletes and dirty a cacheline that
readers will hit.
next prev parent reply other threads:[~2008-01-15 6:56 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20080112064513.803976049@linux-foundation.org>
[not found] ` <20080112064646.659443238@linux-foundation.org>
2008-01-12 11:16 ` [PATCH 9/9] fix sparse warnings Eric Dumazet
2008-01-12 11:28 ` David Miller
2008-01-12 21:08 ` Stephen Hemminger
2008-01-14 11:07 ` Robert Olsson
2008-01-14 17:34 ` Eric Dumazet
2008-01-14 17:59 ` Robert Olsson
2008-01-14 19:27 ` [FIB]: Avoid using static variables without proper locking Eric Dumazet
2008-01-15 7:10 ` David Miller
2008-01-12 21:09 ` [PATCH 9/9] fix sparse warnings Stephen Hemminger
2008-01-13 5:28 ` David Miller
2008-01-13 18:30 ` [FIB]: full_children & empty_children should be uint, not ushort Eric Dumazet
2008-01-13 22:02 ` Robert Olsson
2008-01-14 6:32 ` David Miller
2008-01-13 5:25 ` [PATCH 9/9] fix sparse warnings David Miller
[not found] ` <20080112064646.056241123@linux-foundation.org>
2008-01-13 4:49 ` [PATCH 1/9] get rid of trie_init David Miller
[not found] ` <20080112064646.132747871@linux-foundation.org>
2008-01-13 4:50 ` [PATCH 2/9] get rid of unused revision element David Miller
2008-01-14 11:44 ` Robert Olsson
2008-01-14 12:06 ` David Miller
2008-01-14 16:35 ` Stephen Hemminger
2008-01-15 7:07 ` David Miller
[not found] ` <20080112064646.207183428@linux-foundation.org>
2008-01-13 4:53 ` [PATCH 3/9] move size information to pr_debug() David Miller
[not found] ` <20080112064646.282104074@linux-foundation.org>
2008-01-13 4:55 ` [PATCH 4/9] statistics improvements David Miller
2008-01-13 5:33 ` Stephen Hemminger
2008-01-13 5:44 ` David Miller
2008-01-14 20:57 ` [PATCH] [IPV4] fib_trie: size and statistics Stephen Hemminger
[not found] ` <20080114164450.55f8c9b2@deepthought>
2008-01-15 0:46 ` [PATCH 3/6] [IPV4] trie: put leaf nodes in a slab cache Stephen Hemminger
2008-01-15 0:47 ` [PATCH 4/6] [IPV4] fib_trie style cleanup Stephen Hemminger
2008-01-15 2:58 ` [PATCH 5/6] [IPV4] fib_trie: checkleaf calling convention Stephen Hemminger
2008-01-15 5:07 ` [RFC 6/6] fib_trie: combine leaf and info Stephen Hemminger
2008-01-15 6:12 ` Eric Dumazet
2008-01-15 6:16 ` Eric Dumazet
2008-01-15 16:19 ` Stephen Hemminger
2008-01-15 16:44 ` Robert Olsson
2008-01-15 17:25 ` Eric Dumazet
2008-01-15 17:47 ` Stephen Hemminger
2008-01-15 18:10 ` Eric Dumazet
2008-01-15 18:15 ` Stephen Hemminger
2008-01-15 18:32 ` Eric Dumazet
2008-01-15 20:18 ` Robert Olsson
2008-01-15 21:16 ` Eric Dumazet
2008-01-15 17:59 ` Robert Olsson
2008-01-15 6:49 ` [PATCH 3/6] [IPV4] trie: put leaf nodes in a slab cache Eric Dumazet
2008-01-15 7:29 ` David Miller
2008-01-15 5:00 ` [PATCH 2/6] [IPV4] fib hash|trie initialization Stephen Hemminger
2008-01-15 7:14 ` David Miller
2008-01-15 6:55 ` Eric Dumazet [this message]
2008-01-15 7:28 ` [PATCH] [IPV4] fib_trie: size and statistics David Miller
2008-01-15 7:12 ` David Miller
[not found] ` <20080112064646.356466158@linux-foundation.org>
2008-01-13 4:56 ` [PATCH 5/9] use %u for unsigned printfs David Miller
[not found] ` <20080112064646.432200237@linux-foundation.org>
2008-01-13 4:57 ` [PATCH 6/9] : fib_insert_node cleanup David Miller
[not found] ` <20080112064646.507015655@linux-foundation.org>
2008-01-13 4:58 ` [PATCH 7/9] printk related cleanups David Miller
[not found] ` <20080112064646.583836190@linux-foundation.org>
2008-01-13 5:23 ` [PATCH 8/9] add statistics David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=478C58FD.9030407@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=robert.olsson@its.uu.se \
--cc=shemminger@linux-foundation.org \
--cc=stephen.hemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).