Skip to contentSkip to conversation

Any proper way to prevent system from power management suspension/hibernation?

DISCUSSION Qu Wenruo 2 participants 3 messages Oct 17, 2025 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

Hi,

Recently I'm fixing a bug in btrfs scrub/replace where long running scrub/dev-replace ioctl will prevent systems from suspension/hibernation.

With that fixed, btrfs scrub/dev-replace will abort the current run if the filesystem or the process is being frozen, thus allowing pm to freeze the fs then the process.

However this exposed another problem, now PM suspension/hibernation will always interrupt scrub/dev-replace runs, and it's not that easy to resume from the last handled bytes.

I'm wonder if there is any generic solution to prevent power management from entering suspension/hibernation (using systmed), and is generic enough to handle not only pure systemd, but also various GUI environments (like KDE/GNOME).

If there is such solution, we can provide different systemd services files to end users, and they can choose what version they want, either gives pm the priority and accept scrub/dev-replace can be interrupted, or prevent pm actions in the first place (no attempt to even suspend, thus no extra timeout).

Thanks,
Qu

#1 lore raw
Quoted 1 line · Qu Wenruo

Hi,

Hey Qu,

Quoted 8 lines

Recently I'm fixing a bug in btrfs scrub/replace where long running scrub/dev-replace ioctl will prevent systems from suspension/hibernation.

With that fixed, btrfs scrub/dev-replace will abort the current run if the filesystem or the process is being frozen, thus allowing pm to freeze the fs then the process.

Quoted 8 lines

However this exposed another problem, now PM suspension/hibernation will always interrupt scrub/dev-replace runs, and it's not that easy to resume from the last handled bytes.

I'm wonder if there is any generic solution to prevent power management from entering suspension/hibernation (using systmed), and is generic enough to handle not only pure systemd, but also various GUI environments (like KDE/GNOME).

I think this could be a good fit for [systemd-inhibit][0][1] which could be used to wrap the relevant command in the systemd unit.

Quoted 8 lines

If there is such solution, we can provide different systemd services files to end users, and they can choose what version they want, either gives pm the priority and accept scrub/dev-replace can be interrupted, or prevent pm actions in the first place (no attempt to even suspend, thus no extra timeout).

Thanks,
Qu

Cheers,
Chris

[0]: https://www.freedesktop.org/software/systemd/man/latest/systemd-inhibit.html
[1]: https://systemd.io/INHIBITOR_LOCKS/

author
#2 lore raw
Quoted 17 lines · Christian Heusel
Quoted 1 line · Qu Wenruo

Hi,

Hey Qu,

Quoted 12 lines

Recently I'm fixing a bug in btrfs scrub/replace where long running scrub/dev-replace ioctl will prevent systems from suspension/hibernation.

With that fixed, btrfs scrub/dev-replace will abort the current run if the filesystem or the process is being frozen, thus allowing pm to freeze the fs then the process.

However this exposed another problem, now PM suspension/hibernation will always interrupt scrub/dev-replace runs, and it's not that easy to resume from the last handled bytes.

Quoted 7 lines
Quoted 4 lines

I'm wonder if there is any generic solution to prevent power management from entering suspension/hibernation (using systmed), and is generic enough to handle not only pure systemd, but also various GUI environments (like KDE/GNOME).

I think this could be a good fit for [systemd-inhibit][0][1] which could be used to wrap the relevant command in the systemd unit.

Thanks a lot!

That's exactly what we need for the systemd service files.

Although pulling in the full systemd dependency for btrfs-progs may be a little overkilled, for btrfsmaintance service files it's definitely more than enough.

Thanks you very much for this awesome hint,
Qu

Quoted 15 lines
Quoted 9 lines

If there is such solution, we can provide different systemd services files to end users, and they can choose what version they want, either gives pm the priority and accept scrub/dev-replace can be interrupted, or prevent pm actions in the first place (no attempt to even suspend, thus no extra timeout).

Thanks,
Qu

Cheers,
Chris

[0]: https://www.freedesktop.org/software/systemd/man/latest/systemd-inhibit.html
[1]: https://systemd.io/INHIBITOR_LOCKS/