xa_alloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ xa_alloc(9) β€” Kernel API Manual πŸ’…

okay so bestie, this is the XArray allocation moment where the kernel goes β€œfind me an empty little spot for this entry” and the spot selection is literally the whole plot. πŸŽ€

🌸 NAME 🌸

xa_alloc - Find somewhere to store this entry in the XArray.

πŸ¦‹ SYNOPSIS πŸ¦‹

int xa_alloc (struct xarray *xa , u32 *id , void *entry , struct
       xa_limit limit , gfp_t gfp );

πŸŽ€ ARGUMENTS πŸŽ€

  • xa β€” XArray. the whole data structure bestie, no cap πŸ’–
  • id β€” Pointer to ID. this is where the chosen index gets written ✨
  • entry β€” New entry. the thing you're storing 🫢
  • limit β€” Range of ID to allocate. the allowed ID zone 🌈
  • gfp β€” Memory allocation flags. the β€œcan I nap while doing this?” flags 😴

πŸ’– DESCRIPTION πŸ’–

Okay so here's the tea: xa_alloc 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. A concurrent lookup will not see an uninitialised id. periodt. πŸ’…

Must only be operated on an xarray initialized with flag XA_FLAGS_ALLOC set in xa_init_flags. no cap, that's mandatory β€” this is not a casual suggestion, bestie 🚨

πŸ¦‹ CONTEXT πŸ¦‹

Any context. Takes and releases the xa_lock. May sleep if the gfp flags permit. so yes, it can catch a nap β€” but only if the flags say it's allowed πŸ˜­πŸ’€

⭐ RETURN ⭐

0 on success, -ENOMEM if memory could not be allocated or -EBUSY if there are no free entries in limit. That's the whole vibe check. πŸ’€

🌈 SEE ALSO 🌈

Kernel file ./include/linux/xarray.h plus this entire iconic little squad:


Signed off from ./include/linux, October 2026 β€” this is xa_alloc(9), bestie. πŸ«ΆπŸ’–

πŸ“¦ where this page comes from