mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Tejun Heo <tj@kernel.org>, Johannes Weiner <hannes@cmpxchg.org>,
	Michal Koutny <mkoutny@suse.com>,
	Michal Hocko <mhocko@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Christian Brauner <brauner@kernel.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Suren Baghdasaryan <surenb@google.com>,
	"T . J . Mercier" <tjmercier@google.com>,
	Usama Arif <usama.arif@linux.dev>,
	Meta kernel team <kernel-team@meta.com>,
	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
Date: Tue, 1 Dec 2026 09:56:12 -0800	[thread overview]
Message-ID: <20261201095612.936988f85920786ec5b0464f@linux-foundation.org> (raw)
In-Reply-To: <20261130173425.4117363-12-shakeel.butt@linux.dev>

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

> 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 <akpm@linux-foundation.org>
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@linux.dev
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Koutný <mkoutny@suse.com>

 kernel/cgroup/freezer.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

--- a/kernel/cgroup/freezer.c~cgroup-freezer-dont-hold-cgroup_mutex-for-cgroupfreeze-fix
+++ a/kernel/cgroup/freezer.c
@@ -349,6 +349,18 @@ int cgroup_freeze(struct cgroup *cgrp, b
 		}
 		dsct->freezer.e_freeze = 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 = 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 = css_rightmost_descendant(css);
+			continue;
+		}
 		if (css != &cgrp->self && css->cgroup->freezer.freeze) {
 			css = css_rightmost_descendant(css);
 			continue;
_


  reply	other threads:[~2026-12-01 17:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 17:34 [PATCH v2 00/11] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 01/11] cgroup: don't lose a task in css_task_iter when a migration fails Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 02/11] cgroup: kill a child forked while cgroup.kill runs Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 03/11] cgroup/freezer: check own tasks and descendants for the frozen state Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 04/11] cgroup/freezer: don't update the frozen state of removed cgroups Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 05/11] cgroup/freezer: test the freeze trap bit under siglock Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 06/11] selftests/cgroup: test cgroup.procs reads across a failed migration Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 07/11] selftests/cgroup: test the frozen state of a cgroup with tasks and children Shakeel Butt
2026-12-01 17:55   ` Andrew Morton
2026-11-30 17:34 ` [PATCH v2 08/11] selftests/cgroup: test cgroup.kill in a threaded cgroup Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 09/11] cgroup: factor out cgroup_kn_break_active() and cgroup_kn_unbreak_active() Shakeel Butt
2026-11-30 17:34 ` [PATCH v2 10/11] cgroup: don't hold cgroup_mutex for cgroup.kill Shakeel Butt
2026-12-01 17:55   ` Andrew Morton
2026-12-01 17:56   ` Andrew Morton
2026-11-30 17:34 ` [PATCH v2 11/11] cgroup/freezer: don't hold cgroup_mutex for cgroup.freeze Shakeel Butt
2026-12-01 17:56   ` Andrew Morton [this message]
2026-12-01 17:55 ` [PATCH v2 00/11] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze Andrew Morton
2026-12-01 18:15   ` Shakeel Butt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201095612.936988f85920786ec5b0464f@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=oleg@redhat.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    --cc=tjmercier@google.com \
    --cc=usama.arif@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®