__xa_cmpxchg(9)
π¦ __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:
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_insert(9),xa_store_range(9)xas_get_order(9),xa_get_order(9)__xa_alloc(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, 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
- 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