]> git.hungrycats.org Git - linux/commit
btrfs: stripe_alloc: complete parked writes on allocation coverage, not clocks
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sat, 19 Sep 2026 17:17:52 +0000 (13:17 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 23:37:48 +0000 (18:37 -0500)
commitb428dfea6a214992ba4a6d758d18285e337ef218
tree494f3bc151e5635b1e7a8eee791181cc31bbc670
parentce3c629be98bf496bd7fc92dbb7706568a052e54
btrfs: stripe_alloc: complete parked writes on allocation coverage, not clocks

A parked partial-stripe write goes down its RMW path when its deadline
expires or a retirement flush kicks it, even when every byte it is
missing below the run's frontier belongs to an allocation whose data IO
is already in flight -- allocation happens at writeback submission, and
the commit's retirement drain waits for exactly those arrivals.  Timing
out such a park buys nothing and costs a stripe read plus a second write
of the same stripe: measured on an 8-device raid5 buffered fill, the
100ms deadline turns ~2200 parked stripes per 2GB into read-modify-
writes (pad_decline_live), and stretching the clock 20x recovers only
14% -- the clock is the wrong instrument.

Replace the clock with a coverage test.  A parked rbio is ready when its
gathered bios cover everything the covering run has allocated inside its
stripe (btrfs_stripe_run_alloc_ceiling); the remainder lies at or past
the frontier, so the existing pad turns it into a single full-stripe
write with no read phase.  Merges check readiness as they land, the park
timer holds unready parks instead of expiring them, and run-retirement
flushes leave unready parks parked: the retirement has already closed
the run (freezing the allocated prefix) and its drain waits on the very
arrivals that will complete them.  Waiter-driven flushes (fsync's
pre-writeback kick, ordered-extent waits) and sync parks keep today's
forced behaviour: a blocked waiter's latency beats a saved stripe read.

A stuck cap (10x the park deadline) bounds the wait when an arrival can
never come: a writeback error abandoned the allocation, or the stripe
was already written once by a forced sync park.  Such parks are forced
down the old path and counted.

New sysfs stripe_park_stats counters: unparked_ready (parks completed by
the coverage test) and stuck (parks forced at the cap).

[zygo: 7.3 port: 7.3 has no per-chunk stripe length (map->stripe_len,
map->stripe_shift, two-argument btrfs_stripe_nr_to_offset()), context
adjusted to BTRFS_STRIPE_LEN; the change itself is unchanged]

Assisted-by: Claude:claude-fable-5
Assisted-by: Claude:claude-fable-5-1
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/file.c
fs/btrfs/fs.h
fs/btrfs/ordered-data.c
fs/btrfs/raid56.c
fs/btrfs/raid56.h
fs/btrfs/sysfs.c