Skip to content

RFC bcachefs: make btree bitmap GC crash safe

Matthias Goergens linux-bcachefs 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest1 patch 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1bcachefs: make btree bitmap GC crash safefs/sb/members.c+50 -30 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [RFC PATCH 0/1] bcachefs: make btree bitmap GC crash safe

Hi Kent,

Bitmap GC can replace the member bitmap while an interior update has changed the in-memory topology but has not made its new nodes and parent pointer durable. A crash can then leave old nodes reachable but absent from the bitmap.

I will send the ktest patch separately in this thread; it applies to ktest master. The test evacuates a member and holds btree-node and journal writes on both devices with dm-delay. It runs bitmap GC while interior updates are in flight, then checks offline crash copies taken before and after the held writes are released. A no-GC case checks a crash copy taken under the same I/O delay.

I reran the three cases on bcachefs-tools testing at a3e92ebc6d6f, using a 7.3.0-rc2 VM kernel and separately built debug/test-hook modules. The no-GC case held 71 interior updates and passed offline fsck. The unfixed GC case also held 71 updates; GC published early and both crash copies failed fsck, with 57 bitmap errors. With the fix, GC waited for 72 held updates, then both copies passed fsck without bitmap errors.

The fix drains pending interior updates, rechecks and scans under gc.lock, then flushes the journal before publishing the new bitmap. Earlier focused runs also exercised the drain/recheck retry, read-only transition and journal-error paths. The source patch is based on bcachefs-tools testing at a3e92ebc6d6f; the ktest patch is based on ktest master at 1fa3232f27cd and applies to the newer master checked before sending. The focused tests are:

btree_bitmap_gc_crash
btree_bitmap_gc_crash_no_gc

I have two open performance/liveness questions. The pre-scan drain waits for the interior-update list to become empty, so a sustained overlapping stream may delay this pass indefinitely. The gc.lock writer also spans the full bitmap walk, including disk reads and any superblock repair writes, and can delay interior updates. The VM results above establish crash behaviour on a small tree; they do not measure these costs on a large filesystem. I would welcome guidance on that trade-off.

Matthias