/*
* Which sectors of this stripe may be padded?
*
- * Fills @dead with one bit per sector of the stripe, set where the sector
- * holds nothing anyone intends to write: space the run has not handed out
- * yet, and space it handed out but got back before the write was issued.
- * A caller may zero-fill exactly those and write the whole stripe.
+ * Fills @dead with one bit per sector, set where the sector holds nothing
+ * anyone has written: never handed out, handed out and abandoned, or
+ * handed out with the write not yet completed (per the run's written map).
+ * The caller may zero-fill exactly those and write the whole stripe.
+ * @unwritten, when non-NULL, gets the subset that is allocated but
+ * unwritten.
*
- * Returns false if no run covers the stripe, in which case nothing may be
- * padded: without a run there is no claim of exclusivity, and an uncovered
- * sector may hold committed data.
+ * Zeroing an allocated sector whose write is still to come is safe: the
+ * caller holds the stripe lock, which every raid56 write to the stripe
+ * takes, so that write lands after the caller's; completed writes are in
+ * the written map before the stripe is unlocked (rbio_orig_end_io()); and
+ * nothing reads the sector before its own write lands, since its extent is
+ * not committed until then. A NOCOW run's written map is not consulted:
+ * its live sectors are rewritten in place, so they may already hold data.
*
- * This replaces asking where the run's frontier is. The frontier answers
- * "what has never been allocated", which misses allocations that were
- * abandoned below it -- a tree block COWed twice in one transaction, a
- * reservation released, an allocation the finder discarded. Those leave
- * holes that are equally safe to pad, and skipping them is the difference
- * between padding most partial stripes and padding all of them.
- *
- * @info, when non-NULL, reports the covering run's state at the moment of
- * the decision, for the pad-decline trace: a later extent-tree dump cannot
- * reconstruct where the frontier was when the write arrived.
+ * Returns false if no run covers the stripe; nothing may be padded then,
+ * since an uncovered sector may hold committed data. @info, when non-NULL,
+ * records the covering run's state for the pad-decline trace.
*/
bool btrfs_stripe_run_pad_mask(struct btrfs_fs_info *fs_info, u64 stripe_start,
u64 stripe_len, unsigned long *dead,
+ unsigned long *unwritten,
struct btrfs_stripe_pad_info *info)
{
const u32 bits = fs_info->sectorsize_bits;
if (first + nsectors > run->live_nbits)
break;
bitmap_zero(dead, nsectors);
- for (u32 i = 0; i < nsectors; i++)
- if (!test_bit(first + i, run->live))
+ if (unwritten)
+ bitmap_zero(unwritten, nsectors);
+ for (u32 i = 0; i < nsectors; i++) {
+ if (!test_bit(first + i, run->live)) {
+ set_bit(i, dead);
+ } else if (run->written &&
+ !test_bit(first + i, run->written)) {
set_bit(i, dead);
+ if (unwritten)
+ set_bit(i, unwritten);
+ }
+ }
if (info)
info->reason = BTRFS_STRIPE_PAD_OK;
ret = true;
const u32 nsectors = rbio->nr_data * rbio->stripe_nsectors;
struct btrfs_stripe_pad_info info;
unsigned long *dead;
+ unsigned long *unwritten;
u32 covered = 0;
+ u32 nr_unwritten = 0;
bool ok = false;
int i;
return false;
dead = bitmap_zalloc(nsectors, GFP_NOFS);
- if (!dead)
+ unwritten = bitmap_zalloc(nsectors, GFP_NOFS);
+ if (!dead || !unwritten) {
+ bitmap_free(dead);
+ bitmap_free(unwritten);
return false;
+ }
if (!btrfs_stripe_run_pad_mask(fs_info, stripe_start, stripe_len, dead,
- &info)) {
+ unwritten, &info)) {
trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
stripe_len, 0, 0, nsectors,
info.run_start, info.run_end,
covered++;
/*
- * Every data sector this rbio does not cover must be dead. A live
- * uncovered sector belongs to another writer's allocation and this
- * write does not carry its data, so padding would destroy it: that
- * is a distinct refusal from the oracle's, and it is the one that
- * says another writer's allocation shares this stripe.
+ * Every uncovered sector must be dead per the run. A live uncovered
+ * sector that was already written holds data this write does not
+ * carry, so refuse (UNCOVERED); the stripe pin (rbio_needs_pin())
+ * normally supplies such sectors from the cache, so nothing is read.
*/
for (i = 0; i < nsectors; i++) {
if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
info.reason);
goto out;
}
+ if (test_bit(i, unwritten))
+ nr_unwritten++;
}
ok = true;
out:
bitmap_free(dead);
+ bitmap_free(unwritten);
if (!ok)
return false;
bitmap_set(&rbio->dbitmap, 0, rbio->stripe_nsectors);
spin_unlock(&rbio->bio_list_lock);
atomic64_inc(&fs_info->stripe_park_stats.padded);
+ if (nr_unwritten)
+ atomic64_inc(&fs_info->stripe_park_stats.padded_unwritten);
return true;
}
"expired %lld\n"
"stuck %lld\n"
"padded %lld\n"
+ "padded_unwritten %lld\n"
"rmw_reads %lld\n",
atomic64_read(&fs_info->stripe_park_stats.parked),
atomic64_read(&fs_info->stripe_park_stats.merged_bytes),
atomic64_read(&fs_info->stripe_park_stats.expired),
atomic64_read(&fs_info->stripe_park_stats.stuck),
atomic64_read(&fs_info->stripe_park_stats.padded),
+ atomic64_read(&fs_info->stripe_park_stats.padded_unwritten),
atomic64_read(&fs_info->stripe_park_stats.rmw_reads));
}
BTRFS_ATTR(, stripe_park_stats, btrfs_stripe_park_stats_show);