Skip to content

Commit dc35dbe

Browse files
Alexander Duyckdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2e1ac88 commit dc35dbe

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

net/ipv4/fib_trie.c

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ struct key_vector {
111111
};
112112
};
113113

114-
#define TNODE_SIZE(n) offsetof(struct key_vector, tnode[n])
114+
struct tnode {
115+
struct key_vector kv[1];
116+
};
117+
118+
#define TNODE_SIZE(n) offsetof(struct tnode, kv[0].tnode[n])
115119
#define LEAF_SIZE TNODE_SIZE(1)
116120

117121
#ifdef CONFIG_IP_FIB_TRIE_STATS
@@ -288,7 +292,7 @@ static void __node_free_rcu(struct rcu_head *head)
288292

289293
#define node_free(n) call_rcu(&n->rcu, __node_free_rcu)
290294

291-
static struct key_vector *tnode_alloc(int bits)
295+
static struct tnode *tnode_alloc(int bits)
292296
{
293297
size_t size;
294298

@@ -317,48 +321,50 @@ static inline void empty_child_dec(struct key_vector *n)
317321

318322
static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
319323
{
320-
struct key_vector *l = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
321-
if (l) {
322-
l->parent = NULL;
323-
/* set key and pos to reflect full key value
324-
* any trailing zeros in the key should be ignored
325-
* as the nodes are searched
326-
*/
327-
l->key = key;
328-
l->slen = fa->fa_slen;
329-
l->pos = 0;
330-
/* set bits to 0 indicating we are not a tnode */
331-
l->bits = 0;
332-
333-
/* link leaf to fib alias */
334-
INIT_HLIST_HEAD(&l->leaf);
335-
hlist_add_head(&fa->fa_list, &l->leaf);
336-
}
324+
struct tnode *kv = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
325+
struct key_vector *l = kv->kv;
326+
327+
if (!kv)
328+
return NULL;
329+
330+
/* initialize key vector */
331+
l->key = key;
332+
l->pos = 0;
333+
l->bits = 0;
334+
l->slen = fa->fa_slen;
335+
336+
/* link leaf to fib alias */
337+
INIT_HLIST_HEAD(&l->leaf);
338+
hlist_add_head(&fa->fa_list, &l->leaf);
339+
337340
return l;
338341
}
339342

340343
static struct key_vector *tnode_new(t_key key, int pos, int bits)
341344
{
342-
struct key_vector *tn = tnode_alloc(bits);
345+
struct tnode *tnode = tnode_alloc(bits);
343346
unsigned int shift = pos + bits;
347+
struct key_vector *tn = tnode->kv;
344348

345349
/* verify bits and pos their msb bits clear and values are valid */
346350
BUG_ON(!bits || (shift > KEYLENGTH));
347351

348-
if (tn) {
349-
tn->parent = NULL;
350-
tn->slen = pos;
351-
tn->pos = pos;
352-
tn->bits = bits;
353-
tn->key = (shift < KEYLENGTH) ? (key >> shift) << shift : 0;
354-
if (bits == KEYLENGTH)
355-
tn->full_children = 1;
356-
else
357-
tn->empty_children = 1ul << bits;
358-
}
359-
360-
pr_debug("AT %p s=%zu %zu\n", tn, TNODE_SIZE(0),
352+
pr_debug("AT %p s=%zu %zu\n", tnode, TNODE_SIZE(0),
361353
sizeof(struct key_vector *) << bits);
354+
355+
if (!tnode)
356+
return NULL;
357+
358+
if (bits == KEYLENGTH)
359+
tn->full_children = 1;
360+
else
361+
tn->empty_children = 1ul << bits;
362+
363+
tn->key = (shift < KEYLENGTH) ? (key >> shift) << shift : 0;
364+
tn->pos = pos;
365+
tn->bits = bits;
366+
tn->slen = pos;
367+
362368
return tn;
363369
}
364370

0 commit comments

Comments
 (0)