__xa_alloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– __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 flag XA_FLAGS_ALLOC set in xa_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 in limit, the range is full, it's giving sold out πŸ’€

🧚 SEE ALSO 🧚

Kernel file ./lib/xarray.c and the whole extended universe:

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