From: Tiffany Yang <ynaffit@google.com>
To: linux-kernel@vger.kernel.org
Cc: "John Stultz" <jstultz@google.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Stephen Boyd" <sboyd@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Pavel Machek" <pavel@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Chen Ridong" <chenridong@huawei.com>,
kernel-team@android.com, "Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [RFC PATCH v3 0/2] cgroup: Track time in cgroup v2 freezer
Date: Mon, 4 Aug 2025 20:29:40 -0700 [thread overview]
Message-ID: <20250805032940.3587891-4-ynaffit@google.com> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="true", Size: 3862 bytes --]
Hello,
The cgroup v2 freezer controller is useful for freezing background
applications so they don't contend with foreground tasks. However, this
may disrupt any internal monitoring that the application is performing,
as it may not be aware that it was frozen.
To illustrate, an application might implement a watchdog thread to
monitor a high-priority task by periodically checking its state to
ensure progress. The challenge is that the task only advances when the
application is running, but watchdog timers are set relative to system
time, not app time. If the app is frozen and misses the expected
deadline, the watchdog, unaware of this pause, may kill a healthy
process.
This series tracks the time that each cgroup spends "freezing" and
exposes it via cgroup.freeze.stat.local. If others prefer, I can instead
create cgroup.stat.local and allow the freeze time accounting to be
accessed there instead.
This version includes several basic selftests. I would find feedback
especially useful here! Along with testing basic functionality, I wanted
to demonstrate the following relationships:
1. Freeze time will increase while a cgroup is freezing, regardless of
whether it is frozen or not.
2. Each cgroup's freeze time is independent from the other cgroups in
its hierarchy.
I was hoping to show (1.) with a test that freezes a cgroup and then
checks its freeze time while cgroup.events still shows "frozen 0", but I
am having trouble writing a case that can reliably cause this (even when
letting a forkbomb grow for a while before attempting to
freeze!). Ideally, I could populate a test cgroup with an unfreezable
task. Is there an elegant way to create a process from a selftest that
will become TASK_INTERRUPTIBLE?
The main challenge in establishing (2.) is that in order to make a
meaningful comparison between two cgroups' freeze times, they need to be
obtained at around the same time. The test process may check one
cgroup's freeze time, but then it may be preempted and delayed from
checking another cgroup's for a relatively "long" time. I have tried to
use sleeps to increase what a "long" time would be, but this possibility
makes tests like test_cgfreezer_time_parent non-deterministic, so I am a
bit squeamish about adding it here.
Any suggestions for better tests or anything else would be welcome.
Thank you!
Tiffany
Signed-off-by: Tiffany Yang <ynaffit@google.com>
---
v3:
* Use seqcount along with css_set_lock to guard freeze time accesses as
suggested by Michal Koutný
* Add selftests
v2: https://lore.kernel.org/lkml/20250714050008.2167786-2-ynaffit@google.com/
* Track per-cgroup freezing time instead of per-task frozen time as
suggested by Tejun Heo
v1: https://lore.kernel.org/lkml/20250603224304.3198729-3-ynaffit@google.com/
Cc: John Stultz <jstultz@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Pavel Machek <pavel@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Chen Ridong <chenridong@huawei.com>
Tiffany Yang (2):
cgroup: cgroup.freeze.stat.local time accounting
cgroup: selftests: Add tests for freezer time
Documentation/admin-guide/cgroup-v2.rst | 20 +
include/linux/cgroup-defs.h | 17 +
kernel/cgroup/cgroup.c | 28 +
kernel/cgroup/freezer.c | 10 +-
tools/testing/selftests/cgroup/test_freezer.c | 686 ++++++++++++++++++
5 files changed, 759 insertions(+), 2 deletions(-)
--
2.50.1.565.gc32cd1483b-goog
next reply other threads:[~2025-08-05 3:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 3:29 Tiffany Yang [this message]
2025-08-05 3:29 ` [RFC PATCH v3 1/2] cgroup: cgroup.freeze.stat.local time accounting Tiffany Yang
2025-08-11 18:51 ` Tejun Heo
2025-08-14 1:30 ` Tiffany Yang
2025-08-14 15:54 ` Michal Koutný
2025-08-05 3:29 ` [RFC PATCH v3 2/2] cgroup: selftests: Add tests for freezer time Tiffany Yang
2025-08-14 16:18 ` Michal Koutný
2025-08-19 23:05 ` Tiffany Yang
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=20250805032940.3587891-4-ynaffit@google.com \
--to=ynaffit@google.com \
--cc=anna-maria@linutronix.de \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huawei.com \
--cc=corbet@lwn.net \
--cc=frederic@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jstultz@google.com \
--cc=kernel-team@android.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=roman.gushchin@linux.dev \
--cc=sboyd@kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).