list_for_each_entry_rcu(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… list_for_each_entry_rcu β€” the Kernel API Manual page, bestie edition

okay so you found list_for_each_entry_rcu(9) and you're like "what is this, why is it everywhere in the kernel" β€” don't panic, I got you. this is the RCU list-walker. it's iconic, it's everywhere, and it's literally just a for-loop with vibes. let's go πŸ¦‹


✨ SYNOPSIS ✨

list_for_each_entry_rcu (pos , head , member , cond... );

yes bestie, the spacing is exactly like that, don't come for me, that's how the manpage wrote it πŸ’€


πŸŽ€ ARGUMENTS πŸŽ€

  • pos β€” the type * you use as your loop cursor. this is your main character pointer, the one that walks the list. every iteration it's pointing at something new. she's booked and busy.
  • head β€” the head for your list. the anchor. the starting point. the group chat that everyone's in 🌸
  • member β€” the name of the list_head inside the struct. so like, if your struct has a struct list_head foo inside it, you pass foo here. it's how the macro finds the list node hiding inside your struct, iykyk.
  • cond β€” optional lockdep expression, for when you're calling this from a non-RCU-protection situation. it's the ... in the synopsis, so it's optional-optional πŸ’…

πŸ’– DESCRIPTION πŸ’–

so here's the tea: this list-traversal primitive may safely run concurrently with the _rcu list-mutation primitives β€” think list_add_rcu and friends β€” as long as the traversal is guarded by rcu_read_lock. that's the whole deal. that's the contract. πŸ”₯

no cap, the "as long as it's guarded by rcu_read_lock" part is not optional. skip it and you're in undefined-behaviour territory. she will not be nice about it 😭

other walkers can be adding and removing stuff while you iterate, and you're fine β€” because RCU. slay. periodt.


πŸ‘‘ SEE ALSO πŸ‘‘

fr fr go read the source, it's right here in the kernel file:

./include/linux/rculist.h

and then the whole friend group, alphabetically-ish, all of them:

like, the whole roster. read them all. or at least the ones you need. no pressure 🫢


🌈 the sign-off 🌈

this page lives in ./include/linux, and it's stamped October 2026. so go forth, iterate your RCU lists, hold that read lock, and remember: main character energy only. mwah πŸ’‹ ✨

πŸ“¦ where this page comes from