2 * Copyright (C) 2001 Momchil Velikov
3 * Portions Copyright (C) 2001 Christoph Hellwig
4 * Copyright (C) 2005 SGI, Christoph Lameter
5 * Copyright (C) 2006 Nick Piggin
6 * Copyright (C) 2012 Konstantin Khlebnikov
7 * Copyright (C) 2016 Intel, Matthew Wilcox
8 * Copyright (C) 2016 Intel, Ross Zwisler
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/errno.h>
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/export.h>
29 #include <linux/radix-tree.h>
30 #include <linux/percpu.h>
31 #include <linux/slab.h>
32 #include <linux/kmemleak.h>
33 #include <linux/notifier.h>
34 #include <linux/cpu.h>
35 #include <linux/string.h>
36 #include <linux/bitops.h>
37 #include <linux/rcupdate.h>
38 #include <linux/preempt.h> /* in_interrupt() */
41 /* Number of nodes in fully populated tree of given height */
42 static unsigned long height_to_maxnodes
[RADIX_TREE_MAX_PATH
+ 1] __read_mostly
;
45 * Radix tree node cache.
47 static struct kmem_cache
*radix_tree_node_cachep
;
50 * The radix tree is variable-height, so an insert operation not only has
51 * to build the branch to its corresponding item, it also has to build the
52 * branch to existing items if the size has to be increased (by
55 * The worst case is a zero height tree with just a single item at index 0,
56 * and then inserting an item at index ULONG_MAX. This requires 2 new branches
57 * of RADIX_TREE_MAX_PATH size to be created, with only the root node shared.
60 #define RADIX_TREE_PRELOAD_SIZE (RADIX_TREE_MAX_PATH * 2 - 1)
63 * Per-cpu pool of preloaded nodes
65 struct radix_tree_preload
{
67 /* nodes->private_data points to next preallocated node */
68 struct radix_tree_node
*nodes
;
70 static DEFINE_PER_CPU(struct radix_tree_preload
, radix_tree_preloads
) = { 0, };
72 static inline struct radix_tree_node
*entry_to_node(void *ptr
)
74 return (void *)((unsigned long)ptr
& ~RADIX_TREE_INTERNAL_NODE
);
77 static inline void *node_to_entry(void *ptr
)
79 return (void *)((unsigned long)ptr
| RADIX_TREE_INTERNAL_NODE
);
82 #define RADIX_TREE_RETRY node_to_entry(NULL)
84 #ifdef CONFIG_RADIX_TREE_MULTIORDER
85 /* Sibling slots point directly to another slot in the same node */
86 static inline bool is_sibling_entry(struct radix_tree_node
*parent
, void *node
)
89 return (parent
->slots
<= ptr
) &&
90 (ptr
< parent
->slots
+ RADIX_TREE_MAP_SIZE
);
93 static inline bool is_sibling_entry(struct radix_tree_node
*parent
, void *node
)
99 static inline unsigned long get_slot_offset(struct radix_tree_node
*parent
,
102 return slot
- parent
->slots
;
105 static unsigned int radix_tree_descend(struct radix_tree_node
*parent
,
106 struct radix_tree_node
**nodep
, unsigned long index
)
108 unsigned int offset
= (index
>> parent
->shift
) & RADIX_TREE_MAP_MASK
;
109 void **entry
= rcu_dereference_raw(parent
->slots
[offset
]);
111 #ifdef CONFIG_RADIX_TREE_MULTIORDER
112 if (radix_tree_is_internal_node(entry
)) {
113 if (is_sibling_entry(parent
, entry
)) {
114 void **sibentry
= (void **) entry_to_node(entry
);
115 offset
= get_slot_offset(parent
, sibentry
);
116 entry
= rcu_dereference_raw(*sibentry
);
121 *nodep
= (void *)entry
;
125 static inline gfp_t
root_gfp_mask(struct radix_tree_root
*root
)
127 return root
->gfp_mask
& __GFP_BITS_MASK
;
130 static inline void tag_set(struct radix_tree_node
*node
, unsigned int tag
,
133 __set_bit(offset
, node
->tags
[tag
]);
136 static inline void tag_clear(struct radix_tree_node
*node
, unsigned int tag
,
139 __clear_bit(offset
, node
->tags
[tag
]);
142 static inline int tag_get(struct radix_tree_node
*node
, unsigned int tag
,
145 return test_bit(offset
, node
->tags
[tag
]);
148 static inline void root_tag_set(struct radix_tree_root
*root
, unsigned int tag
)
150 root
->gfp_mask
|= (__force gfp_t
)(1 << (tag
+ __GFP_BITS_SHIFT
));
153 static inline void root_tag_clear(struct radix_tree_root
*root
, unsigned tag
)
155 root
->gfp_mask
&= (__force gfp_t
)~(1 << (tag
+ __GFP_BITS_SHIFT
));
158 static inline void root_tag_clear_all(struct radix_tree_root
*root
)
160 root
->gfp_mask
&= __GFP_BITS_MASK
;
163 static inline int root_tag_get(struct radix_tree_root
*root
, unsigned int tag
)
165 return (__force
int)root
->gfp_mask
& (1 << (tag
+ __GFP_BITS_SHIFT
));
168 static inline unsigned root_tags_get(struct radix_tree_root
*root
)
170 return (__force
unsigned)root
->gfp_mask
>> __GFP_BITS_SHIFT
;
174 * Returns 1 if any slot in the node has this tag set.
175 * Otherwise returns 0.
177 static inline int any_tag_set(struct radix_tree_node
*node
, unsigned int tag
)
180 for (idx
= 0; idx
< RADIX_TREE_TAG_LONGS
; idx
++) {
181 if (node
->tags
[tag
][idx
])
188 * radix_tree_find_next_bit - find the next set bit in a memory region
190 * @addr: The address to base the search on
191 * @size: The bitmap size in bits
192 * @offset: The bitnumber to start searching at
194 * Unrollable variant of find_next_bit() for constant size arrays.
195 * Tail bits starting from size to roundup(size, BITS_PER_LONG) must be zero.
196 * Returns next bit offset, or size if nothing found.
198 static __always_inline
unsigned long
199 radix_tree_find_next_bit(struct radix_tree_node
*node
, unsigned int tag
,
200 unsigned long offset
)
202 const unsigned long *addr
= node
->tags
[tag
];
204 if (offset
< RADIX_TREE_MAP_SIZE
) {
207 addr
+= offset
/ BITS_PER_LONG
;
208 tmp
= *addr
>> (offset
% BITS_PER_LONG
);
210 return __ffs(tmp
) + offset
;
211 offset
= (offset
+ BITS_PER_LONG
) & ~(BITS_PER_LONG
- 1);
212 while (offset
< RADIX_TREE_MAP_SIZE
) {
215 return __ffs(tmp
) + offset
;
216 offset
+= BITS_PER_LONG
;
219 return RADIX_TREE_MAP_SIZE
;
222 static unsigned int iter_offset(const struct radix_tree_iter
*iter
)
224 return (iter
->index
>> iter_shift(iter
)) & RADIX_TREE_MAP_MASK
;
228 * The maximum index which can be stored in a radix tree
230 static inline unsigned long shift_maxindex(unsigned int shift
)
232 return (RADIX_TREE_MAP_SIZE
<< shift
) - 1;
235 static inline unsigned long node_maxindex(struct radix_tree_node
*node
)
237 return shift_maxindex(node
->shift
);
241 static void dump_node(struct radix_tree_node
*node
, unsigned long index
)
245 pr_debug("radix node: %p offset %d indices %lu-%lu parent %p tags %lx %lx %lx shift %d count %d exceptional %d\n",
246 node
, node
->offset
, index
, index
| node_maxindex(node
),
248 node
->tags
[0][0], node
->tags
[1][0], node
->tags
[2][0],
249 node
->shift
, node
->count
, node
->exceptional
);
251 for (i
= 0; i
< RADIX_TREE_MAP_SIZE
; i
++) {
252 unsigned long first
= index
| (i
<< node
->shift
);
253 unsigned long last
= first
| ((1UL << node
->shift
) - 1);
254 void *entry
= node
->slots
[i
];
257 if (entry
== RADIX_TREE_RETRY
) {
258 pr_debug("radix retry offset %ld indices %lu-%lu parent %p\n",
259 i
, first
, last
, node
);
260 } else if (!radix_tree_is_internal_node(entry
)) {
261 pr_debug("radix entry %p offset %ld indices %lu-%lu parent %p\n",
262 entry
, i
, first
, last
, node
);
263 } else if (is_sibling_entry(node
, entry
)) {
264 pr_debug("radix sblng %p offset %ld indices %lu-%lu parent %p val %p\n",
265 entry
, i
, first
, last
, node
,
266 *(void **)entry_to_node(entry
));
268 dump_node(entry_to_node(entry
), first
);
274 static void radix_tree_dump(struct radix_tree_root
*root
)
276 pr_debug("radix root: %p rnode %p tags %x\n",
278 root
->gfp_mask
>> __GFP_BITS_SHIFT
);
279 if (!radix_tree_is_internal_node(root
->rnode
))
281 dump_node(entry_to_node(root
->rnode
), 0);
286 * This assumes that the caller has performed appropriate preallocation, and
287 * that the caller has pinned this thread of control to the current CPU.
289 static struct radix_tree_node
*
290 radix_tree_node_alloc(struct radix_tree_root
*root
)
292 struct radix_tree_node
*ret
= NULL
;
293 gfp_t gfp_mask
= root_gfp_mask(root
);
296 * Preload code isn't irq safe and it doesn't make sense to use
297 * preloading during an interrupt anyway as all the allocations have
298 * to be atomic. So just do normal allocation when in interrupt.
300 if (!gfpflags_allow_blocking(gfp_mask
) && !in_interrupt()) {
301 struct radix_tree_preload
*rtp
;
304 * Even if the caller has preloaded, try to allocate from the
305 * cache first for the new node to get accounted to the memory
308 ret
= kmem_cache_alloc(radix_tree_node_cachep
,
309 gfp_mask
| __GFP_NOWARN
);
314 * Provided the caller has preloaded here, we will always
315 * succeed in getting a node here (and never reach
318 rtp
= this_cpu_ptr(&radix_tree_preloads
);
321 rtp
->nodes
= ret
->private_data
;
322 ret
->private_data
= NULL
;
326 * Update the allocation stack trace as this is more useful
329 kmemleak_update_trace(ret
);
332 ret
= kmem_cache_alloc(radix_tree_node_cachep
, gfp_mask
);
334 BUG_ON(radix_tree_is_internal_node(ret
));
338 static void radix_tree_node_rcu_free(struct rcu_head
*head
)
340 struct radix_tree_node
*node
=
341 container_of(head
, struct radix_tree_node
, rcu_head
);
345 * must only free zeroed nodes into the slab. radix_tree_shrink
346 * can leave us with a non-NULL entry in the first slot, so clear
347 * that here to make sure.
349 for (i
= 0; i
< RADIX_TREE_MAX_TAGS
; i
++)
350 tag_clear(node
, i
, 0);
352 node
->slots
[0] = NULL
;
353 INIT_LIST_HEAD(&node
->private_list
);
355 kmem_cache_free(radix_tree_node_cachep
, node
);
359 radix_tree_node_free(struct radix_tree_node
*node
)
361 call_rcu(&node
->rcu_head
, radix_tree_node_rcu_free
);
365 * Load up this CPU's radix_tree_node buffer with sufficient objects to
366 * ensure that the addition of a single element in the tree cannot fail. On
367 * success, return zero, with preemption disabled. On error, return -ENOMEM
368 * with preemption not disabled.
370 * To make use of this facility, the radix tree must be initialised without
371 * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE().
373 static int __radix_tree_preload(gfp_t gfp_mask
, int nr
)
375 struct radix_tree_preload
*rtp
;
376 struct radix_tree_node
*node
;
380 * Nodes preloaded by one cgroup can be be used by another cgroup, so
381 * they should never be accounted to any particular memory cgroup.
383 gfp_mask
&= ~__GFP_ACCOUNT
;
386 rtp
= this_cpu_ptr(&radix_tree_preloads
);
387 while (rtp
->nr
< nr
) {
389 node
= kmem_cache_alloc(radix_tree_node_cachep
, gfp_mask
);
393 rtp
= this_cpu_ptr(&radix_tree_preloads
);
395 node
->private_data
= rtp
->nodes
;
399 kmem_cache_free(radix_tree_node_cachep
, node
);
408 * Load up this CPU's radix_tree_node buffer with sufficient objects to
409 * ensure that the addition of a single element in the tree cannot fail. On
410 * success, return zero, with preemption disabled. On error, return -ENOMEM
411 * with preemption not disabled.
413 * To make use of this facility, the radix tree must be initialised without
414 * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE().
416 int radix_tree_preload(gfp_t gfp_mask
)
418 /* Warn on non-sensical use... */
419 WARN_ON_ONCE(!gfpflags_allow_blocking(gfp_mask
));
420 return __radix_tree_preload(gfp_mask
, RADIX_TREE_PRELOAD_SIZE
);
422 EXPORT_SYMBOL(radix_tree_preload
);
425 * The same as above function, except we don't guarantee preloading happens.
426 * We do it, if we decide it helps. On success, return zero with preemption
427 * disabled. On error, return -ENOMEM with preemption not disabled.
429 int radix_tree_maybe_preload(gfp_t gfp_mask
)
431 if (gfpflags_allow_blocking(gfp_mask
))
432 return __radix_tree_preload(gfp_mask
, RADIX_TREE_PRELOAD_SIZE
);
433 /* Preloading doesn't help anything with this gfp mask, skip it */
437 EXPORT_SYMBOL(radix_tree_maybe_preload
);
440 * The same as function above, but preload number of nodes required to insert
441 * (1 << order) continuous naturally-aligned elements.
443 int radix_tree_maybe_preload_order(gfp_t gfp_mask
, int order
)
445 unsigned long nr_subtrees
;
446 int nr_nodes
, subtree_height
;
448 /* Preloading doesn't help anything with this gfp mask, skip it */
449 if (!gfpflags_allow_blocking(gfp_mask
)) {
455 * Calculate number and height of fully populated subtrees it takes to
456 * store (1 << order) elements.
458 nr_subtrees
= 1 << order
;
459 for (subtree_height
= 0; nr_subtrees
> RADIX_TREE_MAP_SIZE
;
461 nr_subtrees
>>= RADIX_TREE_MAP_SHIFT
;
464 * The worst case is zero height tree with a single item at index 0 and
465 * then inserting items starting at ULONG_MAX - (1 << order).
467 * This requires RADIX_TREE_MAX_PATH nodes to build branch from root to
470 nr_nodes
= RADIX_TREE_MAX_PATH
;
472 /* Plus branch to fully populated subtrees. */
473 nr_nodes
+= RADIX_TREE_MAX_PATH
- subtree_height
;
475 /* Root node is shared. */
478 /* Plus nodes required to build subtrees. */
479 nr_nodes
+= nr_subtrees
* height_to_maxnodes
[subtree_height
];
481 return __radix_tree_preload(gfp_mask
, nr_nodes
);
484 static unsigned radix_tree_load_root(struct radix_tree_root
*root
,
485 struct radix_tree_node
**nodep
, unsigned long *maxindex
)
487 struct radix_tree_node
*node
= rcu_dereference_raw(root
->rnode
);
491 if (likely(radix_tree_is_internal_node(node
))) {
492 node
= entry_to_node(node
);
493 *maxindex
= node_maxindex(node
);
494 return node
->shift
+ RADIX_TREE_MAP_SHIFT
;
502 * Extend a radix tree so it can store key @index.
504 static int radix_tree_extend(struct radix_tree_root
*root
,
505 unsigned long index
, unsigned int shift
)
507 struct radix_tree_node
*slot
;
508 unsigned int maxshift
;
511 /* Figure out what the shift should be. */
513 while (index
> shift_maxindex(maxshift
))
514 maxshift
+= RADIX_TREE_MAP_SHIFT
;
521 struct radix_tree_node
*node
= radix_tree_node_alloc(root
);
526 /* Propagate the aggregated tag info into the new root */
527 for (tag
= 0; tag
< RADIX_TREE_MAX_TAGS
; tag
++) {
528 if (root_tag_get(root
, tag
))
529 tag_set(node
, tag
, 0);
532 BUG_ON(shift
> BITS_PER_LONG
);
537 if (radix_tree_is_internal_node(slot
)) {
538 entry_to_node(slot
)->parent
= node
;
540 /* Moving an exceptional root->rnode to a node */
541 if (radix_tree_exceptional_entry(slot
))
542 node
->exceptional
= 1;
544 node
->slots
[0] = slot
;
545 slot
= node_to_entry(node
);
546 rcu_assign_pointer(root
->rnode
, slot
);
547 shift
+= RADIX_TREE_MAP_SHIFT
;
548 } while (shift
<= maxshift
);
550 return maxshift
+ RADIX_TREE_MAP_SHIFT
;
554 * radix_tree_shrink - shrink radix tree to minimum height
555 * @root radix tree root
557 static inline void radix_tree_shrink(struct radix_tree_root
*root
,
558 radix_tree_update_node_t update_node
,
562 struct radix_tree_node
*node
= root
->rnode
;
563 struct radix_tree_node
*child
;
565 if (!radix_tree_is_internal_node(node
))
567 node
= entry_to_node(node
);
570 * The candidate node has more than one child, or its child
571 * is not at the leftmost slot, or the child is a multiorder
572 * entry, we cannot shrink.
574 if (node
->count
!= 1)
576 child
= node
->slots
[0];
579 if (!radix_tree_is_internal_node(child
) && node
->shift
)
582 if (radix_tree_is_internal_node(child
))
583 entry_to_node(child
)->parent
= NULL
;
586 * We don't need rcu_assign_pointer(), since we are simply
587 * moving the node from one part of the tree to another: if it
588 * was safe to dereference the old pointer to it
589 * (node->slots[0]), it will be safe to dereference the new
590 * one (root->rnode) as far as dependent read barriers go.
595 * We have a dilemma here. The node's slot[0] must not be
596 * NULLed in case there are concurrent lookups expecting to
597 * find the item. However if this was a bottom-level node,
598 * then it may be subject to the slot pointer being visible
599 * to callers dereferencing it. If item corresponding to
600 * slot[0] is subsequently deleted, these callers would expect
601 * their slot to become empty sooner or later.
603 * For example, lockless pagecache will look up a slot, deref
604 * the page pointer, and if the page has 0 refcount it means it
605 * was concurrently deleted from pagecache so try the deref
606 * again. Fortunately there is already a requirement for logic
607 * to retry the entire slot lookup -- the indirect pointer
608 * problem (replacing direct root node with an indirect pointer
609 * also results in a stale slot). So tag the slot as indirect
610 * to force callers to retry.
613 if (!radix_tree_is_internal_node(child
)) {
614 node
->slots
[0] = RADIX_TREE_RETRY
;
616 update_node(node
, private);
619 radix_tree_node_free(node
);
623 static void delete_node(struct radix_tree_root
*root
,
624 struct radix_tree_node
*node
,
625 radix_tree_update_node_t update_node
, void *private)
628 struct radix_tree_node
*parent
;
631 if (node
== entry_to_node(root
->rnode
))
632 radix_tree_shrink(root
, update_node
, private);
636 parent
= node
->parent
;
638 parent
->slots
[node
->offset
] = NULL
;
641 root_tag_clear_all(root
);
645 radix_tree_node_free(node
);
652 * __radix_tree_create - create a slot in a radix tree
653 * @root: radix tree root
655 * @order: index occupies 2^order aligned slots
656 * @nodep: returns node
657 * @slotp: returns slot
659 * Create, if necessary, and return the node and slot for an item
660 * at position @index in the radix tree @root.
662 * Until there is more than one item in the tree, no nodes are
663 * allocated and @root->rnode is used as a direct slot instead of
664 * pointing to a node, in which case *@nodep will be NULL.
666 * Returns -ENOMEM, or 0 for success.
668 int __radix_tree_create(struct radix_tree_root
*root
, unsigned long index
,
669 unsigned order
, struct radix_tree_node
**nodep
,
672 struct radix_tree_node
*node
= NULL
, *child
;
673 void **slot
= (void **)&root
->rnode
;
674 unsigned long maxindex
;
675 unsigned int shift
, offset
= 0;
676 unsigned long max
= index
| ((1UL << order
) - 1);
678 shift
= radix_tree_load_root(root
, &child
, &maxindex
);
680 /* Make sure the tree is high enough. */
681 if (max
> maxindex
) {
682 int error
= radix_tree_extend(root
, max
, shift
);
688 shift
+= RADIX_TREE_MAP_SHIFT
;
691 while (shift
> order
) {
692 shift
-= RADIX_TREE_MAP_SHIFT
;
694 /* Have to add a child node. */
695 child
= radix_tree_node_alloc(root
);
698 child
->shift
= shift
;
699 child
->offset
= offset
;
700 child
->parent
= node
;
701 rcu_assign_pointer(*slot
, node_to_entry(child
));
704 } else if (!radix_tree_is_internal_node(child
))
707 /* Go a level down */
708 node
= entry_to_node(child
);
709 offset
= radix_tree_descend(node
, &child
, index
);
710 slot
= &node
->slots
[offset
];
713 #ifdef CONFIG_RADIX_TREE_MULTIORDER
714 /* Insert pointers to the canonical entry */
716 unsigned i
, n
= 1 << (order
- shift
);
717 offset
= offset
& ~(n
- 1);
718 slot
= &node
->slots
[offset
];
719 child
= node_to_entry(slot
);
720 for (i
= 0; i
< n
; i
++) {
725 for (i
= 1; i
< n
; i
++) {
726 rcu_assign_pointer(slot
[i
], child
);
740 * __radix_tree_insert - insert into a radix tree
741 * @root: radix tree root
743 * @order: key covers the 2^order indices around index
744 * @item: item to insert
746 * Insert an item into the radix tree at position @index.
748 int __radix_tree_insert(struct radix_tree_root
*root
, unsigned long index
,
749 unsigned order
, void *item
)
751 struct radix_tree_node
*node
;
755 BUG_ON(radix_tree_is_internal_node(item
));
757 error
= __radix_tree_create(root
, index
, order
, &node
, &slot
);
762 rcu_assign_pointer(*slot
, item
);
765 unsigned offset
= get_slot_offset(node
, slot
);
767 if (radix_tree_exceptional_entry(item
))
769 BUG_ON(tag_get(node
, 0, offset
));
770 BUG_ON(tag_get(node
, 1, offset
));
771 BUG_ON(tag_get(node
, 2, offset
));
773 BUG_ON(root_tags_get(root
));
778 EXPORT_SYMBOL(__radix_tree_insert
);
781 * __radix_tree_lookup - lookup an item in a radix tree
782 * @root: radix tree root
784 * @nodep: returns node
785 * @slotp: returns slot
787 * Lookup and return the item at position @index in the radix
790 * Until there is more than one item in the tree, no nodes are
791 * allocated and @root->rnode is used as a direct slot instead of
792 * pointing to a node, in which case *@nodep will be NULL.
794 void *__radix_tree_lookup(struct radix_tree_root
*root
, unsigned long index
,
795 struct radix_tree_node
**nodep
, void ***slotp
)
797 struct radix_tree_node
*node
, *parent
;
798 unsigned long maxindex
;
803 slot
= (void **)&root
->rnode
;
804 radix_tree_load_root(root
, &node
, &maxindex
);
805 if (index
> maxindex
)
808 while (radix_tree_is_internal_node(node
)) {
811 if (node
== RADIX_TREE_RETRY
)
813 parent
= entry_to_node(node
);
814 offset
= radix_tree_descend(parent
, &node
, index
);
815 slot
= parent
->slots
+ offset
;
826 * radix_tree_lookup_slot - lookup a slot in a radix tree
827 * @root: radix tree root
830 * Returns: the slot corresponding to the position @index in the
831 * radix tree @root. This is useful for update-if-exists operations.
833 * This function can be called under rcu_read_lock iff the slot is not
834 * modified by radix_tree_replace_slot, otherwise it must be called
835 * exclusive from other writers. Any dereference of the slot must be done
836 * using radix_tree_deref_slot.
838 void **radix_tree_lookup_slot(struct radix_tree_root
*root
, unsigned long index
)
842 if (!__radix_tree_lookup(root
, index
, NULL
, &slot
))
846 EXPORT_SYMBOL(radix_tree_lookup_slot
);
849 * radix_tree_lookup - perform lookup operation on a radix tree
850 * @root: radix tree root
853 * Lookup the item at the position @index in the radix tree @root.
855 * This function can be called under rcu_read_lock, however the caller
856 * must manage lifetimes of leaf nodes (eg. RCU may also be used to free
857 * them safely). No RCU barriers are required to access or modify the
858 * returned item, however.
860 void *radix_tree_lookup(struct radix_tree_root
*root
, unsigned long index
)
862 return __radix_tree_lookup(root
, index
, NULL
, NULL
);
864 EXPORT_SYMBOL(radix_tree_lookup
);
866 static void replace_slot(struct radix_tree_root
*root
,
867 struct radix_tree_node
*node
,
868 void **slot
, void *item
,
869 bool warn_typeswitch
)
871 void *old
= rcu_dereference_raw(*slot
);
872 int count
, exceptional
;
874 WARN_ON_ONCE(radix_tree_is_internal_node(item
));
876 count
= !!item
- !!old
;
877 exceptional
= !!radix_tree_exceptional_entry(item
) -
878 !!radix_tree_exceptional_entry(old
);
880 WARN_ON_ONCE(warn_typeswitch
&& (count
|| exceptional
));
883 node
->count
+= count
;
884 node
->exceptional
+= exceptional
;
887 rcu_assign_pointer(*slot
, item
);
891 * __radix_tree_replace - replace item in a slot
892 * @root: radix tree root
893 * @node: pointer to tree node
894 * @slot: pointer to slot in @node
895 * @item: new item to store in the slot.
896 * @update_node: callback for changing leaf nodes
897 * @private: private data to pass to @update_node
899 * For use with __radix_tree_lookup(). Caller must hold tree write locked
900 * across slot lookup and replacement.
902 void __radix_tree_replace(struct radix_tree_root
*root
,
903 struct radix_tree_node
*node
,
904 void **slot
, void *item
,
905 radix_tree_update_node_t update_node
, void *private)
908 * This function supports replacing exceptional entries and
909 * deleting entries, but that needs accounting against the
910 * node unless the slot is root->rnode.
912 replace_slot(root
, node
, slot
, item
,
913 !node
&& slot
!= (void **)&root
->rnode
);
919 update_node(node
, private);
921 delete_node(root
, node
, update_node
, private);
925 * radix_tree_replace_slot - replace item in a slot
926 * @root: radix tree root
927 * @slot: pointer to slot
928 * @item: new item to store in the slot.
930 * For use with radix_tree_lookup_slot(), radix_tree_gang_lookup_slot(),
931 * radix_tree_gang_lookup_tag_slot(). Caller must hold tree write locked
932 * across slot lookup and replacement.
934 * NOTE: This cannot be used to switch between non-entries (empty slots),
935 * regular entries, and exceptional entries, as that requires accounting
936 * inside the radix tree node. When switching from one type of entry or
937 * deleting, use __radix_tree_lookup() and __radix_tree_replace().
939 void radix_tree_replace_slot(struct radix_tree_root
*root
,
940 void **slot
, void *item
)
942 replace_slot(root
, NULL
, slot
, item
, true);
946 * radix_tree_tag_set - set a tag on a radix tree node
947 * @root: radix tree root
951 * Set the search tag (which must be < RADIX_TREE_MAX_TAGS)
952 * corresponding to @index in the radix tree. From
953 * the root all the way down to the leaf node.
955 * Returns the address of the tagged item. Setting a tag on a not-present
958 void *radix_tree_tag_set(struct radix_tree_root
*root
,
959 unsigned long index
, unsigned int tag
)
961 struct radix_tree_node
*node
, *parent
;
962 unsigned long maxindex
;
964 radix_tree_load_root(root
, &node
, &maxindex
);
965 BUG_ON(index
> maxindex
);
967 while (radix_tree_is_internal_node(node
)) {
970 parent
= entry_to_node(node
);
971 offset
= radix_tree_descend(parent
, &node
, index
);
974 if (!tag_get(parent
, tag
, offset
))
975 tag_set(parent
, tag
, offset
);
978 /* set the root's tag bit */
979 if (!root_tag_get(root
, tag
))
980 root_tag_set(root
, tag
);
984 EXPORT_SYMBOL(radix_tree_tag_set
);
986 static void node_tag_clear(struct radix_tree_root
*root
,
987 struct radix_tree_node
*node
,
988 unsigned int tag
, unsigned int offset
)
991 if (!tag_get(node
, tag
, offset
))
993 tag_clear(node
, tag
, offset
);
994 if (any_tag_set(node
, tag
))
997 offset
= node
->offset
;
1001 /* clear the root's tag bit */
1002 if (root_tag_get(root
, tag
))
1003 root_tag_clear(root
, tag
);
1006 static void node_tag_set(struct radix_tree_root
*root
,
1007 struct radix_tree_node
*node
,
1008 unsigned int tag
, unsigned int offset
)
1011 if (tag_get(node
, tag
, offset
))
1013 tag_set(node
, tag
, offset
);
1014 offset
= node
->offset
;
1015 node
= node
->parent
;
1018 if (!root_tag_get(root
, tag
))
1019 root_tag_set(root
, tag
);
1023 * radix_tree_iter_tag_set - set a tag on the current iterator entry
1024 * @root: radix tree root
1025 * @iter: iterator state
1028 void radix_tree_iter_tag_set(struct radix_tree_root
*root
,
1029 const struct radix_tree_iter
*iter
, unsigned int tag
)
1031 node_tag_set(root
, iter
->node
, tag
, iter_offset(iter
));
1035 * radix_tree_tag_clear - clear a tag on a radix tree node
1036 * @root: radix tree root
1040 * Clear the search tag (which must be < RADIX_TREE_MAX_TAGS)
1041 * corresponding to @index in the radix tree. If this causes
1042 * the leaf node to have no tags set then clear the tag in the
1043 * next-to-leaf node, etc.
1045 * Returns the address of the tagged item on success, else NULL. ie:
1046 * has the same return value and semantics as radix_tree_lookup().
1048 void *radix_tree_tag_clear(struct radix_tree_root
*root
,
1049 unsigned long index
, unsigned int tag
)
1051 struct radix_tree_node
*node
, *parent
;
1052 unsigned long maxindex
;
1053 int uninitialized_var(offset
);
1055 radix_tree_load_root(root
, &node
, &maxindex
);
1056 if (index
> maxindex
)
1061 while (radix_tree_is_internal_node(node
)) {
1062 parent
= entry_to_node(node
);
1063 offset
= radix_tree_descend(parent
, &node
, index
);
1067 node_tag_clear(root
, parent
, tag
, offset
);
1071 EXPORT_SYMBOL(radix_tree_tag_clear
);
1074 * radix_tree_tag_get - get a tag on a radix tree node
1075 * @root: radix tree root
1077 * @tag: tag index (< RADIX_TREE_MAX_TAGS)
1081 * 0: tag not present or not set
1084 * Note that the return value of this function may not be relied on, even if
1085 * the RCU lock is held, unless tag modification and node deletion are excluded
1088 int radix_tree_tag_get(struct radix_tree_root
*root
,
1089 unsigned long index
, unsigned int tag
)
1091 struct radix_tree_node
*node
, *parent
;
1092 unsigned long maxindex
;
1094 if (!root_tag_get(root
, tag
))
1097 radix_tree_load_root(root
, &node
, &maxindex
);
1098 if (index
> maxindex
)
1103 while (radix_tree_is_internal_node(node
)) {
1106 parent
= entry_to_node(node
);
1107 offset
= radix_tree_descend(parent
, &node
, index
);
1111 if (!tag_get(parent
, tag
, offset
))
1113 if (node
== RADIX_TREE_RETRY
)
1119 EXPORT_SYMBOL(radix_tree_tag_get
);
1121 static inline void __set_iter_shift(struct radix_tree_iter
*iter
,
1124 #ifdef CONFIG_RADIX_TREE_MULTIORDER
1125 iter
->shift
= shift
;
1129 /* Construct iter->tags bit-mask from node->tags[tag] array */
1130 static void set_iter_tags(struct radix_tree_iter
*iter
,
1131 struct radix_tree_node
*node
, unsigned offset
,
1134 unsigned tag_long
= offset
/ BITS_PER_LONG
;
1135 unsigned tag_bit
= offset
% BITS_PER_LONG
;
1137 iter
->tags
= node
->tags
[tag
][tag_long
] >> tag_bit
;
1139 /* This never happens if RADIX_TREE_TAG_LONGS == 1 */
1140 if (tag_long
< RADIX_TREE_TAG_LONGS
- 1) {
1141 /* Pick tags from next element */
1143 iter
->tags
|= node
->tags
[tag
][tag_long
+ 1] <<
1144 (BITS_PER_LONG
- tag_bit
);
1145 /* Clip chunk size, here only BITS_PER_LONG tags */
1146 iter
->next_index
= __radix_tree_iter_add(iter
, BITS_PER_LONG
);
1150 #ifdef CONFIG_RADIX_TREE_MULTIORDER
1151 static void **skip_siblings(struct radix_tree_node
**nodep
,
1152 void **slot
, struct radix_tree_iter
*iter
)
1154 void *sib
= node_to_entry(slot
- 1);
1156 while (iter
->index
< iter
->next_index
) {
1157 *nodep
= rcu_dereference_raw(*slot
);
1158 if (*nodep
&& *nodep
!= sib
)
1161 iter
->index
= __radix_tree_iter_add(iter
, 1);
1169 void ** __radix_tree_next_slot(void **slot
, struct radix_tree_iter
*iter
,
1172 unsigned tag
= flags
& RADIX_TREE_ITER_TAG_MASK
;
1173 struct radix_tree_node
*node
= rcu_dereference_raw(*slot
);
1175 slot
= skip_siblings(&node
, slot
, iter
);
1177 while (radix_tree_is_internal_node(node
)) {
1179 unsigned long next_index
;
1181 if (node
== RADIX_TREE_RETRY
)
1183 node
= entry_to_node(node
);
1185 iter
->shift
= node
->shift
;
1187 if (flags
& RADIX_TREE_ITER_TAGGED
) {
1188 offset
= radix_tree_find_next_bit(node
, tag
, 0);
1189 if (offset
== RADIX_TREE_MAP_SIZE
)
1191 slot
= &node
->slots
[offset
];
1192 iter
->index
= __radix_tree_iter_add(iter
, offset
);
1193 set_iter_tags(iter
, node
, offset
, tag
);
1194 node
= rcu_dereference_raw(*slot
);
1197 slot
= &node
->slots
[0];
1199 node
= rcu_dereference_raw(*slot
);
1204 if (offset
== RADIX_TREE_MAP_SIZE
)
1207 iter
->index
= __radix_tree_iter_add(iter
, offset
);
1209 if ((flags
& RADIX_TREE_ITER_CONTIG
) && (offset
> 0))
1211 next_index
= (iter
->index
| shift_maxindex(iter
->shift
)) + 1;
1212 if (next_index
< iter
->next_index
)
1213 iter
->next_index
= next_index
;
1218 iter
->next_index
= 0;
1221 EXPORT_SYMBOL(__radix_tree_next_slot
);
1223 static void **skip_siblings(struct radix_tree_node
**nodep
,
1224 void **slot
, struct radix_tree_iter
*iter
)
1230 void **radix_tree_iter_resume(void **slot
, struct radix_tree_iter
*iter
)
1232 struct radix_tree_node
*node
;
1235 iter
->index
= __radix_tree_iter_add(iter
, 1);
1236 node
= rcu_dereference_raw(*slot
);
1237 skip_siblings(&node
, slot
, iter
);
1238 iter
->next_index
= iter
->index
;
1242 EXPORT_SYMBOL(radix_tree_iter_resume
);
1245 * radix_tree_next_chunk - find next chunk of slots for iteration
1247 * @root: radix tree root
1248 * @iter: iterator state
1249 * @flags: RADIX_TREE_ITER_* flags and tag index
1250 * Returns: pointer to chunk first slot, or NULL if iteration is over
1252 void **radix_tree_next_chunk(struct radix_tree_root
*root
,
1253 struct radix_tree_iter
*iter
, unsigned flags
)
1255 unsigned tag
= flags
& RADIX_TREE_ITER_TAG_MASK
;
1256 struct radix_tree_node
*node
, *child
;
1257 unsigned long index
, offset
, maxindex
;
1259 if ((flags
& RADIX_TREE_ITER_TAGGED
) && !root_tag_get(root
, tag
))
1263 * Catch next_index overflow after ~0UL. iter->index never overflows
1264 * during iterating; it can be zero only at the beginning.
1265 * And we cannot overflow iter->next_index in a single step,
1266 * because RADIX_TREE_MAP_SHIFT < BITS_PER_LONG.
1268 * This condition also used by radix_tree_next_slot() to stop
1269 * contiguous iterating, and forbid switching to the next chunk.
1271 index
= iter
->next_index
;
1272 if (!index
&& iter
->index
)
1276 radix_tree_load_root(root
, &child
, &maxindex
);
1277 if (index
> maxindex
)
1282 if (!radix_tree_is_internal_node(child
)) {
1283 /* Single-slot tree */
1284 iter
->index
= index
;
1285 iter
->next_index
= maxindex
+ 1;
1288 __set_iter_shift(iter
, 0);
1289 return (void **)&root
->rnode
;
1293 node
= entry_to_node(child
);
1294 offset
= radix_tree_descend(node
, &child
, index
);
1296 if ((flags
& RADIX_TREE_ITER_TAGGED
) ?
1297 !tag_get(node
, tag
, offset
) : !child
) {
1299 if (flags
& RADIX_TREE_ITER_CONTIG
)
1302 if (flags
& RADIX_TREE_ITER_TAGGED
)
1303 offset
= radix_tree_find_next_bit(node
, tag
,
1306 while (++offset
< RADIX_TREE_MAP_SIZE
) {
1307 void *slot
= node
->slots
[offset
];
1308 if (is_sibling_entry(node
, slot
))
1313 index
&= ~node_maxindex(node
);
1314 index
+= offset
<< node
->shift
;
1315 /* Overflow after ~0UL */
1318 if (offset
== RADIX_TREE_MAP_SIZE
)
1320 child
= rcu_dereference_raw(node
->slots
[offset
]);
1323 if ((child
== NULL
) || (child
== RADIX_TREE_RETRY
))
1325 } while (radix_tree_is_internal_node(child
));
1327 /* Update the iterator state */
1328 iter
->index
= (index
&~ node_maxindex(node
)) | (offset
<< node
->shift
);
1329 iter
->next_index
= (index
| node_maxindex(node
)) + 1;
1331 __set_iter_shift(iter
, node
->shift
);
1333 if (flags
& RADIX_TREE_ITER_TAGGED
)
1334 set_iter_tags(iter
, node
, offset
, tag
);
1336 return node
->slots
+ offset
;
1338 EXPORT_SYMBOL(radix_tree_next_chunk
);
1341 * radix_tree_gang_lookup - perform multiple lookup on a radix tree
1342 * @root: radix tree root
1343 * @results: where the results of the lookup are placed
1344 * @first_index: start the lookup from this key
1345 * @max_items: place up to this many items at *results
1347 * Performs an index-ascending scan of the tree for present items. Places
1348 * them at *@results and returns the number of items which were placed at
1351 * The implementation is naive.
1353 * Like radix_tree_lookup, radix_tree_gang_lookup may be called under
1354 * rcu_read_lock. In this case, rather than the returned results being
1355 * an atomic snapshot of the tree at a single point in time, the
1356 * semantics of an RCU protected gang lookup are as though multiple
1357 * radix_tree_lookups have been issued in individual locks, and results
1358 * stored in 'results'.
1361 radix_tree_gang_lookup(struct radix_tree_root
*root
, void **results
,
1362 unsigned long first_index
, unsigned int max_items
)
1364 struct radix_tree_iter iter
;
1366 unsigned int ret
= 0;
1368 if (unlikely(!max_items
))
1371 radix_tree_for_each_slot(slot
, root
, &iter
, first_index
) {
1372 results
[ret
] = rcu_dereference_raw(*slot
);
1375 if (radix_tree_is_internal_node(results
[ret
])) {
1376 slot
= radix_tree_iter_retry(&iter
);
1379 if (++ret
== max_items
)
1385 EXPORT_SYMBOL(radix_tree_gang_lookup
);
1388 * radix_tree_gang_lookup_slot - perform multiple slot lookup on radix tree
1389 * @root: radix tree root
1390 * @results: where the results of the lookup are placed
1391 * @indices: where their indices should be placed (but usually NULL)
1392 * @first_index: start the lookup from this key
1393 * @max_items: place up to this many items at *results
1395 * Performs an index-ascending scan of the tree for present items. Places
1396 * their slots at *@results and returns the number of items which were
1397 * placed at *@results.
1399 * The implementation is naive.
1401 * Like radix_tree_gang_lookup as far as RCU and locking goes. Slots must
1402 * be dereferenced with radix_tree_deref_slot, and if using only RCU
1403 * protection, radix_tree_deref_slot may fail requiring a retry.
1406 radix_tree_gang_lookup_slot(struct radix_tree_root
*root
,
1407 void ***results
, unsigned long *indices
,
1408 unsigned long first_index
, unsigned int max_items
)
1410 struct radix_tree_iter iter
;
1412 unsigned int ret
= 0;
1414 if (unlikely(!max_items
))
1417 radix_tree_for_each_slot(slot
, root
, &iter
, first_index
) {
1418 results
[ret
] = slot
;
1420 indices
[ret
] = iter
.index
;
1421 if (++ret
== max_items
)
1427 EXPORT_SYMBOL(radix_tree_gang_lookup_slot
);
1430 * radix_tree_gang_lookup_tag - perform multiple lookup on a radix tree
1432 * @root: radix tree root
1433 * @results: where the results of the lookup are placed
1434 * @first_index: start the lookup from this key
1435 * @max_items: place up to this many items at *results
1436 * @tag: the tag index (< RADIX_TREE_MAX_TAGS)
1438 * Performs an index-ascending scan of the tree for present items which
1439 * have the tag indexed by @tag set. Places the items at *@results and
1440 * returns the number of items which were placed at *@results.
1443 radix_tree_gang_lookup_tag(struct radix_tree_root
*root
, void **results
,
1444 unsigned long first_index
, unsigned int max_items
,
1447 struct radix_tree_iter iter
;
1449 unsigned int ret
= 0;
1451 if (unlikely(!max_items
))
1454 radix_tree_for_each_tagged(slot
, root
, &iter
, first_index
, tag
) {
1455 results
[ret
] = rcu_dereference_raw(*slot
);
1458 if (radix_tree_is_internal_node(results
[ret
])) {
1459 slot
= radix_tree_iter_retry(&iter
);
1462 if (++ret
== max_items
)
1468 EXPORT_SYMBOL(radix_tree_gang_lookup_tag
);
1471 * radix_tree_gang_lookup_tag_slot - perform multiple slot lookup on a
1472 * radix tree based on a tag
1473 * @root: radix tree root
1474 * @results: where the results of the lookup are placed
1475 * @first_index: start the lookup from this key
1476 * @max_items: place up to this many items at *results
1477 * @tag: the tag index (< RADIX_TREE_MAX_TAGS)
1479 * Performs an index-ascending scan of the tree for present items which
1480 * have the tag indexed by @tag set. Places the slots at *@results and
1481 * returns the number of slots which were placed at *@results.
1484 radix_tree_gang_lookup_tag_slot(struct radix_tree_root
*root
, void ***results
,
1485 unsigned long first_index
, unsigned int max_items
,
1488 struct radix_tree_iter iter
;
1490 unsigned int ret
= 0;
1492 if (unlikely(!max_items
))
1495 radix_tree_for_each_tagged(slot
, root
, &iter
, first_index
, tag
) {
1496 results
[ret
] = slot
;
1497 if (++ret
== max_items
)
1503 EXPORT_SYMBOL(radix_tree_gang_lookup_tag_slot
);
1506 * __radix_tree_delete_node - try to free node after clearing a slot
1507 * @root: radix tree root
1508 * @node: node containing @index
1510 * After clearing the slot at @index in @node from radix tree
1511 * rooted at @root, call this function to attempt freeing the
1512 * node and shrinking the tree.
1514 void __radix_tree_delete_node(struct radix_tree_root
*root
,
1515 struct radix_tree_node
*node
)
1517 delete_node(root
, node
, NULL
, NULL
);
1520 static inline void delete_sibling_entries(struct radix_tree_node
*node
,
1521 void *ptr
, unsigned offset
)
1523 #ifdef CONFIG_RADIX_TREE_MULTIORDER
1525 for (i
= 1; offset
+ i
< RADIX_TREE_MAP_SIZE
; i
++) {
1526 if (node
->slots
[offset
+ i
] != ptr
)
1528 node
->slots
[offset
+ i
] = NULL
;
1535 * radix_tree_delete_item - delete an item from a radix tree
1536 * @root: radix tree root
1538 * @item: expected item
1540 * Remove @item at @index from the radix tree rooted at @root.
1542 * Returns the address of the deleted item, or NULL if it was not present
1543 * or the entry at the given @index was not @item.
1545 void *radix_tree_delete_item(struct radix_tree_root
*root
,
1546 unsigned long index
, void *item
)
1548 struct radix_tree_node
*node
;
1549 unsigned int offset
;
1554 entry
= __radix_tree_lookup(root
, index
, &node
, &slot
);
1558 if (item
&& entry
!= item
)
1562 root_tag_clear_all(root
);
1567 offset
= get_slot_offset(node
, slot
);
1569 /* Clear all tags associated with the item to be deleted. */
1570 for (tag
= 0; tag
< RADIX_TREE_MAX_TAGS
; tag
++)
1571 node_tag_clear(root
, node
, tag
, offset
);
1573 delete_sibling_entries(node
, node_to_entry(slot
), offset
);
1574 __radix_tree_replace(root
, node
, slot
, NULL
, NULL
, NULL
);
1578 EXPORT_SYMBOL(radix_tree_delete_item
);
1581 * radix_tree_delete - delete an item from a radix tree
1582 * @root: radix tree root
1585 * Remove the item at @index from the radix tree rooted at @root.
1587 * Returns the address of the deleted item, or NULL if it was not present.
1589 void *radix_tree_delete(struct radix_tree_root
*root
, unsigned long index
)
1591 return radix_tree_delete_item(root
, index
, NULL
);
1593 EXPORT_SYMBOL(radix_tree_delete
);
1595 void radix_tree_clear_tags(struct radix_tree_root
*root
,
1596 struct radix_tree_node
*node
,
1600 unsigned int tag
, offset
= get_slot_offset(node
, slot
);
1601 for (tag
= 0; tag
< RADIX_TREE_MAX_TAGS
; tag
++)
1602 node_tag_clear(root
, node
, tag
, offset
);
1604 /* Clear root node tags */
1605 root
->gfp_mask
&= __GFP_BITS_MASK
;
1610 * radix_tree_tagged - test whether any items in the tree are tagged
1611 * @root: radix tree root
1614 int radix_tree_tagged(struct radix_tree_root
*root
, unsigned int tag
)
1616 return root_tag_get(root
, tag
);
1618 EXPORT_SYMBOL(radix_tree_tagged
);
1621 radix_tree_node_ctor(void *arg
)
1623 struct radix_tree_node
*node
= arg
;
1625 memset(node
, 0, sizeof(*node
));
1626 INIT_LIST_HEAD(&node
->private_list
);
1629 static __init
unsigned long __maxindex(unsigned int height
)
1631 unsigned int width
= height
* RADIX_TREE_MAP_SHIFT
;
1632 int shift
= RADIX_TREE_INDEX_BITS
- width
;
1636 if (shift
>= BITS_PER_LONG
)
1638 return ~0UL >> shift
;
1641 static __init
void radix_tree_init_maxnodes(void)
1643 unsigned long height_to_maxindex
[RADIX_TREE_MAX_PATH
+ 1];
1646 for (i
= 0; i
< ARRAY_SIZE(height_to_maxindex
); i
++)
1647 height_to_maxindex
[i
] = __maxindex(i
);
1648 for (i
= 0; i
< ARRAY_SIZE(height_to_maxnodes
); i
++) {
1649 for (j
= i
; j
> 0; j
--)
1650 height_to_maxnodes
[i
] += height_to_maxindex
[j
- 1] + 1;
1654 static int radix_tree_cpu_dead(unsigned int cpu
)
1656 struct radix_tree_preload
*rtp
;
1657 struct radix_tree_node
*node
;
1659 /* Free per-cpu pool of preloaded nodes */
1660 rtp
= &per_cpu(radix_tree_preloads
, cpu
);
1663 rtp
->nodes
= node
->private_data
;
1664 kmem_cache_free(radix_tree_node_cachep
, node
);
1670 void __init
radix_tree_init(void)
1673 radix_tree_node_cachep
= kmem_cache_create("radix_tree_node",
1674 sizeof(struct radix_tree_node
), 0,
1675 SLAB_PANIC
| SLAB_RECLAIM_ACCOUNT
,
1676 radix_tree_node_ctor
);
1677 radix_tree_init_maxnodes();
1678 ret
= cpuhp_setup_state_nocalls(CPUHP_RADIX_DEAD
, "lib/radix:dead",
1679 NULL
, radix_tree_cpu_dead
);