lib/radix-tree.c
Source file repositories/reference/linux-study-clean/lib/radix-tree.c
File Facts
- System
- Linux kernel
- Corpus path
lib/radix-tree.c- Extension
.c- Size
- 44109 bytes
- Lines
- 1609
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitmap.hlinux/bitops.hlinux/bug.hlinux/cpu.hlinux/errno.hlinux/export.hlinux/idr.hlinux/init.hlinux/kernel.hlinux/kmemleak.hlinux/percpu.hlinux/preempt.hlinux/radix-tree.hlinux/rcupdate.hlinux/slab.hlinux/string.hlinux/xarray.hradix-tree.h
Detected Declarations
function get_slot_offsetfunction radix_tree_descendfunction root_gfp_maskfunction tag_setfunction tag_clearfunction tag_getfunction root_tag_setfunction root_tag_clearfunction root_tag_clear_allfunction root_tag_getfunction root_tags_getfunction is_idrfunction any_tag_setfunction all_tag_setfunction find_next_bitfunction iter_offsetfunction shift_maxindexfunction node_maxindexfunction next_indexfunction radix_tree_node_allocfunction radix_tree_node_rcu_freefunction radix_tree_node_freefunction INIT_RADIX_TREEfunction INIT_RADIX_TREEfunction radix_tree_maybe_preloadfunction radix_tree_load_rootfunction radix_tree_extendfunction radix_tree_shrinkfunction delete_nodefunction __radix_tree_createfunction radix_tree_free_nodesfunction insert_entriesfunction radix_tree_insertfunction nodesfunction replace_slotfunction node_tag_getfunction calculate_countfunction __radix_tree_lookupfunction radix_tree_lookup_slotfunction radix_tree_for_each_slotfunction node_tag_setfunction tagfunction node_tag_clearfunction tagfunction radix_tree_iter_tag_clearfunction radix_tree_tag_getfunction set_iter_tagsfunction radix_tree_gang_lookup
Annotated Snippet
while (offset < RADIX_TREE_MAP_SIZE) {
tmp = *++addr;
if (tmp)
return __ffs(tmp) + offset;
offset += BITS_PER_LONG;
}
}
return RADIX_TREE_MAP_SIZE;
}
static unsigned int iter_offset(const struct radix_tree_iter *iter)
{
return iter->index & RADIX_TREE_MAP_MASK;
}
/*
* The maximum index which can be stored in a radix tree
*/
static inline unsigned long shift_maxindex(unsigned int shift)
{
return (RADIX_TREE_MAP_SIZE << shift) - 1;
}
static inline unsigned long node_maxindex(const struct radix_tree_node *node)
{
return shift_maxindex(node->shift);
}
static unsigned long next_index(unsigned long index,
const struct radix_tree_node *node,
unsigned long offset)
{
return (index & ~node_maxindex(node)) + (offset << node->shift);
}
/*
* This assumes that the caller has performed appropriate preallocation, and
* that the caller has pinned this thread of control to the current CPU.
*/
static struct radix_tree_node *
radix_tree_node_alloc(gfp_t gfp_mask, struct radix_tree_node *parent,
struct radix_tree_root *root,
unsigned int shift, unsigned int offset,
unsigned int count, unsigned int nr_values)
{
struct radix_tree_node *ret = NULL;
/*
* Preload code isn't irq safe and it doesn't make sense to use
* preloading during an interrupt anyway as all the allocations have
* to be atomic. So just do normal allocation when in interrupt.
*/
if (!gfpflags_allow_blocking(gfp_mask) && !in_interrupt()) {
struct radix_tree_preload *rtp;
/*
* Even if the caller has preloaded, try to allocate from the
* cache first for the new node to get accounted to the memory
* cgroup.
*/
ret = kmem_cache_alloc(radix_tree_node_cachep,
gfp_mask | __GFP_NOWARN);
if (ret)
goto out;
/*
* Provided the caller has preloaded here, we will always
* succeed in getting a node here (and never reach
* kmem_cache_alloc)
*/
rtp = this_cpu_ptr(&radix_tree_preloads);
if (rtp->nr) {
ret = rtp->nodes;
rtp->nodes = ret->parent;
rtp->nr--;
}
/*
* Update the allocation stack trace as this is more useful
* for debugging.
*/
kmemleak_update_trace(ret);
goto out;
}
ret = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask);
out:
BUG_ON(radix_tree_is_internal_node(ret));
if (ret) {
ret->shift = shift;
ret->offset = offset;
ret->count = count;
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/bitops.h`, `linux/bug.h`, `linux/cpu.h`, `linux/errno.h`, `linux/export.h`, `linux/idr.h`, `linux/init.h`.
- Detected declarations: `function get_slot_offset`, `function radix_tree_descend`, `function root_gfp_mask`, `function tag_set`, `function tag_clear`, `function tag_get`, `function root_tag_set`, `function root_tag_clear`, `function root_tag_clear_all`, `function root_tag_get`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.