netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Olsson <Robert.Olsson@data.slu.se>
To: Stephen Hemminger <stephen.hemminger@vyatta.com>
Cc: Eric Dumazet <dada1@cosmosbay.com>,
	David Miller <davem@davemloft.net>,
	robert.olsson@its.uu.se, netdev@vger.kernel.org
Subject: Re: [RFC 6/6] fib_trie: combine leaf and info
Date: Tue, 15 Jan 2008 17:44:47 +0100	[thread overview]
Message-ID: <18316.58111.211387.271534@robur.slu.se> (raw)
In-Reply-To: <20080115081905.3b8b6f05@deepthought>


Stephen Hemminger writes:

 > Okay, I would rather see the leaf_info explicit inside the leaf, also
 > your scheme probably breaks if I add two prefixes and then delete the first.
 > Let me have a go at it.

 I took Eric's patch a bit further... 
 
 Support for delete and dump is needed before any testing at all
 and maybe some macro for checking and setting FP-leaf's

 Cheers.
					--ro


diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 6dab753..f5b276c 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -97,22 +97,32 @@ typedef unsigned int t_key;
 #define IS_LEAF(n) (n->parent & T_LEAF)
 
 struct node {
-	unsigned long parent;
-	t_key key;
+	unsigned long		parent;
+	t_key			key;
 };
 
 struct leaf {
-	unsigned long parent;
-	t_key key;
-	struct hlist_head list;
-	struct rcu_head rcu;
+	unsigned long		parent;
+	t_key			key;
+	/*
+	 * Because we often have only one info per leaf, we embedd one here
+	 * to save some space and speedup lookups (sharing cache line)
+	 * a sort of fastpatch leaf (FP-leaf) this indicated a negative of
+	 * plen_iinfo.
+	 * Note : not inside a structure so that we dont have holes on 64bit 
+	 */
+	int 			plen_iinfo;
+	struct list_head	falh_iinfo;
+
+	struct hlist_head	list;
+	struct rcu_head		rcu;
 };
 
 struct leaf_info {
-	struct hlist_node hlist;
-	struct rcu_head rcu;
-	int plen;
-	struct list_head falh;
+	struct hlist_node	hlist;
+	int			plen;
+	struct list_head	falh;
+	struct rcu_head		rcu;
 };
 
 struct tnode {
@@ -364,11 +374,13 @@ static inline void tnode_free(struct tnode *tn)
 		call_rcu(&tn->rcu, __tnode_free_rcu);
 }
 
-static struct leaf *leaf_new(void)
+static struct leaf *leaf_new(int plen)
 {
 	struct leaf *l = kmalloc(sizeof(struct leaf),  GFP_KERNEL);
 	if (l) {
 		l->parent = T_LEAF;
+		l->plen_iinfo = plen;
+		INIT_LIST_HEAD(&l->falh_iinfo);
 		INIT_HLIST_HEAD(&l->list);
 	}
 	return l;
@@ -890,7 +902,16 @@ static struct leaf_info *find_leaf_info(struct leaf *l, int plen)
 
 static inline struct list_head * get_fa_head(struct leaf *l, int plen)
 {
-	struct leaf_info *li = find_leaf_info(l, plen);
+	struct leaf_info *li;
+
+	if (l->plen_iinfo >= 0) {
+		if(l->plen_iinfo == plen)
+			return &l->falh_iinfo;
+		else
+			return NULL;
+	}
+
+	li = find_leaf_info(l, plen);
 
 	if (!li)
 		return NULL;
@@ -1036,6 +1057,21 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)
 
 	if (n != NULL && IS_LEAF(n) && tkey_equals(key, n->key)) {
 		l = (struct leaf *) n;
+
+		/* 
+		 * Check if it is a FP-leaf if so we have to convert 
+		 * it to an ordinary leaf with leaf_infos
+		 */
+
+		if( l->plen_iinfo >= 0 ) {
+			li = leaf_info_new(l->plen_iinfo);
+			if (!li)
+				return NULL;
+
+			insert_leaf_info(&l->list, li);
+			l->plen_iinfo = -1;
+		}
+
 		li = leaf_info_new(plen);
 
 		if (!li)
@@ -1045,21 +1081,16 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)
 		insert_leaf_info(&l->list, li);
 		goto done;
 	}
-	l = leaf_new();
+
+	/* Insert a FP-leaf */
+	l = leaf_new(plen);
 
 	if (!l)
 		return NULL;
 
 	l->key = key;
-	li = leaf_info_new(plen);
-
-	if (!li) {
-		tnode_free((struct tnode *) l);
-		return NULL;
-	}
+	fa_head = &l->falh_iinfo;
 
-	fa_head = &li->falh;
-	insert_leaf_info(&l->list, li);
 
 	if (t->trie && n == NULL) {
 		/* Case 2: n is NULL, and will just insert a new leaf */
@@ -1089,7 +1120,6 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)
 		}
 
 		if (!tn) {
-			free_leaf_info(li);
 			tnode_free((struct tnode *) l);
 			return NULL;
 		}
@@ -1285,6 +1315,20 @@ static inline int check_leaf(struct trie *t, struct leaf *l,
 	struct hlist_head *hhead = &l->list;
 	struct hlist_node *node;
 
+	i = l->plen_iinfo;	
+	if( i >= 0) {   /* FP-leaf */
+		mask = inet_make_mask(i);
+		err = fib_semantic_match(&l->falh_iinfo, flp, res, htonl(l->key), mask, i);
+		if(err <= 0 ) {
+			*plen = i;
+#ifdef CONFIG_IP_FIB_TRIE_STATS
+			t->stats.semantic_match_passed++;
+#endif
+		return err;
+		}
+	}
+
+
 	hlist_for_each_entry_rcu(li, node, hhead, hlist) {
 		i = li->plen;
 		mask = inet_make_mask(i);
@@ -1614,7 +1658,7 @@ static int fn_trie_delete(struct fib_table *tb, struct fib_config *cfg)
 	li = find_leaf_info(l, plen);
 
 	list_del_rcu(&fa->fa_list);
-
+// FIXME
 	if (list_empty(fa_head)) {
 		hlist_del_rcu(&li->hlist);
 		free_leaf_info(li);
@@ -2336,12 +2380,11 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v)
 		seq_indent(seq, iter->depth);
 		seq_printf(seq, "  |-- %d.%d.%d.%d\n", NIPQUAD(val));
 		for (i = 32; i >= 0; i--) {
-			struct leaf_info *li = find_leaf_info(l, i);
+			struct list_head *fa_head = get_fa_head(l, i);
+			if (fa_head) {
 
-			if (li) {
 				struct fib_alias *fa;
-
-				list_for_each_entry_rcu(fa, &li->falh, fa_list) {
+				list_for_each_entry_rcu(fa, fa_head, fa_list) {
 					char buf1[32], buf2[32];
 
 					seq_indent(seq, iter->depth+1);
@@ -2424,17 +2467,18 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
 		return 0;
 
 	for (i=32; i>=0; i--) {
-		struct leaf_info *li = find_leaf_info(l, i);
+		//struct leaf_info *li = find_leaf_info(l, i);
+		struct list_head *fa_head = get_fa_head(l, i);
 		struct fib_alias *fa;
 		__be32 mask, prefix;
 
-		if (!li)
+		if (!fa_head)
 			continue;
 
-		mask = inet_make_mask(li->plen);
+		mask = inet_make_mask(i);
 		prefix = htonl(l->key);
 
-		list_for_each_entry_rcu(fa, &li->falh, fa_list) {
+		list_for_each_entry_rcu(fa, fa_head, fa_list) {
 			const struct fib_info *fi = fa->fa_info;
 			unsigned flags = fib_flag_trans(fa->fa_type, mask, fi);
 

  reply	other threads:[~2008-01-15 16:45 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 [this message]
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           ` [PATCH] [IPV4] fib_trie: size and statistics Eric Dumazet
2008-01-15  7:28             ` 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=18316.58111.211387.271534@robur.slu.se \
    --to=robert.olsson@data.slu.se \
    --cc=dada1@cosmosbay.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=robert.olsson@its.uu.se \
    --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).