5
5
#include <linux/gfp.h>
6
6
#include <linux/kmemleak.h>
7
7
8
- #define GENRADIX_ARY (PAGE_SIZE / sizeof(struct genradix_node *))
8
+ #define GENRADIX_ARY (GENRADIX_NODE_SIZE / sizeof(struct genradix_node *))
9
9
#define GENRADIX_ARY_SHIFT ilog2(GENRADIX_ARY)
10
10
11
11
struct genradix_node {
@@ -14,13 +14,13 @@ struct genradix_node {
14
14
struct genradix_node * children [GENRADIX_ARY ];
15
15
16
16
/* Leaf: */
17
- u8 data [PAGE_SIZE ];
17
+ u8 data [GENRADIX_NODE_SIZE ];
18
18
};
19
19
};
20
20
21
21
static inline int genradix_depth_shift (unsigned depth )
22
22
{
23
- return PAGE_SHIFT + GENRADIX_ARY_SHIFT * depth ;
23
+ return GENRADIX_NODE_SHIFT + GENRADIX_ARY_SHIFT * depth ;
24
24
}
25
25
26
26
/*
@@ -33,7 +33,7 @@ static inline size_t genradix_depth_size(unsigned depth)
33
33
34
34
/* depth that's needed for a genradix that can address up to ULONG_MAX: */
35
35
#define GENRADIX_MAX_DEPTH \
36
- DIV_ROUND_UP(BITS_PER_LONG - PAGE_SHIFT , GENRADIX_ARY_SHIFT)
36
+ DIV_ROUND_UP(BITS_PER_LONG - GENRADIX_NODE_SHIFT , GENRADIX_ARY_SHIFT)
37
37
38
38
#define GENRADIX_DEPTH_MASK \
39
39
((unsigned long) (roundup_pow_of_two(GENRADIX_MAX_DEPTH + 1) - 1))
@@ -79,23 +79,12 @@ EXPORT_SYMBOL(__genradix_ptr);
79
79
80
80
static inline struct genradix_node * genradix_alloc_node (gfp_t gfp_mask )
81
81
{
82
- struct genradix_node * node ;
83
-
84
- node = (struct genradix_node * )__get_free_page (gfp_mask |__GFP_ZERO );
85
-
86
- /*
87
- * We're using pages (not slab allocations) directly for kernel data
88
- * structures, so we need to explicitly inform kmemleak of them in order
89
- * to avoid false positive memory leak reports.
90
- */
91
- kmemleak_alloc (node , PAGE_SIZE , 1 , gfp_mask );
92
- return node ;
82
+ return kzalloc (GENRADIX_NODE_SIZE , gfp_mask );
93
83
}
94
84
95
85
static inline void genradix_free_node (struct genradix_node * node )
96
86
{
97
- kmemleak_free (node );
98
- free_page ((unsigned long )node );
87
+ kfree (node );
99
88
}
100
89
101
90
/*
@@ -200,7 +189,7 @@ void *__genradix_iter_peek(struct genradix_iter *iter,
200
189
i ++ ;
201
190
iter -> offset = round_down (iter -> offset + objs_per_ptr ,
202
191
objs_per_ptr );
203
- iter -> pos = (iter -> offset >> PAGE_SHIFT ) *
192
+ iter -> pos = (iter -> offset >> GENRADIX_NODE_SHIFT ) *
204
193
objs_per_page ;
205
194
if (i == GENRADIX_ARY )
206
195
goto restart ;
@@ -209,7 +198,7 @@ void *__genradix_iter_peek(struct genradix_iter *iter,
209
198
n = n -> children [i ];
210
199
}
211
200
212
- return & n -> data [iter -> offset & (PAGE_SIZE - 1 )];
201
+ return & n -> data [iter -> offset & (GENRADIX_NODE_SIZE - 1 )];
213
202
}
214
203
EXPORT_SYMBOL (__genradix_iter_peek );
215
204
@@ -235,7 +224,7 @@ void *__genradix_iter_peek_prev(struct genradix_iter *iter,
235
224
236
225
if (ilog2 (iter -> offset ) >= genradix_depth_shift (level )) {
237
226
iter -> offset = genradix_depth_size (level );
238
- iter -> pos = (iter -> offset >> PAGE_SHIFT ) * objs_per_page ;
227
+ iter -> pos = (iter -> offset >> GENRADIX_NODE_SHIFT ) * objs_per_page ;
239
228
240
229
iter -> offset -= obj_size_plus_page_remainder ;
241
230
iter -> pos -- ;
@@ -251,7 +240,7 @@ void *__genradix_iter_peek_prev(struct genradix_iter *iter,
251
240
size_t objs_per_ptr = genradix_depth_size (level );
252
241
253
242
iter -> offset = round_down (iter -> offset , objs_per_ptr );
254
- iter -> pos = (iter -> offset >> PAGE_SHIFT ) * objs_per_page ;
243
+ iter -> pos = (iter -> offset >> GENRADIX_NODE_SHIFT ) * objs_per_page ;
255
244
256
245
if (!iter -> offset )
257
246
return NULL ;
@@ -267,7 +256,7 @@ void *__genradix_iter_peek_prev(struct genradix_iter *iter,
267
256
n = n -> children [i ];
268
257
}
269
258
270
- return & n -> data [iter -> offset & (PAGE_SIZE - 1 )];
259
+ return & n -> data [iter -> offset & (GENRADIX_NODE_SIZE - 1 )];
271
260
}
272
261
EXPORT_SYMBOL (__genradix_iter_peek_prev );
273
262
@@ -289,7 +278,7 @@ int __genradix_prealloc(struct __genradix *radix, size_t size,
289
278
{
290
279
size_t offset ;
291
280
292
- for (offset = 0 ; offset < size ; offset += PAGE_SIZE )
281
+ for (offset = 0 ; offset < size ; offset += GENRADIX_NODE_SIZE )
293
282
if (!__genradix_ptr_alloc (radix , offset , gfp_mask ))
294
283
return - ENOMEM ;
295
284
0 commit comments