Skip to content

PM: Support aborting sleep during filesystem sync

Samuel Wu linux-pm lkml 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest2 patches 1 replyIn review
  2. v61 patch 7 repliesSuperseded
  3. v51 patch 13 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v41 patch14 repliesSuperseded
v33 patches6 repliesApplied
v21 patch3 repliesSuperseded
v11 patch2 repliesSuperseded

Changes in v7 from the cover letter

- Switched to polling for wakeup/fs_sync finishing per Rafael's patch in v6
- Added header files for wait queue and atomics (modify Rafael's patch)
- Cleaned up wq on error in pm_start_workqueues (modify Rafael's patch)
- Changed atomic_add_return(-1, cnt) == 0 to atomic_dec_and_test(cnt) (modify Rafael's patch)
- v6 link: https://lore.kernel.org/all/[email protected]/

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2PM: Add framework to abort during fs_synckernel/power/main.c kernel/power/power.h+74 -60 replies
2/2PM: Call pm_sleep_fs_sync() instead of ksys_sync_helper()kernel/power/hibernate.c kernel/power/suspend.c kernel/power/user.c+13 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v7 yet.

Read the v7 thread

Cover letter [PATCH v7 0/2] PM: Support aborting sleep during filesystem sync

At the start of suspend and hibernate, filesystems will sync to save the current state of the device. However, the long tail of the filesystem sync can take upwards of 25 seconds. If during this filesystem sync there is some wakeup signal, it will not be processed until the sync is complete; from a user's perspective, this looks like the device is unresponsive to any form of input.

This patch adds functionality to handle a sleep abort signal when in the filesystem sync phase of suspend or hibernate. This topic was first discussed by Saravana Kannan at LPC 2024 [1], where the general consensus was to allow filesystem sync on a parallel thread. In case of a wakeup signal, the suspend process will stop waiting on an in-progress filesystem sync, and instead abort suspend before the filesystem sync is complete.

Furthermore, in the case of the back-to-back sleeps, a subsequent filesystem sync is enqueued to ensure the latest files are synced right before sleep. The framework still allows for an early abort in this case.

[1]: https://lpc.events/event/18/contributions/1845/

Samuel Wu (2):
PM: Add framework to abort during fs_sync
PM: Call pm_sleep_fs_sync() instead of ksys_sync_helper()

Changes in v7:
- Switched to polling for wakeup/fs_sync finishing per Rafael's patch in v6
- Added header files for wait queue and atomics (modify Rafael's patch)
- Cleaned up wq on error in pm_start_workqueues (modify Rafael's patch)
- Changed atomic_add_return(-1, cnt) == 0 to atomic_dec_and_test(cnt) (modify Rafael's patch)
- v6 link: https://lore.kernel.org/all/[email protected]/

Changes in v6:
- Use spin_lock_irq() in thread context
- Use dedicated ordered workqueue for sync work items
- Use a counter instead of two bools for synchronization
- Queue fs_sync if it's not already pending on workqueue
- pm_wakeup_clear(0) is prequisite to this feature, so move it within function
- Updated commit text for motive of back-to-back fs syncs
- Tighter lock/unlock around setup, checks, and loop
- Fix function definitions for CONFIG_PM_SLEEP=n
- v5 link: https://lore.kernel.org/all/[email protected]/

Changes in v5:
- Update spin_lock() to spin_lock_irqsave() since abort can be in IRQ context
- Updated changelog description to be more precise regarding continuing abort sleep before fs_sync() is complete
- Rename abort_sleep_during_fs_sync() to pm_stop_waiting_for_fs_sync()
- Simplify from a goto to do-while in pm_sleep_fs_sync()
- v4 link: https://lore.kernel.org/all/[email protected]

Changes in v4:
- Removed patch 1/3 of v3 as it is already picked up on linux-pm
- Squashed patches 2/3 and 3/3 from v3 into this single patch
- Added abort during fs_sync functionality to hibernate in addition to suspend
- Moved variables and functions for abort from power/suspend.c to power/main.c
- Renamed suspend_fs_sync_with_abort() to pm_sleep_fs_sync()
- Renamed suspend_abort_fs_sync() to abort_sleep_during_fs_sync()
- v3 link: https://lore.kernel.org/all/[email protected]/

Changes in v3:
- Split v2 patch into 3 patches
- Moved pm_wakeup_clear() outside of if(sync_on_suspend_enabled) condition
- Updated documentation and comments within kernel/power/suspend.c
- v2 link: https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Added documentation for suspend_abort_fs_sync()
- Made suspend_fs_sync_lock and suspend_fs_sync_complete declaration static
- v1 link: https://lore.kernel.org/all/[email protected]

 kernel/power/hibernate.c |  6 +++-
 kernel/power/main.c      | 77 ++++++++++++++++++++++++++++++++++++----
 kernel/power/power.h     |  1 +
 kernel/power/suspend.c   |  6 +++-
 kernel/power/user.c      |  4 ++-
 5 files changed, 84 insertions(+), 10 deletions(-)

--
2.52.0.rc1.455.g30608eb744-goog