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=1796147774; b=dvvD4JMKq2ufRG/9oDa6GoI7KfHZdgY1AqJmGn8SxFc+4nmkU8D/VoWWQ3gMlkXjnSO7 uAaVg74jrlmc2N3uDKpzpm4yH6wJcUW6eL8MVmcxicjFWX0K4ucL8YI0h36L0kNDmIy3f wx0r+a/GPJwISij4QOErj1Qvwllv1Tar93aQim1lO+jTPppxecXgOJ8ldIG85pdfLinyg goxnVbdXVp8FvSMuLPYFXG5tKRuus9ru0hEBnFSLdrLeqdnp2PGkVvNxZwVe42qGoE0ML lv/udVUk+MXfkqOoProBdnc5tmxVykLIO9wGP68Kr5qJ8WUWo8xiIquZ97FYSifkXiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147774; 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=wxjqdqU8kGym+OgN4Roy3iuvmR9twqrzHDs7o+IOq/M=; b=HzxzqUNWtXtuqkke5NRz1IrhIa1KS17iSbW05SrncWbt4RiETplzGNZhESBpEqblnRtm l7b2DXH0GL2eaKi5WyPlwWCswxzD7W/M9orSjp3pqHMyBhZONGIqqbjiQ0vm3pUBZqboa CtQfeLYC5KDPyq1XnqRVsqWU369ffs1a1YBfbfcOlwADqUS1qpH0NDlequwIiqUmRizAj qpBLQzC76U3vH4subm/YI/IpncWjC8QYBdA7WA9+TwZTZegmVxb9zvGohOs8eg59PzGM/ nWqpbc6/VZBFKMiGvnqGe4Ho2nrkdi9gYVNpBk8r0KG4xA1wKHEAfbud+o9/Vd0NDnQ== 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=CbmzJoo2; 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 1BD67606A322; Tue, 1 Dec 2026 17:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=CbmzJoo2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5A5A1F0089A; Tue, 1 Dec 2026 17:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796147773; bh=wxjqdqU8kGym+OgN4Roy3iuvmR9twqrzHDs7o+IOq/M=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=CbmzJoo2xPsTcAK8PzKFzUIwI1/UF5bj/VrQoKpNeQE2GBsUs1ouyceYwqrrsyUkF JoPIJlRLovIbsXjIL8qFuLoT2lBmZednEOFzQzsDSd+9q1/OvlZO1dIykrG3Qqzcdv AXLcR/oVwFC905ngewJcMtnlSdjRmTXtP4d3JUCc= Date: Tue, 1 Dec 2026 09:56:12 -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 11/11] cgroup/freezer: don't hold cgroup_mutex for cgroup.freeze Message-Id: <20261201095612.936988f85920786ec5b0464f@linux-foundation.org> In-Reply-To: <20261130173425.4117363-12-shakeel.butt@linux.dev> References: <20261130173425.4117363-1-shakeel.butt@linux.dev> <20261130173425.4117363-12-shakeel.butt@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@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=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, 30 Nov 2026 09:34:25 -0800 Shakeel Butt wr= ote: > cgroup.freeze holds cgroup_mutex while it walks the subtree and its tasks. > cgroup_mutex kept freeze writers apart, gave new cgroups a stable parent > state, and blocked migrations. Replace it: From: Andrew Morton Subject: cgroup/freezer: skip empty branches in the task pass Date: Tue, 01 Dec 2026 01:44:33 -0800 The lockless cgroup.freeze implementation walks the subtree once to set states and again to visit tasks. The second pass pins and iterates each cgroup even when the whole branch is unpopulated. In three 64 CPU guest trials, 60 straight-line writes over 1,024 empty descendants had a median latency of 273 us on v2 versus 193 us before the series. This fixes Shakeel Butt's "cgroup/freezer: don't hold cgroup_mutex for cgroup.freeze" patch. An empty branch still needs its CGRP_FROZEN state and trace event updated. Do both in the state pass while holding css_set_lock, then skip that branch in the task pass. A fork or migration into it after state propagation uses the new CGRP_FREEZE bit; an exiting task will not run in user space. The state and trace updates remain in the same order as cgroup_do_freeze(). Link: https://lore.kernel.org/r/20261130173425.4117363-12-shakeel.butt@linu= x.dev Signed-off-by: Andrew Morton Cc: Tejun Heo Cc: Johannes Weiner Cc: Michal Koutn=FD kernel/cgroup/freezer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/kernel/cgroup/freezer.c~cgroup-freezer-dont-hold-cgroup_mutex-for-cgr= oupfreeze-fix +++ a/kernel/cgroup/freezer.c @@ -349,6 +349,18 @@ int cgroup_freeze(struct cgroup *cgrp, b } dsct->freezer.e_freeze =3D e_freeze; cgroup_set_freeze(dsct, e_freeze); + /* + * No task in this subtree needs a signal. Revisit its frozen + * state here so the task pass can skip the whole empty branch. + * Forks and migrations into it use the new CGRP_FREEZE state. + */ + if (!cgroup_is_populated(dsct)) { + if (e_freeze) + TRACE_CGROUP_PATH(freeze, dsct); + else + TRACE_CGROUP_PATH(unfreeze, dsct); + cgroup_update_frozen(dsct); + } spin_unlock_irq(&css_set_lock); applied =3D true; } @@ -377,6 +389,10 @@ int cgroup_freeze(struct cgroup *cgrp, b */ rcu_read_lock(); css_for_each_descendant_pre(css, &cgrp->self) { + if (!cgroup_is_populated(css->cgroup)) { + css =3D css_rightmost_descendant(css); + continue; + } if (css !=3D &cgrp->self && css->cgroup->freezer.freeze) { css =3D css_rightmost_descendant(css); continue; _