__xa_alloc(9)
π __xa_alloc β Kernel API Manual, bestie edition π
Okay so picture this: you're in the Kernel API Manual and you need somewhere β¨iconicβ¨ to stash an entry in the XArray. That's literally this function. Welcome to the group chat, pull up a chair π
πΈ NAME πΈ
__xa_alloc β Find somewhere to store this entry in the XArray. That's it, that's the whole job, and it does it flawlessly π
β¨ SYNOPSIS β¨
int __xa_alloc (struct xarray *xa , u32 *id , void *entry , struct
xa_limit limit , gfp_t gfp );
π¦ ARGUMENTS π¦
xaβ the XArray. Your main character. Everything happens here π«Άidβ Pointer to ID. It's gonna get written to, so bestie, treat it with respect.entryβ New entry. The thing you're dropping in.limitβ Range for allocated ID. The vibe check that your ID has to pass.gfpβ Memory allocation flags. Standard kernel fare, no notes.
π DESCRIPTION π
So what it actually does: it finds an empty entry in xa between limit.min and limit.max, stores the index into the id pointer, then stores the entry at that index. Clean, sequential, iconic.
And here's the gorgeous part β a concurrent lookup will not see an uninitialised id. Not today, not ever. The ordering is handled, no cap π₯
β οΈ Real talk though: this must only be operated on an xarray initialized with flagXA_FLAGS_ALLOCset inxa_init_flags. Do not come in here with a plain xarray and expect slay. It will not slay.
π CONTEXT π
Any context. Yes, any. Flexible queen π
It expects xa_lock to be held on entry. It may release and reacquire xa_lock if the gfp flags permit β so lowkey don't be weird about it holding the lock the whole time.
β RETURN β
0β success, we ate π-ENOMEMβ memory could not be allocated π-EBUSYβ there are no free entries inlimit, the range is full, it's giving sold out π
π§ SEE ALSO π§
Kernel file ./lib/xarray.c and the whole extended universe:
xas_load(9),xas_nomem(9),xas_free_nodes(9),xas_create_range(9),xas_store(9),xas_get_mark(9),xas_set_mark(9),xas_clear_mark(9),xas_init_marks(9),xas_split_alloc(9),xas_split(9),xas_try_split_min_order(9),xas_try_split(9),xas_pause(9),xas_find(9),xas_find_marked(9),xas_find_conflict(9),xa_load(9),__xa_erase(9),xa_erase(9),__xa_store(9),xa_store(9),__xa_cmpxchg(9),__xa_insert(9),xa_store_range(9),xas_get_order(9),xa_get_order(9),__xa_alloc_cyclic(9),__xa_set_mark(9),__xa_clear_mark(9),xa_get_mark(9),xa_set_mark(9),xa_clear_mark(9),xa_find(9),xa_find_after(9),xa_extract(9),xa_delete_node(9),xa_destroy(9)
Like, all of them. Every single one. Go read them, I'll wait π
And that's the page!! π Sourced from ./lib, dated October 2026, filed under __xa_alloc(9) β mwah, bye bestie πβ¨ππ¦
π¦ 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