From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147734; b=uuPw2kOzvAOTjfzuHCNQMkoBrwZdHtXUmjWceGkpIQu3OXBxV59/y0HDu3wYHHr5g9+T B1x1Vzfqdsm9Hk5xDpGp91LDefy+h0kJV3xSra6aT68B2RrcvE8oOOPudOJySOTuTfZny eGcBLBAQZWuHrQcwj1p5F3Zcb6uSTcrk+QJ0YLhgNVg4Pt6cFHH7WHkvghkShmHf+pUvc DXG2979KsPLOnSyEAs+LL+hlUBYO4r+gQkCrafybJYhAshNkqfIJJJpt7MR/Xnb+QbL3D X2V1VuOMbfuN0u3tq2BDP+KXizNuMcFjG1FE7DF4kjSjfaTeqXsaII7ow98s12HHCdg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147734; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=1g+nCrW1/rNcrZZ1HnXEEwUtrGPgloQygYo01ZUIPeg=; b=Pc8I9G/sGWwCi93AEgJEhCNI++TfxyuLTlUPqgWpVJZ1Sv1Jx7ipnuaFPWW19OWZae6j UwFaE5wHk/rCpNlaCj2NePoaFHP+AF7YXNxFYyTgKKw4dGUSpc2QNoUN0yKAK2xTaBniw D2KP5gmGC5VDOHXGiCLqTxpf8BElu961AJR5ZQEZOa75oUvkvX+kxoKuUQIA49epTAc+M bJ+IgsjAUSdQoSKUm6tfXimN3azmpMa5RaD3jyHWOiqxO74y/fcj7gZ0BCQ356CNQLdUU 7BIl3ufowRWm+rcQ02BR+LxjF/6apCXPwlH7k2BFuUOgdGLESPrgHOIGvuox8VWbVRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=MiVa5uSn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5630E606A31A; Tue, 1 Dec 2026 17:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=MiVa5uSn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B6EA1F00893; Tue, 1 Dec 2026 17:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796147733; bh=1g+nCrW1/rNcrZZ1HnXEEwUtrGPgloQygYo01ZUIPeg=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=MiVa5uSnVKMYBH1ya97sCV6eoj88kXK2+ANicVdjQwd6YVxxnQlk++GgnTv30uMvP eSHGVZh9V5XGbyK9RH2Ao0874qkdqJ4a+gKOURZayTJK38Nv+I6Jd3y/ehgIDzoaEp B99PKc6xU0Yp644Ye2x8rGR4N4m8MoYwVql5dejI= Date: Tue, 1 Dec 2026 09:55:32 -0800 From: Andrew Morton To: Shakeel Butt Cc: Tejun Heo , Johannes Weiner , Michal Koutny , Michal Hocko , Roman Gushchin , Christian Brauner , Oleg Nesterov , Sebastian Andrzej Siewior , Suren Baghdasaryan , "T . J . Mercier" , Usama Arif , Meta kernel team , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 00/11] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze Message-Id: <20261201095532.6e638bcaea0119ef81c69c54@linux-foundation.org> In-Reply-To: <20261130173425.4117363-1-shakeel.butt@linux.dev> References: <20261130173425.4117363-1-shakeel.butt@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 30 Nov 2026 09:34:14 -0800 Shakeel Butt 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.