lib/maple_tree.c
Source file repositories/reference/linux-study-clean/lib/maple_tree.c
File Facts
- System
- Linux kernel
- Corpus path
lib/maple_tree.c- Extension
.c- Size
- 174591 bytes
- Lines
- 7046
- 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/maple_tree.hlinux/xarray.hlinux/types.hlinux/export.hlinux/slab.hlinux/limits.hasm/barrier.htrace/events/maple_tree.h
Detected Declarations
function mt_free_bulkfunction mt_return_sheaffunction mt_refill_sheaffunction ma_free_rcufunction mt_set_heightfunction mas_mt_heightfunction mt_attrfunction mte_node_typefunction ma_is_densefunction ma_is_leaffunction mte_is_leaffunction mt_is_reservedfunction mas_set_errfunction mas_is_ptrfunction mas_is_startfunction mas_is_nonefunction mas_is_pausedfunction mas_is_overflowfunction mas_is_underflowfunction mte_to_matfunction mas_mnfunction mte_set_node_deadfunction ma_init_slotfunction mte_has_nullfunction ma_is_rootfunction mte_is_rootfunction mas_is_root_limitsfunction mt_is_allocfunction mte_parent_shiftfunction mte_parent_slot_maskfunction mas_parent_typefunction mas_set_parentfunction mte_parent_slotfunction mte_parentfunction ma_dead_nodefunction mte_dead_nodefunction ma_pivotsfunction ma_gapsfunction mas_safe_pivotfunction mas_safe_minfunction mte_set_pivotfunction ma_slotsfunction mt_write_lockedfunction mt_lockedfunction mas_slot_lockedfunction mas_slotfunction mas_rootfunction mas_root_locked
Annotated Snippet
if (unlikely(pivots[MAPLE_RANGE64_SLOTS - 2])) {
slots = mn->mr64.slot;
next = mt_slot_locked(mt, slots,
MAPLE_RANGE64_SLOTS - 1);
if (unlikely((mte_to_node(next) &&
mte_node_type(next))))
return; /* no metadata, could be node */
}
fallthrough;
case maple_arange_64:
meta = ma_meta(mn, type);
break;
default:
return;
}
meta->gap = 0;
meta->end = 0;
}
/*
* ma_meta_end() - Get the data end of a node from the metadata
* @mn: The maple node
* @mt: The maple node type
*/
static inline unsigned char ma_meta_end(struct maple_node *mn,
enum maple_type mt)
{
struct maple_metadata *meta = ma_meta(mn, mt);
return meta->end;
}
/*
* ma_meta_gap() - Get the largest gap location of a node from the metadata
* @mn: The maple node
*/
static inline unsigned char ma_meta_gap(struct maple_node *mn)
{
return mn->ma64.meta.gap;
}
/*
* ma_set_meta_gap() - Set the largest gap location in a nodes metadata
* @mn: The maple node
* @mt: The maple node type
* @offset: The location of the largest gap.
*/
static inline void ma_set_meta_gap(struct maple_node *mn, enum maple_type mt,
unsigned char offset)
{
struct maple_metadata *meta = ma_meta(mn, mt);
meta->gap = offset;
}
/*
* mat_add() - Add a @dead_enode to the ma_topiary of a list of dead nodes.
* @mat: the ma_topiary, a linked list of dead nodes.
* @dead_enode: the node to be marked as dead and added to the tail of the list
*
* Add the @dead_enode to the linked list in @mat.
*/
static inline void mat_add(struct ma_topiary *mat,
struct maple_enode *dead_enode)
{
mte_set_node_dead(dead_enode);
mte_to_mat(dead_enode)->next = NULL;
if (!mat->tail) {
mat->tail = mat->head = dead_enode;
return;
}
mte_to_mat(mat->tail)->next = dead_enode;
mat->tail = dead_enode;
}
static void mt_free_walk(struct rcu_head *head);
static void mt_destroy_walk(struct maple_enode *enode, struct maple_tree *mt,
bool free);
/*
* mas_mat_destroy() - Free all nodes and subtrees in a dead list.
* @mas: the maple state
* @mat: the ma_topiary linked list of dead nodes to free.
*
* Destroy walk a dead list.
*/
static void mas_mat_destroy(struct ma_state *mas, struct ma_topiary *mat)
{
Annotation
- Immediate include surface: `linux/maple_tree.h`, `linux/xarray.h`, `linux/types.h`, `linux/export.h`, `linux/slab.h`, `linux/limits.h`, `asm/barrier.h`, `trace/events/maple_tree.h`.
- Detected declarations: `function mt_free_bulk`, `function mt_return_sheaf`, `function mt_refill_sheaf`, `function ma_free_rcu`, `function mt_set_height`, `function mas_mt_height`, `function mt_attr`, `function mte_node_type`, `function ma_is_dense`, `function ma_is_leaf`.
- 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.