Skip to content

store: name and place a process by what it became, under cgroup v2 - #2

Merged
aledbf merged 2 commits into
ci-baselinefrom
cgroup-v2-names
Nov 22, 2026
Merged

aledbf merged 2 commits into
ci-baselinefrom
cgroup-v2-names

Conversation

@aledbf

@aledbf aledbf commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

spin-stack/machine draws its boot with this fork to see how systemd starts inside a ~300-400 ms VM boot on one vCPU, and to catch regressions release to release. On that machine (kernel 7.3.5, cgroup v2 only) the chart named journald, logind, udevd and every executor "9", and labelled every process's cgroup "(null)". A reader could not tell which service spent the time.

What

  • Names. systemd execs systemd-executor through a file descriptor, and the kernel names a task exec'd that way after the descriptor (/dev/fd/9, so "9"). The executor then execs the service. Bootchart read the name once from /proc/PID/sched and refreshed it only every Hz/4 samples (250 ms at 200 Hz), so the service kept the executor's name for the whole boot. The comm (and the command line with -C) is now read from /proc/PID/comm again on every sample in which the process ran, which is when an exec can have happened.
  • cgroup v2. The cgroup came from cg_pid_get_path, which statfs'd /sys/fs/cgroup to choose v1 or v2. Before systemd mounts it that fails, and the label stayed NULL. It was also read once, before the process moved from init.scope into its unit. It is now read from /proc/PID/cgroup (systemd's name=systemd hierarchy on v1 or hybrid, the 0:: line on v2) whenever the process ran. cgroup-util.c goes.
  • Units. With -c, each process is labelled with its unit, the cgroup path without the slices above it (systemd-journald.service, user@0.service/init.scope). A "Top CPU consumers by unit" table sums CPU time over a unit's processes.
  • Parent pid. /proc/PID/stat puts the comm in parentheses without quoting it, and the parent pid was read as its fourth word. A comm with a space ("Web Content") made the scan fail, and that process was never sampled. The parent pid is now read after the last ).
  • /proc/PID/sched is no longer read. Its start time was parsed and never drawn.
  • Test seam. --proc=PATH samples a directory laid out as /proc. The pids are sorted before the tree is built, because the tree needs a parent before its children and only /proc itself lists them in that order.

Checked

tests/identity builds a fixture /proc where pid 62 starts as "9" in init.scope and becomes systemd-journal in system.slice/systemd-journald.service while the sampler runs. It also covers a v1/hybrid name=systemd process and a comm with a space and a parenthesis. The test asserts the labels and the unit table. It fails when the identity is read only at first sight (checked by reverting that condition). make check passes under ASan/UBSan with gcc in an Ubuntu 24.04 container. The CI run covers clang. A lab chart from a real boot comes with the spin-stack/machine PR that builds this fork.

Stacked on #1.

🤖 Generated with Claude Code

A service's process in a boot changes name and cgroup after bootchart
first sees it. systemd execs its executor through a file descriptor,
and the kernel names a task exec'd that way after the descriptor, so
journald, logind, udevd and every executor were charted as "9": the
name was read once from /proc/PID/sched and refreshed only every Hz/4
samples (250 ms at 200 Hz). The cgroup was read once too, before the
process moved from init.scope into its unit, and through cgroup-util,
which statfs'd /sys/fs/cgroup before systemd had mounted it and gave
up, so every label read "(null)".

Now the comm, the command line with -C and the cgroup are read again
on every sample in which the process ran, which is when an exec or a
move can have happened. The cgroup comes from /proc/PID/cgroup itself:
systemd's name=systemd hierarchy on v1 or hybrid, the 0:: line on v2.
A process is labelled with its unit, the cgroup path without the
slices above it, and a table lists CPU time by unit. /proc/PID/sched,
whose start time nothing drew, is no longer read, and cgroup-util goes.

--proc samples a directory laid out as /proc, which tests/identity
builds and changes under the sampler. The pids are sorted before the
tree is built, since the tree needs a parent before its children and
only /proc itself lists them in that order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
/proc/PID/stat puts the comm in parentheses without quoting it, and
bootchart took the parent pid as the fourth word. A comm with a space,
such as "Web Content", moved it: the scan failed and the process was
never sampled, so it was missing from the chart. The parent pid is now
read after the last ')'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf
aledbf merged commit f9b1fa4 into ci-baseline Nov 22, 2026
2 checks passed
@aledbf aledbf mentioned this pull request Nov 22, 2026
aledbf added a commit that referenced this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant