From: Samuel Wu <wusamuel@google.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>, Pavel Machek <pavel@kernel.org>
Cc: Samuel Wu <wusamuel@google.com>,
kernel-team@android.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] freezer: Check frozen() before freezing() in freeze_task()
Date: Sat, 14 Nov 2026 16:31:14 -0800 [thread overview]
Message-ID: <20261115003113.1852160-2-wusamuel@google.com> (raw)
During the freeze stage of suspend, there are multiple passes over the
same list of tasks. Each pass tries to freeze non-frozen tasks, meaning
that the number of frozen tasks increase monotonically, and that each
subsequent pass will mostly be iterating over frozen tasks. Therefore,
it is faster to *first* check that a task is frozen before other checks,
especially since the frozen check is computationally trivial.
Check frozen(p) before !freezing(p) to short circuit the more expensive
freezing_slow_path() calls, while retaining identical return semantics.
On a v7.3 Pixel 9 device, this consistently reduces freeze_processes
latency by ~10% (~4.5 ms).
Signed-off-by: Samuel Wu <wusamuel@google.com>
---
kernel/freezer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/freezer.c b/kernel/freezer.c
index a76bf957fb32..1adf09321389 100644
--- a/kernel/freezer.c
+++ b/kernel/freezer.c
@@ -166,7 +166,7 @@ bool freeze_task(struct task_struct *p)
unsigned long flags;
spin_lock_irqsave(&freezer_lock, flags);
- if (!freezing(p) || frozen(p) || __freeze_task(p)) {
+ if (frozen(p) || !freezing(p) || __freeze_task(p)) {
spin_unlock_irqrestore(&freezer_lock, flags);
return false;
}
--
2.56.0.679.gc527c65306-goog
next reply other threads:[~2026-11-15 0:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 0:31 Samuel Wu [this message]
2026-11-15 0:49 ` Bradley Morgan
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=20261115003113.1852160-2-wusamuel@google.com \
--to=wusamuel@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@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
all inboxes | Powered by JetHome®