css_next_descendant_pre(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… css_next_descendant_pre(9) β€” find the next descendant for pre-order walk

okay bestie, quick vibe check: this is a page from the Kernel API Manual, and it's genuinely one of those lil functions that runs the whole cgroup family tree walk. not me being dramatic β€” it's literally the iterator logic behind css_for_each_descendant_pre. let's go πŸŽ€


✨ SYNOPSIS ✨

struct cgroup_subsys_state * css_next_descendant_pre (struct
cgroup_subsys_state *pos , struct cgroup_subsys_state *root );

like, that's the whole thing. she takes two css pointers and hands you back another one πŸ¦‹


🌸 ARGUMENTS 🌸

  • pos β€” where you're standing right now, bestie. pass NULL to kick off the traversal from scratch 🏁
  • root β€” the css whose descendants we're walking. she's the main character of this whole operation πŸ‘‘

πŸ’– DESCRIPTION πŸ’–

so this one is meant to be used by css_for_each_descendant_pre β€” it's the lil engine that finds the next descendant to visit when you're doing a pre-order traversal of root's descendants. and yes, root is included in the iteration β€” she's literally the first node visited. no cap πŸ‘‘

now, the locking tea: this function needs cgroup_mutex or RCU read locking. but listen β€” it does not require the whole traversal to live inside a single critical section. that's the slay part. also, you do not have to hold onto a reference to pos. πŸ’… she'll still hand you the correct next descendant as long as both pos and root are accessible and pos is a descendant of root. iconic behaviour, fr fr.

about visibility (this is the part where you gotta pay attention, bestie 🫢): if a subsystem synchronizes ->css_online with the start of iteration, then a css that finished ->css_online is guaranteed to be visible in future iterations and will stay visible until the last reference is put. but a css that hasn't finished ->css_online, or one that already finished ->css_offline, may still show up during traversal 😭 β€” it's genuinely just out there living its life. so it is each subsystem's responsibility to synchronize against on/offlining. that's the assignment, not ours ✨

lowkey important: the on/offlining synchronization is on you (well, on each subsystem). this page is very clear that it won't do it for you πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./kernel/cgroup/cgroup.c, plus a truly unhinged amount of friends:

like… that's a whole group chat right there πŸ˜­πŸ’€


mwah, that's the page πŸ’œ this lil baddie lives in ./kernel/cgroup and the docs are dated October 2026 β€” go forth and walk those descendants in pre-order, bestie, you've got this 🫢✨

πŸ“¦ where this page comes from