scx_cgroup_claim_subtree(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… scx_cgroup_claim_subtree β€” kernel API manual, bestie edition

okay so this one lives in the 9 section of the kernel API manual, and it's called scx_cgroup_claim_subtree(9). Strap in, it's a whole cgroup handover situation and honestly it ate. πŸŽ€


✨ NAME ✨

scx_cgroup_claim_subtree β€” claim the subtree's cgroups for an enabling sub 🫢


🌸 SYNOPSIS 🌸

s32 scx_cgroup_claim_subtree (struct scx_sched *sch );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • sch β€” the sub-scheduler that's being enabled. that's the main character of this whole function ngl πŸ‘‘

πŸ”₯ DESCRIPTION πŸ”₯

So this gets called while enabling sch β€” specifically after the subtree's cgrp->scx_sched's have been pointed at sch, and before any task gets claimed. it's giving "cgroups first, tasks second," which literally mirrors the exact same order root enable uses. consistency icon πŸ’…

Now, a little warning label moment: the ops.init_task args are task_group-granular, so they can still reference a cgroup outside the handed-over set when the cpu controller is coarser than the sub topology, or when it's mounted on cgroup1. like, they're allowed to point elsewhere, no cap πŸ™ˆ

The order of operations here is the whole point, so pay attention bestie:

  1. First, init each of the parent sched's subtree cgroups on sch.
  2. Only then exit them from the parent.

Why? So that if an init fails, it can be unwound with the parent completely untouched. slay. and that lil "both-inited" transient moment? nobody outside scx_cgroup_lock can even see it β€” it's invisible, a private vibe ✨

  • SCX_TG_SUB_INIT tracks how far the first pass got.
  • SCX_TG_INITED stays set the whole time throughout β€” except for a task_group whose ops.cgroup_init failed on the parent (peep scx_cgroup_return_subtree). in that case there's literally nothing to exit from the parent, so SCX_TG_INITED gets set back along with the transfer. not me fixing the bookkeeping 😭

Also important: dying-but-not-yet-offlined task_groups are included in all this. a removed cgroup keeps hosting scheduling events until its dying tasks finish their final context switches, so it still needs to be inited on a sched, and its offline-time ops.cgroup_exit follows the last of those events. it's not gone until it's gone, periodt πŸ’€

Return value time: returns 0 on success, -errno on failure. and on failure, sch has been scx_error'd and is left with no cgroups. yeah. rough, but that's the contract 🫠


🌈 SEE ALSO 🌈

Kernel file ./kernel/sched/ext/sub.c, plus this whole friend group:


πŸ’– that's the whole page bestie, go init some subtrees responsibly πŸ’–

okay bye ily, this one shipped from ./kernel/sched/ext, dated October 2026, and the page itself is scx_cgroup_claim_subtree(9) β€” mwah πŸ§šπŸ’œ

πŸ“¦ where this page comes from