btrfs: stripe_alloc: count whole stripes stranded behind live runs as trapped
The data admission gate admits a reservation while the whole-stripe
supply, bytes_stripe_claimable, covers it, and the per-commit scan
measures that supply as the block group's wholly free full stripes.
But a wholly free stripe inside a live stripe run's range cannot be
claimed: btrfs_stripe_run_range_usable() rejects any claim overlapping
a run object, because a second run over the same range would make the
range-to-run lookups ambiguous. The run was claimed over the stripe,
the extents allocated there were freed again, and the run has not been
freed yet. For a COW run that window closes at the next commit; a
nodatacow inode's private run deliberately survives commits and lives
until the inode is evicted.
On a raid56 filesystem filled to ENOSPC by fsstress (thousands of
fallocated files, so thousands of cached inodes each holding a private
NOCOW run) a live walk of the free space cache showed the accounting
exact -- the wholly free stripes summed to bytes_stripe_claimable to the
byte -- and 99% of them inside the ranges of open NOCOW runs with no
inflight IO: 22.8 MiB of 22.8 MiB behind 387 runs in one group, 73.4 MiB
of 73.4 MiB behind 976 runs in another. Every claim failed in O(1) on
the "no claimable run" verdict, every write() admitted against the 99 MiB
of phantom supply failed at writeback, and the data was dropped ("data
writeback allocation ... returned ENOSPC despite reservation margin"),
about 100,000 delalloc ranges per run of the degraded acceptance suite
where the stock allocator drops none.
Have the scan take such stripes out of the claimable supply: count them
in stripe_unusable, which btrfs_space_info_used() already charges so the
gate cannot admit against them, and record them separately as
stripe_stranded so that btrfs_stripe_bg_wants_reclaim() does not ask
relocation to recover space that comes back by itself. When a run is
freed, mark its group for rescan so the next commit credits the stripes
back. The space_info total is exposed as bytes_stripe_stranded in sysfs
and in the space info dump.
This makes the gate honest -- write() gets the ENOSPC instead of
writeback dropping the data -- but does not return the stranded space
while the runs live; that is the run lifecycle's business.
The space_info totals are kept equal to the sum of the armed groups:
claim, arm, disarm and rescan update a group's value and the total
together under sinfo->lock, and the commit scan sums the groups under
sinfo->lock while it holds groups_sem. Reading the groups unlocked and
assigning the totals later lost or doubled updates made in between, and a
group made read-only could have its whole claimable supply counted again
until the next commit, admitting writes that writeback could not place.
The scan does not restore the stripe_meta margin and reserve when
stripe_alloc was disabled after it started.