lib/xarray.c
Source file repositories/reference/linux-study-clean/lib/xarray.c
File Facts
- System
- Linux kernel
- Corpus path
lib/xarray.c- Extension
.c- Size
- 65269 bytes
- Lines
- 2482
- 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/export.hlinux/list.hlinux/slab.hlinux/xarray.hradix-tree.h
Detected Declarations
function xa_lock_typefunction xas_lock_typefunction xas_unlock_typefunction xa_track_freefunction xa_zero_busyfunction xa_mark_setfunction xa_mark_clearfunction node_get_markfunction node_set_markfunction node_clear_markfunction node_any_markfunction node_mark_allfunction xas_squash_marksfunction get_offsetfunction xas_set_offsetfunction xas_move_indexfunction xas_next_offsetfunction xas_loadfunction xa_node_freefunction xas_nomemfunction xas_nomemfunction __xas_nomemfunction xas_updatefunction xas_sizefunction xas_maxfunction max_indexfunction xas_shrinkfunction xas_delete_nodefunction xas_free_nodesfunction xas_expandfunction xas_createfunction xas_create_rangefunction update_nodefunction xas_storefunction xas_get_markfunction xas_set_markfunction xas_clear_markfunction xas_init_marksfunction node_get_marksfunction node_mark_slotsfunction node_set_marksfunction __xas_init_node_for_splitfunction xas_split_allocfunction xas_splitfunction xas_try_split_min_orderfunction xas_try_splitfunction xas_pausefunction __xas_prev
Annotated Snippet
if (find_next_bit(marks, limit, xas->xa_offset + 1) != limit) {
__set_bit(xas->xa_offset, marks);
bitmap_clear(marks, xas->xa_offset + 1, xas->xa_sibs);
}
if (mark == XA_MARK_MAX)
break;
mark_inc(mark);
}
}
/* extracts the offset within this node from the index */
static unsigned int get_offset(unsigned long index, struct xa_node *node)
{
return (index >> node->shift) & XA_CHUNK_MASK;
}
static void xas_set_offset(struct xa_state *xas)
{
xas->xa_offset = get_offset(xas->xa_index, xas->xa_node);
}
/* move the index either forwards (find) or backwards (sibling slot) */
static void xas_move_index(struct xa_state *xas, unsigned long offset)
{
unsigned int shift = xas->xa_node->shift;
xas->xa_index &= ~XA_CHUNK_MASK << shift;
xas->xa_index += offset << shift;
}
static void xas_next_offset(struct xa_state *xas)
{
xas->xa_offset++;
xas_move_index(xas, xas->xa_offset);
}
static void *set_bounds(struct xa_state *xas)
{
xas->xa_node = XAS_BOUNDS;
return NULL;
}
/*
* Starts a walk. If the @xas is already valid, we assume that it's on
* the right path and just return where we've got to. If we're in an
* error state, return NULL. If the index is outside the current scope
* of the xarray, return NULL without changing @xas->xa_node. Otherwise
* set @xas->xa_node to NULL and return the current head of the array.
*/
static void *xas_start(struct xa_state *xas)
{
void *entry;
if (xas_valid(xas))
return xas_reload(xas);
if (xas_error(xas))
return NULL;
entry = xa_head(xas->xa);
if (!xa_is_node(entry)) {
if (xas->xa_index)
return set_bounds(xas);
} else {
if ((xas->xa_index >> xa_to_node(entry)->shift) > XA_CHUNK_MASK)
return set_bounds(xas);
}
xas->xa_node = NULL;
return entry;
}
static __always_inline void *xas_descend(struct xa_state *xas,
struct xa_node *node)
{
unsigned int offset = get_offset(xas->xa_index, node);
void *entry = xa_entry(xas->xa, node, offset);
xas->xa_node = node;
while (xa_is_sibling(entry)) {
offset = xa_to_sibling(entry);
entry = xa_entry(xas->xa, node, offset);
if (node->shift && xa_is_node(entry))
entry = XA_RETRY_ENTRY;
}
xas->xa_offset = offset;
return entry;
}
/**
* xas_load() - Load an entry from the XArray (advanced).
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/export.h`, `linux/list.h`, `linux/slab.h`, `linux/xarray.h`, `radix-tree.h`.
- Detected declarations: `function xa_lock_type`, `function xas_lock_type`, `function xas_unlock_type`, `function xa_track_free`, `function xa_zero_busy`, `function xa_mark_set`, `function xa_mark_clear`, `function node_get_mark`, `function node_set_mark`, `function node_clear_mark`.
- 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.