xa_for_each_marked(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… xa_for_each_marked β€” Kernel API Manual, bestie edition ✨

okay so picture this: you're deep in the kernel, you've got an XArray, and some of the entries in it are tagged β€” marked, if you will β€” and you only want the marked ones. That's the whole gig. Welcome to xa_for_each_marked(9), brought to you by the Kernel API Manual. Let's get into it πŸŽ€


✨ NAME ✨

xa_for_each_marked β€” the iterator that goes through all the marked entries in an XArray. Only the marked ones. It's giving selective, and honestly? Obsessed. πŸ‘‘


🌸 SYNOPSIS 🌸

xa_for_each_marked (xa , index , entry , filter );

yes, that's the whole signature, no cap. Put it in your code and let it cook πŸ“


πŸ¦‹ ARGUMENTS πŸ¦‹

  • xa β€” the XArray itself. The main character. The whole vibe lives here.
  • index β€” the index of the entry. It's your cursor, it's your GPS, it's the little dot on the map πŸ—ΊοΈ
  • entry β€” the entry you got back from the array. This is the thing you actually wanted, the payoff, the slay πŸ’…
  • filter β€” the selection criterion. The bouncer at the door. If an entry doesn't match filter, it does not get in. Periodt. 🚫

πŸ’– DESCRIPTION πŸ’–

So here's what's happening while you iterate: entry will have the value of the entry stored in xa at index. Simple, clean, iconic.

The iteration skips every entry in the array that doesn't match filter. Not interested, moving on, next πŸ’€

You may modify index during the iteration if you want to skip indices or reprocess indices β€” yes bestie, you have permission, it's literally fine. And it's safe to modify the array during the iteration too. Go off, be free, live your truth 🌈

At the end of the iteration, entry will be set to NULL, and index will have a value less than or equal to max. That's just how it wraps up. Clean exit, no loose ends 🫢

Now, the performance tea β˜• β€” and this part matters, ngl:

  • xa_for_each_marked is O(n.log(n)), while xas_for_each_marked is O(n).
  • 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)).
  • xa_for_each_marked will spin if it hits a retry entry. πŸŒ€ Like, it's just gonna sit there spinning. If you intend to see retry entries, you should use the xas_for_each_marked iterator instead.
  • Heads up though: the xas_for_each_marked iterator will expand into more inline code than xa_for_each_marked. Trade-offs, babe. Everything's a trade-off. 😭
⚠️ fr fr read that spin warning again. If retry entries are in your future, xa_for_each_marked is not the one. Use xas_for_each_marked.

πŸ’œ CONTEXT πŸ’œ

Any context. Literally any. It takes and releases the RCU lock on its own. Low maintenance, high value, we love to see it 🧚


⭐ SEE ALSO ⭐

Kernel file ./include/linux/xarray.h, plus the whole friend group:


and that's the page!! πŸ’– huge thanks to the fine folks over at ./include/linux β€” this one dropped October 2026, so mark your calendars bestie πŸ—“οΈβœ¨ go iterate over something marked, you've got this, mwah πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from