From: Hillf Danton <hdanton@sina.com>
To: Samuel Wu <wusamuel@google.com>
Cc: "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>,
Saravana Kannan <saravanak@google.com>,
kernel-team@android.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5] PM: Support aborting sleep during filesystem sync
Date: Wed, 22 Oct 2025 09:15:44 +0800 [thread overview]
Message-ID: <20251022011547.8648-1-hdanton@sina.com> (raw)
In-Reply-To: <CAG2KctpHA+L=xh-VQ8SVDSRcqyL+ch=WMVrKS+pckLmC6uJwvw@mail.gmail.com>
On Tue, 21 Oct 2025 13:13:39 -0700 Samuel Wu wrote:
> On Fri, Oct 17, 2025 at 5:17 PM Hillf Danton <hdanton@sina.com> wrote:
> > On Fri, 17 Oct 2025 23:39:06 +0000 Samuel Wu wrote:
> > > +/**
> > > + * pm_sleep_fs_sync - Trigger fs_sync with ability to abort
> > > + *
> > > + * Return 0 on successful file system sync, otherwise returns -EBUSY if file
> > > + * system sync was aborted.
> > > + */
> > > +int pm_sleep_fs_sync(void)
> > > +{
> > > + bool need_pm_sleep_fs_sync_requeue;
> > > + unsigned long flags;
> > > +
> > > + do {
> > > + spin_lock_irqsave(&pm_sleep_fs_sync_lock, flags);
> > > + reinit_completion(&pm_sleep_fs_sync_complete);
> >
> > Given difficulty following up here, can you specify why reinit is needed?
>
> There are two possibilities that make reinit_completion() necessary:
> 1. Suspend abort triggers completion, but is canceled before
> pm_wakeup_pending(), so need reinit to restart the
> wait_for_completion() process.
> 2. Handling back-to-back suspend attempts: after a subsequent suspend
> attempt finishes waiting for a previous suspend's fs_sync to finish,
> we need the reinit to start the wait_for_completion() process of the
> subsequent suspend's fs_sync.
>
If 1. and 2. matches the comment for wait_for_completion() below,
static DECLARE_COMPLETION(foo);
waiter waker1 waker2
--- --- ---
for (;;) {
reinit_completion(&foo)
do anything
wait_for_completion(&foo)
do bar1 do bar2
complete(&foo) complete(&foo)
if (end)
break;
}
the chance for reinit to drop one wakeup is not zero.
If drop makes sense, for what do you wait after receiving two wakeups?
> > > + /*
> > > + * Handle the case where a sleep immediately follows a previous
> > > + * sleep 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 sleeping.
> > > + */
> > > + if (pm_sleep_fs_sync_queued) {
> > > + need_pm_sleep_fs_sync_requeue = true;
> > > + } else {
> > > + need_pm_sleep_fs_sync_requeue = false;
> > > + pm_sleep_fs_sync_queued = true;
> > > + schedule_work(&sync_filesystems);
> > > + }
> > > + spin_unlock_irqrestore(&pm_sleep_fs_sync_lock, flags);
> > > +
> > > + /*
> > > + * Completion is triggered by fs_sync finishing or an abort sleep
> > > + * signal, whichever comes first
> > > + */
> > > + wait_for_completion(&pm_sleep_fs_sync_complete);
> > > + if (pm_wakeup_pending())
> > > + return -EBUSY;
> > > + } while (need_pm_sleep_fs_sync_requeue);
> > > +
> > > + return 0;
> > > +}
next prev parent reply other threads:[~2025-10-22 1:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 23:39 Samuel Wu
2025-10-18 0:17 ` Hillf Danton
2025-10-21 20:13 ` Samuel Wu
2025-10-22 1:15 ` Hillf Danton [this message]
2025-10-22 18:41 ` Samuel Wu
2025-10-22 22:32 ` Hillf Danton
2025-10-29 19:03 ` Samuel Wu
2025-10-18 13:19 ` kernel test robot
2025-10-18 18:31 ` kernel test robot
2025-10-21 20:13 ` Samuel Wu
2025-10-23 19:43 ` Rafael J. Wysocki
2025-10-23 22:46 ` Saravana Kannan
2025-10-24 8:37 ` Rafael J. Wysocki
2025-10-29 13:23 ` Rafael J. Wysocki
2025-10-29 19:13 ` Samuel Wu
2025-10-29 20:35 ` Rafael J. Wysocki
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=20251022011547.8648-1-hdanton@sina.com \
--to=hdanton@sina.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 \
--cc=wusamuel@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®