Skip to content

btrfs: scrub: enhance freezing and signal handling

Qu Wenruo linux-btrfs 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 2 repliesIn review
  2. v23 patches 9 repliesSuperseded
  3. v13 patches 9 repliesSuperseded

Changes in v3 from the cover letter

- Update the commit message and cover letter to indicate a behavior change
Btrfs-progs updates will follow soon after merge into for-next. This will includes docs update, and maybe an automatic resume behavior (with new options to toggle).

- Update the commit message of the last patch to explain why v2 cgroup freezing is depending on signals
Unlike legacy freezer of v1 cgroup, v2 cgroup freezer is fully based on signal handling, thus freezing through v2 cgroup looks exactly like a pending non-fatal signal. And freezing() will not return true in this case.

- Add the reviewed-by tag from Filipe

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs: scrub: add cancel/pause/removed bg checks for raid56 parity stripesfs/btrfs/scrub.c+17 -60 replies
2/3btrfs: scrub: cancel the run if the process or fs is being frozenfs/btrfs/scrub.c+46 -70 replies
3/3btrfs: scrub: cancel the run if there is a pending signalfs/btrfs/scrub.c+2 -20 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchFilipe Manana
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] btrfs: scrub: enhance freezing and signal handling

[CHANGELOG]
v3:
- Update the commit message and cover letter to indicate a behavior change
Btrfs-progs updates will follow soon after merge into for-next. This will includes docs update, and maybe an automatic resume behavior (with new options to toggle).

- Update the commit message of the last patch to explain why v2 cgroup freezing is depending on signals
Unlike legacy freezer of v1 cgroup, v2 cgroup freezer is fully based on signal handling, thus freezing through v2 cgroup looks exactly like a pending non-fatal signal. And freezing() will not return true in this case.

- Add the reviewed-by tag from Filipe

v2:
- Remove copy-pasted comments that are too obvious in the first place Also remove a stale comment in the old code.

- Add extra explanation on why both fs and process freezing need to be checked
Mostly due to the configurable behavior of pm suspension/hiberation, thus we have to handle both cases.

It's a long known bug that when scrub/dev-replace is running, power management suspension will time out and fail.

After more debugging and helps from Askar Safin, it turns out there are at least 3 components involved:

- Process freezing
This is at the preparation for suspension, which requires all user space processes (and some kthreads) to be frozen, which requires the process return to user space.

Thus if the process (normally btrfs command) is falling into a long running ioctl (like scrub/dev-replace) it will not be frozen thus breaking the pm suspension.

This mean paused scrub is not feasible, as paused scrub will still make the ioctl executing process trapped inside kernel space.

- Filesystem freezing
It's an optional behavior during pm suspension, previously I submitted one patch detecting such situation, and so far it works as expected. But this fs freezing is only optional, not yet default behavior of pm suspension.

- Systemd slice freezing
Systemd slice freezing utilize cgroup freezer, and the freezing() checks will not return true until the whole cgroup is marked frozen.

But before that a wakeup signal is sent to the user process, and during the kernel signal handling that process will be frozen. So until the process returned to user space, it will not be marked frozen.

Thus we have to do regular pending signal checks to prevent cgroup freezing time out.

To address all those problems, the series will:

- Add extra cancel/pause/removed bg checks for raid56 parity stripes Mostly to reduce delay for RAID56 cases, and make the behavior more consistent.

- Cancel the scrub if the fs or process is being frozen Please note that here we have to check both fs and process freezing, please refer to the changelog and comment of the second patch for the reason.

- Cancel the scrub if there is a pending signal
This allows regular signal to interrupt scrub/dev-replace, without the extra signal handling hack in btrfs-progs (but that existing handling won't hurt either).

This also address the time out during systemd slice freezing. Unlike pm freezing, v2 cgroup freezing is fully based on signal handling thus freezing() function will not return true during v2 cgroup freeing.

So when v2 cgroup is freezing the processing running scrub/replace, we will properly detect a pending signal and abort the scrub/replace so that freezing can be done when the process returned to the user space.

[BEHAVIOR CHANGE]
Unfortunately this will bring a behavior change, and will mostly affecting dev-replace:

Dev-replace will be interrupted by pm, and can not be resumed but only starts from the beginning.

The same dev-replace now will fail due to pm, breaking the old expectation. End users will need extra steps to prevent suspension/hibernation instead.

And btrfs-progs also needs to be updated to handle the new -EINTR error (maybe restart the operation if possible).

Qu Wenruo (3):
btrfs: scrub: add cancel/pause/removed bg checks for raid56 parity
stripes
btrfs: scrub: cancel the run if the process or fs is being frozen
btrfs: scrub: cancel the run if there is a pending signal

 fs/btrfs/scrub.c | 70 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 60 insertions(+), 10 deletions(-)
Signature · 1 line
2.51.0