xa_for_each_range(9)
π xa_for_each_range β from the Kernel API Manual, section 9 π
okay bestie, so this one is literally called xa_for_each_range(9) and it lives in the Kernel API Manual. let's get into it β¨
πΈ NAME πΈ
xa_for_each_range β bestie, it iterates over a portion of an XArray. not the whole thing. a portion. we're being picky and we're being efficient π
β¨ SYNOPSIS β¨
xa_for_each_range (xa , index , entry , start , last );
that's the whole vibe. five things go in, magic comes out πͺ
π«Ά ARGUMENTS π«Ά
xaβ the XArray itself. the container. the main character of this whole operation πindexβ the index of an entry. it's your lil position tracker, and yes it moves π―entryβ the entry retrieved from the array. this is the prize you get each loop πstartβ the first index to retrieve from the array. where the party begins πlastβ the last index to retrieve from the array. where the party ends, sadly π
π¦ DESCRIPTION π¦
so during the iteration, entry will have the value of the entry stored in xa at index. literally what it says on the tin, no cap β¨
and here's the cute part: you may modify index during the iteration if you want to skip or reprocess indices. iconic behaviour. you're driving, not the loop ππ¨ and yes β it is safe to modify the array during the iteration. go off, bestie.
at the end of the iteration, entry will be set to NULL and index will have a value less than or equal to max. so no weird leftovers, no zombie pointers. clean exit π§Ό
now the performance tea, and this part actually matters so listen up βοΈ:
xa_for_each_range is O(n.log(n)) while xas_for_each is O(n). okay so the other one is technically faster, BUT π β you have to handle your own locking with xas_for_each, and if you have to unlock after each iteration, it will also end up being O(n.log(n)). so the classic "it depends" situation, we love that for us π
β οΈ also important:xa_for_each_rangewill spin if it hits a retry entry. like, spin. forever-ish. if you intend to see retry entries, you should use thexas_for_eachiterator instead. don't say i didn't warn you π
and one last trade-off for the spreadsheet girlies: the xas_for_each iterator will expand into more inline code than xa_for_each_range. so it's a whole size-vs-flexibility moment β¨π
π CONTEXT π
any context. literally any. it takes and releases the RCU lock, so it handles its own biz π«Ά no preconditions, no drama.
π₯ SEE ALSO π₯
Kernel file ./include/linux/xarray.h β plus this whole friend group π:
xa_mk_value(9)xa_to_value(9)xa_is_value(9)xa_tag_pointer(9)xa_untag_pointer(9)xa_pointer_tag(9)xa_is_zero(9)xa_is_err(9)xa_err(9)struct xa_limit(9)struct xarray(9)DEFINE_XARRAY_FLAGS(9)DEFINE_XARRAY(9)DEFINE_XARRAY_ALLOC(9)DEFINE_XARRAY_ALLOC1(9)xa_init_flags(9)xa_init(9)xa_empty(9)xa_marked(9)xa_for_each_start(9)xa_for_each(9)xa_for_each_marked(9)xa_store_bh(9)xa_store_irq(9)xa_erase_bh(9)xa_erase_irq(9)xa_cmpxchg(9)xa_cmpxchg_bh(9)xa_cmpxchg_irq(9)xa_insert(9)xa_insert_bh(9)xa_insert_irq(9)xa_alloc(9)xa_alloc_bh(9)xa_alloc_irq(9)xa_alloc_cyclic(9)xa_alloc_cyclic_bh(9)xa_alloc_cyclic_irq(9)xa_reserve(9)xa_reserve_bh(9)xa_reserve_irq(9)xa_release(9)xa_is_sibling(9)xa_is_retry(9)xa_is_advanced(9)xa_update_node_t(9)XA_STATE(9)XA_STATE_ORDER(9)xas_error(9)xas_set_err(9)xas_invalid(9)xas_valid(9)xas_is_node(9)xas_reset(9)xas_retry(9)xas_reload(9)xas_set(9)xas_advance(9)xas_set_order(9)xas_set_update(9)xas_next_entry(9)xas_next_marked(9)xas_for_each(9)xas_for_each_marked(9)xas_for_each_conflict(9)xas_prev(9)xas_next(9)
and that's the page, bestie π§π this one ships out of ./include/linux, October 2026, and it's filed under xa_for_each_range(9) β go iterate responsibly, mwah ππ
π¦ 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