css_for_each_child(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’« css_for_each_child(9) πŸ’«

okay so this is a page from the Kernel API Manual β€” section 9, kernel API, bestie. it's called css_for_each_child and it's about looping through a css's children. yes, that kind of css. no, not the styling one 😭 this is cgroups-land.


πŸŽ€ NAME πŸŽ€

css_for_each_child β€” iterate through children of a css

✨ SYNOPSIS ✨

css_for_each_child (pos , parent );

🌸 ARGUMENTS 🌸

  • pos β€” the css * you're using as the loop cursor. this is your little "where am i rn" pointer, she's the main character of the loop πŸ’…
  • parent β€” the css whose children you're walking through. the mom, basically πŸ‘‘

πŸ’– DESCRIPTION πŸ’–

so you walk parent's children. that's the whole vibe. but β€” and this is the important part β€” it must be called under rcu_read_lock. not optional, no cap. πŸ”’

here's the situation with visibility, and honestly it's giving "read the fine print":

  • if a subsystem synchronizes ->css_online with the start of the iteration, then a css that's finished ->css_online is guaranteed to show up in future iterations, and it will stay visible until the last reference is put. slay, stability. πŸ¦‹
  • a css that hasn't finished ->css_online, or that already finished ->css_offline, may pop up during traversal. like, surprise guest energy. πŸ™ˆ
  • so it's each subsystem's own responsibility to synchronize against things going on/offline. nobody's gonna do it for you, bestie.

also! you're allowed to temporarily drop the RCU read lock during iteration. freedom πŸ•ŠοΈ but β€” the caller is responsible for making sure pos stays accessible until the start of the next iteration. how? for example, by bumping the css refcnt. keep your cursor alive, basically. 🫢

⚠️ quick recap of the two hard rules: call it under rcu_read_lock, and if you drop the lock mid-loop, you keep pos reachable (bump that refcnt). otherwise it's on you, fr fr.

πŸ‘€ SEE ALSO πŸ‘€

kernel file ./include/linux/cgroup.h, plus the whole friend group:


and that's the whole page, periodt. πŸ’œ sign-off time: this one lives under ./include/linux in the kernel tree, dated October 2026, and it's css_for_each_child(9) β€” see you at the next iteration πŸ§šβ€β™€οΈβœ¨

πŸ“¦ where this page comes from