[PATCH RESEND 3/3] md/raid10: keep look-ahead bitmap chunks when resync is interrupted

From: Eric Hagberg

Date: Fri Dec 04 2026 - 12:46:38 EST


From: Jason Chu <jaschu@xxxxxxxxxxxxxx>

bitmap_start_sync() always covers at least one page worth of sectors from
the offset it is given. If fewer sectors than that remain in the bitmap
chunk that holds the offset, it also moves the next chunk from NEEDED to
RESYNC. Call this the look-ahead.

A resync reaches such an offset when a bad block has shortened an earlier
window, so that the cursor is no longer page aligned. From reading the
code, it also does so whenever the bitmap chunk is smaller than a page.

If the resync is interrupted while the cursor is still inside the first
chunk, the final call to raid10_sync_request() ends the chunk at
curr_resync only. bitmap_close_sync() then clears RESYNC on the
look-ahead chunk without setting NEEDED. The restarted resync skips that
chunk as clean, and copies that differ inside it are not made equal.

Reproduced in a KVM guest with the "resync-abort" test of the script in
the cover letter: 2 members, near=2, 4KiB chunks, 1MiB bitmap chunks,
bitmap chunks 0 and 1 dirty, one bad block on member 0 five sectors
before the end of bitmap chunk 0, and the two copies of one sector in
bitmap chunk 1 different. The test holds the I/O of one member to stop
the resync with its cursor between the bad block and the end of bitmap
chunk 0, then restarts the resync and lets it finish:

v7.4-rc5 with the two previous patches:
verdict=FAIL stopped_at=2044 copies_of_sector_3048=differ
mismatch_cnt=128
with this patch:
verdict=PASS stopped_at=2044 copies_of_sector_3048=equal
mismatch_cnt=0

On an aborted resync with the classic bitmap, re-arm the in-progress
chunks from the one that holds curr_resync to the end, then call
close_sync() as before. md has waited for all resync I/O before the
final call, so the chunks below curr_resync are complete and can be
closed. A resync that is interrupted and restarted again and again
therefore still makes progress.

curr_resync can hold one of the MD_RESYNC_* markers instead of a sector
when the resync is interrupted before its first step. Walk from sector 0
in that case.

The cost is a second walk over the bitmap counters when a resync is
aborted.

Fixes: 1187cf0a3c8b ("md: Allow write-intent bitmaps to have chunksize < PAGE_SIZE")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jason Chu <jaschu@xxxxxxxxxxxxxx>
Signed-off-by: Eric Hagberg <ehagberg@xxxxxxxxxxxxxx>
---
drivers/md/raid10.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index e42abe7..2de4ec1 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3090,6 +3090,12 @@ static bool raid10_classic_bitmap(struct mddev *mddev)
* member for the far layout. An aborted recovery therefore re-arms every
* in-progress chunk (@start == 0). A chunk whose copies are all done may
* stay dirty and be copied again, but an unfinished copy is not skipped.
+ *
+ * Resync looks ahead: bitmap start_sync puts at least a page worth of
+ * sectors from the cursor in progress, which can include the chunk after
+ * the one that holds the cursor. An aborted resync re-arms the chunks from
+ * the one that holds the cursor onward. The caller then closes the chunks
+ * behind it, whose I/O has completed, so that progress is kept.
*/
static void raid10_abort_sync_bitmap(struct mddev *mddev, sector_t start)
{
@@ -3236,6 +3242,19 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
* still have copies outstanding.
*/
raid10_abort_sync_bitmap(mddev, 0);
+ } else if (aborted && raid10_classic_bitmap(mddev)) {
+ sector_t start = mddev->curr_resync;
+
+ /* An MD_RESYNC_* marker, or within the first sectors. */
+ if (start <= MD_RESYNC_ACTIVE)
+ start = 0;
+ /*
+ * All resync I/O below curr_resync has completed.
+ * Re-arm the look-ahead from there, then close the
+ * chunks behind it as a completed sync would.
+ */
+ raid10_abort_sync_bitmap(mddev, start);
+ mddev->bitmap_ops->close_sync(mddev);
} else if (md_bitmap_enabled(mddev, false)) {
mddev->bitmap_ops->close_sync(mddev);
}
--
2.43.7