xa_for_each(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… xa_for_each β€” the manual page, but make it make sense

okay so this is xa_for_each(9) from the Kernel API Manual, and honestly? she's iconic. let's get into it 🫢


✨ NAME ✨

xa_for_each β€” the iterator that walks over all the present entries in an XArray. that's it, that's the vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

xa_for_each (xa , index , entry );

πŸŽ€ ARGUMENTS πŸŽ€

  • xa β€” your XArray. the whole thing. the main character, lowkey πŸ‘‘
  • index β€” the index of an entry. yes bestie, you track where you're at with this πŸ’…
  • entry β€” the entry that got retrieved from the array. this is what you came for ✨

πŸ’– DESCRIPTION πŸ’–

so during the iteration, entry is gonna hold the value of whatever entry is stored in xa at index. literally that simple, no cap.

and here's the cute part β€” you're allowed to modify index mid-iteration if you wanna skip some indices or reprocess them. honestly? flexible queen behaviour. 🧚 it's also safe to modify the array while you're iterating. go off.

at the end of the iteration, entry gets set to NULL and index will have a value less than or equal to max. so don't be weirded out when it ends like that, that's just how she wraps up 🎬

now for the part where you gotta pay attention, bestie, because this is the whole comparison saga:

  • xa_for_each is O(n.log(n)) while xas_for_each is O(n). different tax brackets, fr fr 😭
  • with xas_for_each you have to handle your own locking β€” yes, your own. and if you have to unlock after each iteration, it will also end up being O(n.log(n)). so like… the speed flex kind of evaporates πŸ’€
  • xa_for_each will spin if it hits a retry entry. so if you actually intend to see retry entries, you should use the xas_for_each iterator instead. periodt.
  • xas_for_each will expand into more inline code than xa_for_each. so there's a tradeoff, iykyk 🌈

🌟 CONTEXT 🌟

Any context. she takes and releases the RCU lock. that's it. she's low maintenance πŸŽ€


πŸ”₯ SEE ALSO πŸ”₯

okay the cross-reference list is long long, but every single one of these deserves their moment. no skips, no cuts, we respect the whole squad πŸ’œ


lowkey reminder bestie: xa_for_each will spin on a retry entry, and it's O(n.log(n)) β€” if that's a problem for your use case, xas_for_each is right there but you gotta do your own locking. know the difference, okay? πŸ’…

and that's the page!! mwah πŸ’‹ this one came to you from ./include/linux, dated October 2026, living in the Kernel API Manual β€” go forth and iterate, you absolute legend πŸŒˆβ­πŸ‘‘

πŸ“¦ where this page comes from