__xa_cmpxchg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ __xa_cmpxchg β€” the "compare and swap but make it XArray" girlie ✨

okay so this is a page from the Kernel API Manual, and we're talking about __xa_cmpxchg(9). buckle up bestie, it's actually so clean πŸ’…


✨ NAME ✨

__xa_cmpxchg β€” conditionally replace an entry in the XArray. that's it. that's the whole vibe πŸŽ€


🌸 SYNOPSIS 🌸

void * __xa_cmpxchg (struct xarray *xa , unsigned long index , void *old
, void *entry , gfp_t gfp );

literally just five little args, she's lowkey minimal 🫢


πŸ“ ARGUMENTS πŸ“

  • xa β€” the XArray. your main character data structure πŸ‘‘
  • index β€” index into array. where in the array we're poking around πŸ”
  • old β€” old value to test against. the vibe check value, basically 🌈
  • entry β€” new value to place in array. the glow-up πŸ’–
  • gfp β€” memory allocation flags. the rules for how we're allowed to grab memory ✨

πŸ’œ DESCRIPTION πŸ’œ

okay so first things first, and this is ngl the most important part: you must already be holding the xa_lock when calling this function. no cap. that's non-negotiable πŸ™ˆ

here's the tea though β€” it will drop the lock if it needs to allocate memory, and then it reacquires it afterwards. so she's flexible, but she's coming back for that lock, bestie πŸ’…

so how does it actually work? if the entry at index is the same as old, it gets replaced with entry. and if the return value is equal to old, then the exchange was successful β€” slay βœ…

fr fr, check that return value against old. that's how you know if you actually ate or not πŸ”₯

🧚 CONTEXT 🧚

Any context. she's versatile like that πŸ’β€β™€οΈ

Expects xa_lock to be held on entry. (yes we said it already, but she's saying it again because it matters)

May release and reacquire xa_lock if gfp flags permit. iconic lock choreography honestly 🩰


⭐ RETURN ⭐

the old value at this index, or xa_err if an error happened 😭


πŸ”₯ SEE ALSO πŸ”₯

this is the whole friend group, all from the kernel file ./lib/xarray.c:

like, the whole extended family showed up. iykyk 🫢


and that's the page, bestie! brought to you from ./lib, dated October 2026, and yes she's still out here being __xa_cmpxchg(9) πŸ’…βœ¨ mwah, go hold that lock πŸŽ€

πŸ“¦ where this page comes from