fib_trie: Add tnode struct as a container for fields not needed in key_vector
This change pulls the fields not explicitly needed in the key_vector and placed them in the new tnode structure. By doing this we will eventually be able to reduce the key_vector down to 16 bytes on 64 bit systems, and 12 bytes on 32 bit systems. Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
2e1ac88a48
Коммит
dc35dbeda3
|
@ -111,7 +111,11 @@ struct key_vector {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TNODE_SIZE(n) offsetof(struct key_vector, tnode[n])
|
struct tnode {
|
||||||
|
struct key_vector kv[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TNODE_SIZE(n) offsetof(struct tnode, kv[0].tnode[n])
|
||||||
#define LEAF_SIZE TNODE_SIZE(1)
|
#define LEAF_SIZE TNODE_SIZE(1)
|
||||||
|
|
||||||
#ifdef CONFIG_IP_FIB_TRIE_STATS
|
#ifdef CONFIG_IP_FIB_TRIE_STATS
|
||||||
|
@ -288,7 +292,7 @@ static void __node_free_rcu(struct rcu_head *head)
|
||||||
|
|
||||||
#define node_free(n) call_rcu(&n->rcu, __node_free_rcu)
|
#define node_free(n) call_rcu(&n->rcu, __node_free_rcu)
|
||||||
|
|
||||||
static struct key_vector *tnode_alloc(int bits)
|
static struct tnode *tnode_alloc(int bits)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
|
@ -317,48 +321,50 @@ static inline void empty_child_dec(struct key_vector *n)
|
||||||
|
|
||||||
static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
|
static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
|
||||||
{
|
{
|
||||||
struct key_vector *l = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
|
struct tnode *kv = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
|
||||||
if (l) {
|
struct key_vector *l = kv->kv;
|
||||||
l->parent = NULL;
|
|
||||||
/* set key and pos to reflect full key value
|
if (!kv)
|
||||||
* any trailing zeros in the key should be ignored
|
return NULL;
|
||||||
* as the nodes are searched
|
|
||||||
*/
|
/* initialize key vector */
|
||||||
l->key = key;
|
l->key = key;
|
||||||
l->slen = fa->fa_slen;
|
|
||||||
l->pos = 0;
|
l->pos = 0;
|
||||||
/* set bits to 0 indicating we are not a tnode */
|
|
||||||
l->bits = 0;
|
l->bits = 0;
|
||||||
|
l->slen = fa->fa_slen;
|
||||||
|
|
||||||
/* link leaf to fib alias */
|
/* link leaf to fib alias */
|
||||||
INIT_HLIST_HEAD(&l->leaf);
|
INIT_HLIST_HEAD(&l->leaf);
|
||||||
hlist_add_head(&fa->fa_list, &l->leaf);
|
hlist_add_head(&fa->fa_list, &l->leaf);
|
||||||
}
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct key_vector *tnode_new(t_key key, int pos, int bits)
|
static struct key_vector *tnode_new(t_key key, int pos, int bits)
|
||||||
{
|
{
|
||||||
struct key_vector *tn = tnode_alloc(bits);
|
struct tnode *tnode = tnode_alloc(bits);
|
||||||
unsigned int shift = pos + bits;
|
unsigned int shift = pos + bits;
|
||||||
|
struct key_vector *tn = tnode->kv;
|
||||||
|
|
||||||
/* verify bits and pos their msb bits clear and values are valid */
|
/* verify bits and pos their msb bits clear and values are valid */
|
||||||
BUG_ON(!bits || (shift > KEYLENGTH));
|
BUG_ON(!bits || (shift > KEYLENGTH));
|
||||||
|
|
||||||
if (tn) {
|
pr_debug("AT %p s=%zu %zu\n", tnode, TNODE_SIZE(0),
|
||||||
tn->parent = NULL;
|
sizeof(struct key_vector *) << bits);
|
||||||
tn->slen = pos;
|
|
||||||
tn->pos = pos;
|
if (!tnode)
|
||||||
tn->bits = bits;
|
return NULL;
|
||||||
tn->key = (shift < KEYLENGTH) ? (key >> shift) << shift : 0;
|
|
||||||
if (bits == KEYLENGTH)
|
if (bits == KEYLENGTH)
|
||||||
tn->full_children = 1;
|
tn->full_children = 1;
|
||||||
else
|
else
|
||||||
tn->empty_children = 1ul << bits;
|
tn->empty_children = 1ul << bits;
|
||||||
}
|
|
||||||
|
|
||||||
pr_debug("AT %p s=%zu %zu\n", tn, TNODE_SIZE(0),
|
tn->key = (shift < KEYLENGTH) ? (key >> shift) << shift : 0;
|
||||||
sizeof(struct key_vector *) << bits);
|
tn->pos = pos;
|
||||||
|
tn->bits = bits;
|
||||||
|
tn->slen = pos;
|
||||||
|
|
||||||
return tn;
|
return tn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче