@@ -93,8 +93,6 @@ typedef unsigned int t_key;
93
93
#define IS_LEAF (n ) (!(n)->bits)
94
94
95
95
struct key_vector {
96
- struct rcu_head rcu ;
97
-
98
96
t_key empty_children ; /* KEYLENGTH bits needed */
99
97
t_key full_children ; /* KEYLENGTH bits needed */
100
98
struct key_vector __rcu * parent ;
@@ -112,7 +110,9 @@ struct key_vector {
112
110
};
113
111
114
112
struct tnode {
113
+ struct rcu_head rcu ;
115
114
struct key_vector kv [1 ];
115
+ #define tn_bits kv[0].bits
116
116
};
117
117
118
118
#define TNODE_SIZE (n ) offsetof(struct tnode, kv[0].tnode[n])
@@ -159,6 +159,11 @@ static const int sync_pages = 128;
159
159
static struct kmem_cache * fn_alias_kmem __read_mostly ;
160
160
static struct kmem_cache * trie_leaf_kmem __read_mostly ;
161
161
162
+ static inline struct tnode * tn_info (struct key_vector * kv )
163
+ {
164
+ return container_of (kv , struct tnode , kv [0 ]);
165
+ }
166
+
162
167
/* caller must hold RTNL */
163
168
#define node_parent (n ) rtnl_dereference((n)->parent)
164
169
#define get_child (tn , i ) rtnl_dereference((tn)->tnode[i])
@@ -191,13 +196,6 @@ static inline unsigned long get_index(t_key key, struct key_vector *kv)
191
196
return index >> kv -> pos ;
192
197
}
193
198
194
- static inline struct fib_table * trie_get_table (struct trie * t )
195
- {
196
- unsigned long * tb_data = (unsigned long * )t ;
197
-
198
- return container_of (tb_data , struct fib_table , tb_data [0 ]);
199
- }
200
-
201
199
/* To understand this stuff, an understanding of keys and all their bits is
202
200
* necessary. Every node in the trie has a key associated with it, but not
203
201
* all of the bits in that key are significant.
@@ -280,17 +278,17 @@ static inline void alias_free_mem_rcu(struct fib_alias *fa)
280
278
281
279
static void __node_free_rcu (struct rcu_head * head )
282
280
{
283
- struct key_vector * n = container_of (head , struct key_vector , rcu );
281
+ struct tnode * n = container_of (head , struct tnode , rcu );
284
282
285
- if (IS_LEAF ( n ) )
283
+ if (! n -> tn_bits )
286
284
kmem_cache_free (trie_leaf_kmem , n );
287
- else if (n -> bits <= TNODE_KMALLOC_MAX )
285
+ else if (n -> tn_bits <= TNODE_KMALLOC_MAX )
288
286
kfree (n );
289
287
else
290
288
vfree (n );
291
289
}
292
290
293
- #define node_free (n ) call_rcu(&n ->rcu, __node_free_rcu)
291
+ #define node_free (n ) call_rcu(&tn_info(n) ->rcu, __node_free_rcu)
294
292
295
293
static struct tnode * tnode_alloc (int bits )
296
294
{
@@ -441,26 +439,26 @@ static inline void put_child_root(struct key_vector *tp, struct trie *t,
441
439
442
440
static inline void tnode_free_init (struct key_vector * tn )
443
441
{
444
- tn -> rcu .next = NULL ;
442
+ tn_info ( tn ) -> rcu .next = NULL ;
445
443
}
446
444
447
445
static inline void tnode_free_append (struct key_vector * tn ,
448
446
struct key_vector * n )
449
447
{
450
- n -> rcu .next = tn -> rcu .next ;
451
- tn -> rcu .next = & n -> rcu ;
448
+ tn_info ( n ) -> rcu .next = tn_info ( tn ) -> rcu .next ;
449
+ tn_info ( tn ) -> rcu .next = & tn_info ( n ) -> rcu ;
452
450
}
453
451
454
452
static void tnode_free (struct key_vector * tn )
455
453
{
456
- struct callback_head * head = & tn -> rcu ;
454
+ struct callback_head * head = & tn_info ( tn ) -> rcu ;
457
455
458
456
while (head ) {
459
457
head = head -> next ;
460
458
tnode_free_size += TNODE_SIZE (1ul << tn -> bits );
461
459
node_free (tn );
462
460
463
- tn = container_of (head , struct key_vector , rcu );
461
+ tn = container_of (head , struct tnode , rcu )-> kv ;
464
462
}
465
463
466
464
if (tnode_free_size >= PAGE_SIZE * sync_pages ) {
0 commit comments