Skip to content

Commit 6e22d17

Browse files
Alexander Duyckdavem330
authored andcommitted
fib_trie: Pull empty_children and full_children into tnode
This pulls the information about the child array out of the key_vector and places it in the tnode since that is where it is needed. Signed-off-by: Alexander Duyck <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 56ca2ad commit 6e22d17

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

net/ipv4/fib_trie.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ typedef unsigned int t_key;
9393
#define IS_LEAF(n) (!(n)->bits)
9494

9595
struct key_vector {
96-
t_key empty_children; /* KEYLENGTH bits needed */
97-
t_key full_children; /* KEYLENGTH bits needed */
9896
struct key_vector __rcu *parent;
9997

10098
t_key key;
@@ -111,6 +109,8 @@ struct key_vector {
111109

112110
struct tnode {
113111
struct rcu_head rcu;
112+
t_key empty_children; /* KEYLENGTH bits needed */
113+
t_key full_children; /* KEYLENGTH bits needed */
114114
struct key_vector kv[1];
115115
#define tn_bits kv[0].bits
116116
};
@@ -309,12 +309,12 @@ static struct tnode *tnode_alloc(int bits)
309309

310310
static inline void empty_child_inc(struct key_vector *n)
311311
{
312-
++n->empty_children ? : ++n->full_children;
312+
++tn_info(n)->empty_children ? : ++tn_info(n)->full_children;
313313
}
314314

315315
static inline void empty_child_dec(struct key_vector *n)
316316
{
317-
n->empty_children-- ? : n->full_children--;
317+
tn_info(n)->empty_children-- ? : tn_info(n)->full_children--;
318318
}
319319

320320
static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
@@ -354,9 +354,9 @@ static struct key_vector *tnode_new(t_key key, int pos, int bits)
354354
return NULL;
355355

356356
if (bits == KEYLENGTH)
357-
tn->full_children = 1;
357+
tnode->full_children = 1;
358358
else
359-
tn->empty_children = 1ul << bits;
359+
tnode->empty_children = 1ul << bits;
360360

361361
tn->key = (shift < KEYLENGTH) ? (key >> shift) << shift : 0;
362362
tn->pos = pos;
@@ -396,9 +396,9 @@ static void put_child(struct key_vector *tn, unsigned long i,
396396
isfull = tnode_full(tn, n);
397397

398398
if (wasfull && !isfull)
399-
tn->full_children--;
399+
tn_info(tn)->full_children--;
400400
else if (!wasfull && isfull)
401-
tn->full_children++;
401+
tn_info(tn)->full_children++;
402402

403403
if (n && (tn->slen < n->slen))
404404
tn->slen = n->slen;
@@ -768,8 +768,8 @@ static inline bool should_inflate(struct key_vector *tp, struct key_vector *tn)
768768

769769
/* Keep root node larger */
770770
threshold *= tp ? inflate_threshold : inflate_threshold_root;
771-
used -= tn->empty_children;
772-
used += tn->full_children;
771+
used -= tn_info(tn)->empty_children;
772+
used += tn_info(tn)->full_children;
773773

774774
/* if bits == KEYLENGTH then pos = 0, and will fail below */
775775

@@ -783,7 +783,7 @@ static inline bool should_halve(struct key_vector *tp, struct key_vector *tn)
783783

784784
/* Keep root node larger */
785785
threshold *= tp ? halve_threshold : halve_threshold_root;
786-
used -= tn->empty_children;
786+
used -= tn_info(tn)->empty_children;
787787

788788
/* if bits == KEYLENGTH then used = 100% on wrap, and will fail below */
789789

@@ -794,10 +794,10 @@ static inline bool should_collapse(struct key_vector *tn)
794794
{
795795
unsigned long used = child_length(tn);
796796

797-
used -= tn->empty_children;
797+
used -= tn_info(tn)->empty_children;
798798

799799
/* account for bits == KEYLENGTH case */
800-
if ((tn->bits == KEYLENGTH) && tn->full_children)
800+
if ((tn->bits == KEYLENGTH) && tn_info(tn)->full_children)
801801
used -= KEY_MAX;
802802

803803
/* One child or none, time to drop us from the trie */
@@ -1963,7 +1963,7 @@ static void trie_collect_stats(struct trie *t, struct trie_stat *s)
19631963
s->tnodes++;
19641964
if (n->bits < MAX_STAT_DEPTH)
19651965
s->nodesizes[n->bits]++;
1966-
s->nullpointers += n->empty_children;
1966+
s->nullpointers += tn_info(n)->empty_children;
19671967
}
19681968
}
19691969
rcu_read_unlock();
@@ -2238,7 +2238,8 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v)
22382238
seq_indent(seq, iter->depth-1);
22392239
seq_printf(seq, " +-- %pI4/%zu %u %u %u\n",
22402240
&prf, KEYLENGTH - n->pos - n->bits, n->bits,
2241-
n->full_children, n->empty_children);
2241+
tn_info(n)->full_children,
2242+
tn_info(n)->empty_children);
22422243
} else {
22432244
__be32 val = htonl(n->key);
22442245
struct fib_alias *fa;

0 commit comments

Comments
 (0)