From: Samuel Wu <wusamuel@google.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Pavel Machek <pavel@kernel.org>, Len Brown <lenb@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Danilo Krummrich <dakr@kernel.org>
Cc: Samuel Wu <wusamuel@google.com>,
kernel-team@android.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Saravana Kannan <saravanak@google.com>
Subject: [PATCH v3 3/3] PM: Support abort during fs_sync of back-to-back suspends
Date: Wed, 20 Aug 2025 17:42:35 -0700 [thread overview]
Message-ID: <20250821004237.2712312-4-wusamuel@google.com> (raw)
In-Reply-To: <20250821004237.2712312-1-wusamuel@google.com>
There is extra care needed to account for back-to-back suspends while
still maintaining functionality to immediately abort during the
filesystem sync stage.
This patch handles this by serializing the filesystem sync sequence with
an invariant; a subsequent suspend's filesystem sync operation will only
start when the previous suspend's filesystem sync has finished. While
waiting for the previous suspend's filesystem sync to finish, the
subsequent suspend will still abort early if a wakeup event is
triggered, solving the original issue of filesystem sync blocking abort.
Suggested-by: Saravana Kannan <saravanak@google.com>
Signed-off-by: Samuel Wu <wusamuel@google.com>
Reviewed-by: Saravana Kannan <saravanak@google.com>
---
kernel/power/suspend.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index edacd2a4143b..514c590ec383 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -75,6 +75,8 @@ bool pm_suspend_default_s2idle(void)
}
EXPORT_SYMBOL_GPL(pm_suspend_default_s2idle);
+static bool suspend_fs_sync_queued;
+static DEFINE_SPINLOCK(suspend_fs_sync_lock);
static DECLARE_COMPLETION(suspend_fs_sync_complete);
/**
@@ -85,7 +87,9 @@ static DECLARE_COMPLETION(suspend_fs_sync_complete);
*/
void suspend_abort_fs_sync(void)
{
+ spin_lock(&suspend_fs_sync_lock);
complete(&suspend_fs_sync_complete);
+ spin_unlock(&suspend_fs_sync_lock);
}
void s2idle_set_ops(const struct platform_s2idle_ops *ops)
@@ -420,7 +424,11 @@ void __weak arch_suspend_enable_irqs(void)
static void sync_filesystems_fn(struct work_struct *work)
{
ksys_sync_helper();
+
+ spin_lock(&suspend_fs_sync_lock);
+ suspend_fs_sync_queued = false;
complete(&suspend_fs_sync_complete);
+ spin_unlock(&suspend_fs_sync_lock);
}
static DECLARE_WORK(sync_filesystems, sync_filesystems_fn);
@@ -432,8 +440,26 @@ static DECLARE_WORK(sync_filesystems, sync_filesystems_fn);
*/
static int suspend_fs_sync_with_abort(void)
{
+ bool need_suspend_fs_sync_requeue;
+
+Start_fs_sync:
+ spin_lock(&suspend_fs_sync_lock);
reinit_completion(&suspend_fs_sync_complete);
- schedule_work(&sync_filesystems);
+ /*
+ * Handle the case where a suspend immediately follows a previous
+ * suspend that was aborted during fs_sync. In this case, wait for the
+ * previous filesystem sync to finish. Then do another filesystem sync
+ * so any subsequent filesystem changes are synced before suspending.
+ */
+ if (suspend_fs_sync_queued) {
+ need_suspend_fs_sync_requeue = true;
+ } else {
+ need_suspend_fs_sync_requeue = false;
+ suspend_fs_sync_queued = true;
+ schedule_work(&sync_filesystems);
+ }
+ spin_unlock(&suspend_fs_sync_lock);
+
/*
* Completion is triggered by fs_sync finishing or a suspend abort
* signal, whichever comes first
@@ -441,6 +467,8 @@ static int suspend_fs_sync_with_abort(void)
wait_for_completion(&suspend_fs_sync_complete);
if (pm_wakeup_pending())
return -EBUSY;
+ if (need_suspend_fs_sync_requeue)
+ goto Start_fs_sync;
return 0;
}
--
2.51.0.261.g7ce5a0a67e-goog
next prev parent reply other threads:[~2025-08-21 0:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 0:42 [PATCH v3 0/3] PM: Support aborting suspend during filesystem sync Samuel Wu
2025-08-21 0:42 ` [PATCH v3 1/3] PM: Make pm_wakeup_clear() call more clear Samuel Wu
2025-09-04 19:06 ` Rafael J. Wysocki
2025-08-21 0:42 ` [PATCH v3 2/3] PM: Support aborting suspend during filesystem sync Samuel Wu
2025-09-04 19:22 ` Rafael J. Wysocki
2025-09-05 5:07 ` Saravana Kannan
2025-09-05 9:38 ` Rafael J. Wysocki
2025-09-09 1:41 ` Saravana Kannan
2025-08-21 0:42 ` Samuel Wu [this message]
2025-08-21 6:45 ` [PATCH v3 3/3] PM: Support abort during fs_sync of back-to-back suspends Saravana Kannan
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=20250821004237.2712312-4-wusamuel@google.com \
--to=wusamuel@google.com \
--cc=dakr@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-team@android.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=saravanak@google.com \
/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®