Re: [PATCH v2 00/11] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze

From: Andrew Morton

Date: Tue Dec 01 2026 - 12:55:38 EST


On Mon, 30 Nov 2026 09:34:14 -0800 Shakeel Butt <shakeel.butt@xxxxxxxxx> wrote:

> cgroup.kill and cgroup.freeze take cgroup_mutex and hold it while they
> walk every task of the subtree. cgroup.kill is how userspace OOM
> killers, service managers and container runtimes stop a workload, often
> when the system is already under pressure. Waiting for cgroup_mutex
> makes the kill as slow as the slowest cgroup operation on the machine.

I gave this series a fairly thorough workout on my LLM-driven live
kernel test setup.

I told it "if you hit a bug, fix it and keep going". It seems to have
found four issues, fixed them and then everything worked OK. Its fixes
sped a few things up nicely. I'll send those 4 patches in reply to the
patches which they patch.

tl;dr: objective achieved, some things got nicely faster, no stability
issues.



Wall of words follows. Organized as Functionality, Performance and
Stress.

Sorry, I tried but it's still pretty dense. I don't know how to
simplify this really - it did a lot of testing!

I've retained the case files so lmk if anything needs
clarification/explanation.




Kernel A ends immediately before the 11-patch series;
Kernel B includes all 11;
Kernel F is B plus the four proposed fixes.


Functionality:

Shakeel's main performance objective was achieved: cgroup.kill and
cgroup.freeze no longer make unrelated cgroup operations wait for their
task walks. In the forced overlap tests, a roughly 350 ms wait on A
fell to about 0.08 ms on B. With 64 workers, populated kill throughput
rose from 11,724 to 13,641 operations/s; single-worker kill over 256
empty children fell from 55 to 27 s. Populated freeze was near
baseline, though the repeated dense 64-worker test was slower. The
series needs the proposed correctness fixes before it is ready: testing
reproduced two cgroup.kill errors in uncorrected v2 that the fixes
addressed

Performance:

Shakeel's cgroup.kill/cgroup.freeze v2: performance
December 1, 2026

Setup: Linux 7.4-rc4, KVM guest, 64 vCPUs, two NUMA nodes, 16 GiB.
Fresh A, B and F kernel builds and guest boots from the same mm queue.


Test B/A F/A
kill-1-populated 1.0x 1.0x
kill-64-populated 1.16x 1.12x
freeze-1-populated 1.0x 1.0x
freeze-64-populated 0.96x 0.98x
kill-1-256-empty-children 2.07x 2.07x
freeze-1-256-empty-children 1.36x 2.23x
freeze-1-4096-empty-children 1.34x 2.08x
freeze-64-64-empty-children-each 1.0x 1.0x
kill-1-256-tasks 1.18x 1.16x
kill-64-8-tasks 1.95x 2.45x
freeze-64-8-tasks 0.88x 0.94x
freeze-1-256-tasks 0.90x 0.84x *
fork-64-64-levels 1.0x 1.0x
kill-1-64-empty-levels 1.11x 1.04x
kill-64-64-empty-levels 1.0x 0.98x

Two forced-overlap tests used separate, temporary kernel builds.
Their source edits add a 350 ms pause at a chosen point. The pause
is absent from the ordinary A, B and F rate kernels above.

In the first test, one task starts an unrelated cgroup mkdir. It
pauses for 350 ms while holding cgroup_mutex. During that pause,
another task writes cgroup.kill or cgroup.freeze to a populated
cgroup; the table times that write. A waits for mkdir to release
the mutex. B completes the write while mkdir is still paused.

In the reverse test, a cgroup.kill or cgroup.freeze write pauses
for 350 ms partway through its walk. Another task then creates an
unrelated cgroup; the table times mkdir. A holds cgroup_mutex
across the walk, so mkdir waits. B does not hold the mutex across
the walk, so mkdir finishes while the write is still paused.
Each entry below is the median of three timed operations.

Test A time B time
kill-during-mutex-holder 346.851 ms 0.080 ms
freeze-during-mutex-holder 346.575 ms 0.082 ms
mkdir-during-slow-kill 354.153 ms 0.079 ms
mkdir-during-slow-freeze 351.450 ms 0.063 ms

Speedup is B or F rate divided by A rate; for timed tests it is A
time divided by B or F time. Above 1.0x is faster. The forced
overlap times show whether an unrelated operation waits for the
chosen pause; they are not throughput results. F was not measured
for those rows.

kill-N-populated, freeze-N-populated: N processes, each with its
own cgroup and one sleep task. Kill starts and moves a task, writes
cgroup.kill and waits for exit. Freeze writes 1, waits for frozen,
writes 0 and waits for thaw. These rows time the entire cycle.

kill-1-256-empty-children: time a cgroup.kill write to the parent
of 256 empty child cgroups. freeze-1-256-empty-children: time each
freeze/thaw write to the same layout, excluding the later checks.

freeze-1-4096-empty-children: time freeze/thaw writes to a parent
with 4096 empty direct children, four trials. The 64-worker row
has 64 separate parents, each with 64 children (4096 total).

kill-N-M-tasks, freeze-N-M-tasks: N processes, each with M sleep
tasks in its own cgroup. Time each kill or freeze/thaw write only;
check task death or frozen state outside the timed interval.

fork-64-64-levels: 64 workers in one cgroup at the end of a
64-level hierarchy; each repeatedly forks and waits for a child.
kill-N-64-empty-levels: N threads, each with its own 64-level empty
branch and an open cgroup.kill fd; time repeated write plus lseek.

Populated kill rose from 11,724 to 13,641 cycles/s with 64 workers
(13,180 with F). One-worker freezing of 4096 empty children took
735/550/353 us on A/B/F.

The freeze-64-8-tasks row is from five trials per kernel: A/B/F
1933/2190/2064 us. A later A order control was about 2045 us;
the size of the B cost depends on run order. * The eight-trial
freeze-1-256-tasks results varied widely: A 580-747 us, B 710-868
us, F 576-1241 us. CPU0-pinned trials were bimodal on all three
kernels, so this row does not establish a fixed-kernel regression.

Adversarial check: with 64 source-delayed kills active, unrelated
migration median write latency rose from 38.6 to 40.4 us on B and
from 37.2 to 38.9 us on F with one worker. With 64 workers it rose
from 6.81 to 7.16 ms on B and 5.22 to 7.22 ms on F; wall rates
varied and did not consistently fall.

These are short runs on one boot per kernel. Rows rounded to 1.0x
are close in this run, not proof of equal performance. Raw results
and test scripts: case shakeel-cgroup-kill-freeze-v2-20261201-04.


Stress testing:

On the 64-vCPU KASAN/lockdep kernel, 64 concurrent cgroup.kill writers
killed 128 tasks, and 64 freezer writers completed 960 freeze/thaw
cycles. A mixed workload of freeze, kill, migration and cgroup
creation completed 1,056 operations on both v2 and the four-fix kernel.
The final four-fix run completed without a hung thread or kernel
warning.

Temporary source edits widened races between a descendant kill and
threaded conversion, freeze and migration, and cgroup creation and
freeze notification. The uncorrected v2 kernel accepted a threaded
conversion while a descendant kill was active; the fix returned EBUSY.
It also allowed cgroup.kill on a domain-invalid cgroup to kill a
process with a thread outside the target subtree; the fix refused the
write. All three widened races were repeated 24 times with the four
fixes applied, passing 72 assertions without a kernel warning.

Fault injection exercised the changed dead-cgroup and active-reference
error paths, ENOMEM during threaded conversion, and four allocation
sites in the new freezer selftest. The corrected kernel returned the
expected errors, preserved or restored cgroup state, and recovered on
subsequent operations. Kernel failslab produced 44 allocation failures
without a freeze or cleanup violation.

Strict KCSAN runs completed their workloads but reported races in
shared kernfs, VFS, scheduler and bitmap code. None of those reports
contained a changed cgroup function in either stack. These runs are
reported with that limitation; they were not KCSAN-clean.