Repository navigation
store: name and place a process by what it became, under cgroup v2 - #2
Merged
Merged
Conversation
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>
aledbf
force-pushed
the
cgroup-v2-names
branch
from
November 22, 2026 15:57
c65c0cc to
16062b1
Compare
/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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
systemd-executorthrough 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/schedand 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/commagain on every sample in which the process ran, which is when an exec can have happened.cg_pid_get_path, whichstatfs'd/sys/fs/cgroupto choose v1 or v2. Before systemd mounts it that fails, and the label stayed NULL. It was also read once, before the process moved frominit.scopeinto its unit. It is now read from/proc/PID/cgroup(systemd'sname=systemdhierarchy on v1 or hybrid, the0::line on v2) whenever the process ran.cgroup-util.cgoes.-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./proc/PID/statputs 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/schedis no longer read. Its start time was parsed and never drawn.--proc=PATHsamples 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/procitself lists them in that order.Checked
tests/identitybuilds a fixture/procwhere pid 62 starts as "9" ininit.scopeand becomessystemd-journalinsystem.slice/systemd-journald.servicewhile the sampler runs. It also covers a v1/hybridname=systemdprocess 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 checkpasses 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