xa_alloc_cyclic(9)
π xa_alloc_cyclic(9) β like, the Kernel API Manual page, but make it make sense β¨
okay so bestie, gather round, because this one is from the Kernel API Manual and it's genuinely so useful once you get the vibe. The function is xa_alloc_cyclic, and it is literally the "find me a spot and put my thing there" icon of the XArray world. π
π NAME π
xa_alloc_cyclic β find somewhere to store this entry in the XArray. that's it. that's the whole assignment. π
πΈ SYNOPSIS πΈ
int xa_alloc_cyclic (struct xarray *xa , u32 *id , void *entry , struct
xa_limit limit , u32 *next , gfp_t gfp );
look at her. six params. main character energy fr fr. π¦
β¨ ARGUMENTS β¨
xaβ the XArray. your canvas. your little data home. πidβ pointer to the ID. the function writes the index it picked in here. πentryβ the new entry. the thing you actually want to store. πlimitβ the range of allocated ID. you get a min and a max and you do not stray outside them, periodt. π§nextβ pointer to next ID to allocate. it's where the search starts (and it wraps around if it runs off the end, iykyk). πgfpβ memory allocation flags. the whole "can I sleep or not" situation. π΄
π¦ DESCRIPTION π¦
so the way this works: it finds an empty entry in xa somewhere between limit.min and limit.max β inclusive vibes β then stores the index into the id pointer, and then stores the entry at that index. β¨
and the order matters bestie: because it does the id first, a concurrent lookup will not see an uninitialised id. slay. π
the search for an empty entry starts at next, and it will wrap around if necessary. cyclic, see? it's giving circular. π
β οΈ okay, important one: this must only be operated on an xarray initialized with the flagXA_FLAGS_ALLOCset inxa_init_flags. no cap, don't skip this. π
also ngl, if you're a caller who actually cares whether wrapping has occurred, you should use __xa_alloc_cyclic instead. the info is there, just not from this one. π
π CONTEXT π
any context, bestie. it takes and releases the xa_lock. and it may sleep if the gfp flags permit β so like, know your flags before you commit. π
β RETURN β
0if the allocation succeeded π-ENOMEMif memory could not be allocated π-EBUSYif there are no free entries inlimitπ«
three outcomes. that's it. go off. π₯
π SEE ALSO π
so there's a whole friend group here, and honestly? they're all iconic. first up, the kernel file itself lives at ./include/linux/xarray.h. and then:
the value-detective squad:
xa_mk_value(9),xa_to_value(9),xa_is_value(9),xa_tag_pointer(9),xa_untag_pointer(9),xa_pointer_tag(9),xa_is_zero(9),xa_is_err(9),xa_err(9)
the struct girlies:
struct xa_limit(9),struct xarray(9)
defining + initialising:
DEFINE_XARRAY_FLAGS(9),DEFINE_XARRAY(9),DEFINE_XARRAY_ALLOC(9),DEFINE_XARRAY_ALLOC1(9),xa_init_flags(9),xa_init(9),xa_empty(9),xa_marked(9)
iteration nation:
storing + erasing (the bh/irq cinematic universe):
compare-and-swap crew:
inserting:
the alloc family (our girl's relatives):
reserve + release:
little status checks:
the XA_STATE macros:
the xas_* extended family (there are SO many, drink some water):
xas_error(9),xas_set_err(9),xas_invalid(9),xas_valid(9),xas_is_node(9),xas_reset(9),xas_retry(9),xas_reload(9),xas_set(9),xas_advance(9),xas_set_order(9),xas_set_update(9),xas_next_entry(9),xas_next_marked(9),xas_for_each(9),xas_for_each_marked(9),xas_for_each_conflict(9),xas_prev(9),xas_next(9)
and that's the page, bestie!! π«Ά coming at you from ./include/linux and dated October 2026 β mwah, go allocate something cyclic responsibly, ily, bye!! π§π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms