include/linux/generic-radix-tree.h
Source file repositories/reference/linux-study-clean/include/linux/generic-radix-tree.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/generic-radix-tree.h- Extension
.h- Size
- 11703 bytes
- Lines
- 403
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/page.hlinux/bug.hlinux/limits.hlinux/log2.hlinux/math.hlinux/slab.hlinux/types.h
Detected Declarations
struct genradix_rootstruct __genradixstruct genradix_nodestruct genradix_iterfunction genradix_depth_shiftfunction sizefunction genradix_root_to_depthfunction genradix_free_nodefunction __idx_to_offsetfunction __genradix_iter_peek_prevfunction __genradix_iter_rewind
Annotated Snippet
struct __genradix {
struct genradix_root *root;
};
struct genradix_node {
union {
/* Interior node: */
struct genradix_node *children[GENRADIX_ARY];
/* Leaf: */
u8 data[GENRADIX_NODE_SIZE];
};
};
static inline struct genradix_node *genradix_alloc_node(gfp_t gfp_mask)
{
return kzalloc(GENRADIX_NODE_SIZE, gfp_mask);
}
static inline void genradix_free_node(struct genradix_node *node)
{
kfree(node);
}
/*
* NOTE: currently, sizeof(_type) must not be larger than GENRADIX_NODE_SIZE:
*/
#define __GENRADIX_INITIALIZER \
{ \
.tree = { \
.root = NULL, \
} \
}
/*
* We use a 0 size array to stash the type we're storing without taking any
* space at runtime - then the various accessor macros can use typeof() to get
* to it for casts/sizeof - we also force the alignment so that storing a type
* with a ridiculous alignment doesn't blow up the alignment or size of the
* genradix.
*/
#define GENRADIX(_type) \
struct { \
struct __genradix tree; \
_type type[0] __aligned(1); \
}
#define DEFINE_GENRADIX(_name, _type) \
GENRADIX(_type) _name = __GENRADIX_INITIALIZER
/**
* genradix_init - initialize a genradix
* @_radix: genradix to initialize
*
* Does not fail
*/
#define genradix_init(_radix) \
do { \
*(_radix) = (typeof(*_radix)) __GENRADIX_INITIALIZER; \
} while (0)
void __genradix_free(struct __genradix *);
/**
* genradix_free: free all memory owned by a genradix
* @_radix: the genradix to free
*
* After freeing, @_radix will be reinitialized and empty
*/
#define genradix_free(_radix) __genradix_free(&(_radix)->tree)
static inline size_t __idx_to_offset(size_t idx, size_t obj_size)
{
if (__builtin_constant_p(obj_size))
BUILD_BUG_ON(obj_size > GENRADIX_NODE_SIZE);
else
BUG_ON(obj_size > GENRADIX_NODE_SIZE);
if (!is_power_of_2(obj_size)) {
size_t objs_per_page = GENRADIX_NODE_SIZE / obj_size;
return (idx / objs_per_page) * GENRADIX_NODE_SIZE +
(idx % objs_per_page) * obj_size;
} else {
return idx * obj_size;
}
}
Annotation
- Immediate include surface: `asm/page.h`, `linux/bug.h`, `linux/limits.h`, `linux/log2.h`, `linux/math.h`, `linux/slab.h`, `linux/types.h`.
- Detected declarations: `struct genradix_root`, `struct __genradix`, `struct genradix_node`, `struct genradix_iter`, `function genradix_depth_shift`, `function size`, `function genradix_root_to_depth`, `function genradix_free_node`, `function __idx_to_offset`, `function __genradix_iter_peek_prev`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
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.