scx_cgroup_claim_subtree(9)
π 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:
- First, init each of the parent sched's subtree cgroups on
sch. - 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_INITtracks how far the first pass got.SCX_TG_INITEDstays set the whole time throughout β except for a task_group whoseops.cgroup_initfailed on the parent (peepscx_cgroup_return_subtree). in that case there's literally nothing to exit from the parent, soSCX_TG_INITEDgets 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:
scx_skip_subtree_pre(9)scx_next_descendant_pre(9)scx_rescue_charge(9)scx_rescue_end(9)scx_rescue_keep(9)scx_rescue_accrue(9)scx_rescue_admit(9)scx_rescue_try_admit(9)scx_rescue_check_overload(9)scx_rescue_timerfn(9)scx_resolve_local_dsq(9)queue_sync_ecaps(9)scx_process_sync_ecaps(9)scx_unbypass_replay_ecaps(9)scx_discard_stale_ecaps_syncs(9)scx_rehome_task(9)scx_punt_task(9)scx_cgroup_return_subtree(9)scx_cgroup_task_migrating(9)scx_cgroup_task_migrated(9)scx_cgroup_task_migrate_canceled(9)scx_bpf_sub_dispatch(9)scx_bpf_sub_grant(9)scx_bpf_sub_revoke(9)scx_bpf_sub_caps(9)scx_bpf_sub_kill_bstr(9)
π 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms