]> git.hungrycats.org Git - linux/commitdiff
btrfs: stripe_alloc: count claimable whole-stripe supply directly
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sat, 19 Sep 2026 17:17:54 +0000 (13:17 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 23:37:49 +0000 (18:37 -0500)
Data reservations are admitted against arithmetic -- free space minus
trapped fragments minus open-run remainders minus a per-extent margin --
and under sustained near-full churn the arithmetic and the claim rule
disagree for long enough that admitted buffered writes reach writeback
with nothing claimable left: measured, ~5.2-5.5k reserved writebacks
dropped per fsstress churn run, silently for anything not waiting on
fsync.  Stock refuses the same write()s up front.  Nothing between
"durable by fsync" and "refused by write()" is acceptable when an
operator accident fills the disk.

First step, accounting only: measure the constraint instead of deriving
it.  bg->stripe_claimable counts bytes of fully free whole stripes --
exactly what btrfs_claim_free_stripe_run() can take, the complement of
stripe_unusable within each stripe.  The commit rescan derives it from
the same pass that computes trapped bytes (free minus trapped) and is
the sole upward correction; incremental maintenance under
ctl->tree_lock only ever DEBITS -- removals round their decrement OUT
to every touched stripe, claims subtract exactly what they took.  The
counter can therefore only under-count between commits, never
over-count.

Crediting freed whole stripes incrementally on the add side is
deliberately not done, having been tried and dropped.  Several add
paths re-add free space that a low-level remove never de-credited --
the async discard trim (unlink_free_space / bitmap_clear_bits, then
do_trimming's re-add through __btrfs_add_free_space) and
btrfs_remove_free_space's middle-split tail re-add -- so crediting on
add double-counts and drives the counter ABOVE the authoritative scan.
That is the dangerous direction: once admission gates on this counter,
an over-count admits reservations against phantom supply that writeback
then drops, while an under-count is an early, clean write()-time
ENOSPC.  Debit-only makes over-counting structurally impossible,
whatever a future re-add path forgets to de-credit.  (Reproduced with
compress+autodefrag+discard=async on a legacy-converted raid5
filesystem, incremental ~= 2x scanned; credit_return attribution
confirmed the phantom entered through do_trimming's re-add, not the
open-stripe allocator returns.)

A WARN_RATELIMIT at the rescan catches the dangerous direction anyway
(incremental above scanned), which under a debit-only rule means a
missed consumption site, and localizes it; the clamp to the scanned
value keeps every rescan authoritative regardless.  Rate limited rather
than _ONCE because such a gap recurs on every commit, and reporting
only the first hit hides that it is ongoing.

The space_info aggregate bytes_stripe_claimable follows the
stripe_unusable pattern (incremental between commits, re-totaled from
armed groups at the rescan), shows in the ENOSPC dump and in sysfs.
No admission change yet; that comes once the counter proves accurate
under the fill, churn, balance and reclaim suites.  The by-size
fast-fail in the claim keeps its early exit: the point of measuring is
to make such inputs trustworthy, not to search harder around them.

Data block groups only for now; raid56 metadata and mixed block groups
join when the data counter has settled.

A trim takes a free range out of the tree, drops tree_lock for the
discard and adds the range back, and a rescan in that window would find
fewer claimable stripes than the incremental count (seen as "incremental
stripe_claimable ... above scanned" with discard=async).  Each step
changes exactly the stripes the range belongs to, so the unlink debits
every one of them that was claimable (wholly free, not inside a live run:
the scan's rule) and the re-add credits every one that is claimable now,
in the tree_lock section that unlinks or links the range.  Rounding
instead would over-debit a stripe per trimmed sub-stripe hole, and async
discard trims thousands after a delete.  The wholly-free test falls back
to the bitmap lookup at offset_to_bitmap() as the other callers do, since
an extent entry starting inside a bitmap's window hides the bitmap from a
non-fuzzy search.

The nocow tail claim, btrfs_claim_stripe_tail(), now counts and removes
the tail in one ctl->tree_lock section, with claim_stripe_run_pieces()
doing the removal as for any claimed run, and fails with -ENOSPC unless
the whole tail is in the cache, debiting the
claimable count for what it removes in the same lock section.  It counted under the lock and then
called btrfs_remove_free_space(), which returns 0 when the range is not
in the cache at all: two allocations for the same inode (two direct
writers, writeback racing fallocate) or a trim holding an entry out could
both "remove" the same tail and hand out the same extent.  A self-test
claims the same tail twice.

[zygo: 7.3 port: 7.3 still tracks trimming ranges under
cache_writeout_mutex (v1 space cache); kept around the converted calls,
as on 6.18]

Assisted-by: Claude:claude-fable-5
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/free-space-cache.c
fs/btrfs/space-info.c
fs/btrfs/space-info.h
fs/btrfs/sysfs.c
include/trace/events/btrfs.h

index ddd9104e83d4134b9c23bcc2f23a1834449875c5..7811df8f11b1de3c9812c6cf9fcb6988ad7d5dc0 100644 (file)
@@ -1058,6 +1058,30 @@ bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
        return true;
 }
 
+/*
+ * Is the full stripe at @stripe inside a live run's range, i.e. stranded by
+ * the rule of btrfs_stripe_run_stranded_stripes()?  Caller holds
+ * ctl->tree_lock.
+ */
+bool btrfs_stripe_run_strands(struct btrfs_block_group *bg, u64 stripe)
+{
+       const u64 fsl = bg->full_stripe_len;
+       struct btrfs_open_stripe_run *run;
+       unsigned long flags;
+       bool ret = false;
+
+       spin_lock_irqsave(&bg->stripe_run_lock, flags);
+       list_for_each_entry(run, &bg->open_stripe_runs, list) {
+               if (run->end > run->start &&
+                   stripe < run->end && stripe + fsl > run->start) {
+                       ret = true;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&bg->stripe_run_lock, flags);
+       return ret;
+}
+
 /*
  * Lower an allocation ceiling to the end of the last live sector at or above
  * @floor.  Sectors between it and the frontier were allocated and abandoned:
@@ -1726,6 +1750,7 @@ void btrfs_scan_stripe_unusable(struct btrfs_fs_info *fs_info, bool force)
 
        list_for_each_entry(sinfo, &fs_info->space_info, list) {
                u64 total = 0;
+               u64 total_claimable = 0;
                int raid;
 
                if (!(sinfo->flags & BTRFS_BLOCK_GROUP_DATA))
@@ -1757,14 +1782,18 @@ void btrfs_scan_stripe_unusable(struct btrfs_fs_info *fs_info, bool force)
                                 * groups are excluded; their free space is already
                                 * accounted as read-only.
                                 */
-                               if (READ_ONCE(bg->stripe_unusable_ready))
+                               if (READ_ONCE(bg->stripe_unusable_ready)) {
                                        total += READ_ONCE(bg->stripe_unusable);
+                                       total_claimable +=
+                                               READ_ONCE(bg->stripe_claimable);
+                               }
                        }
                }
                up_read(&sinfo->groups_sem);
 
                spin_lock(&sinfo->lock);
                sinfo->bytes_stripe_unusable = total;
+               sinfo->bytes_stripe_claimable = total_claimable;
                /*
                 * The rescan usually lowers the counter (mid-transaction
                 * incremental adds overcount conservatively); admission
index 11eb1af0bd5fae63d9fd5a6e15ddf334d1519489..4f91a65dc97731f4e7497fefbe8629ae171c28ad 100644 (file)
@@ -278,6 +278,15 @@ struct btrfs_block_group {
         * free_space_ctl->tree_lock and space_info->lock.
         */
        u64 stripe_unusable;
+       /*
+        * Directly measured claimable supply: bytes of fully free, aligned
+        * whole stripes in the free space cache -- exactly what
+        * btrfs_claim_free_stripe_run() can take.  Maintained incrementally
+        * under ctl->tree_lock by rules meant to err only low (early
+        * write()-time ENOSPC); the commit rescan corrects it, and warns if
+        * it was ever high.
+        */
+       u64 stripe_claimable;
        /*
         * Upper bound on the longest run btrfs_claim_free_stripe_run() can
         * find, learned from actual scans: (u64)-1 means unknown, 0 means an
@@ -442,6 +451,7 @@ void btrfs_close_bg_open_stripes(struct btrfs_block_group *bg);
 void btrfs_retire_block_group_stripes(struct btrfs_block_group *bg);
 void btrfs_wake_open_stripe_waiters(struct btrfs_fs_info *fs_info);
 bool btrfs_stripe_in_open_run(struct btrfs_fs_info *fs_info, u64 logical);
+bool btrfs_stripe_run_strands(struct btrfs_block_group *bg, u64 stripe);
 bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
                                   u64 run_start, u64 *run_len);
 /*
index ce9c0d08690d5a1a5314d947f039ac956e087cad..6dbab0f6f576c1f430418acf9026e0c8148b6ff1 100644 (file)
@@ -2617,9 +2617,15 @@ static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl,
        }
 }
 
-static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
-                          u64 offset, u64 bytes,
-                          enum btrfs_trim_state trim_state)
+static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta);
+static u64 stripe_touched_bytes(const struct btrfs_block_group *bg,
+                               u64 bytenr, u64 size);
+static void stripe_trim_claimable(struct btrfs_block_group *bg, u64 bytenr,
+                                 u64 size, bool out);
+
+static int add_free_space(struct btrfs_block_group *block_group,
+                         u64 offset, u64 bytes,
+                         enum btrfs_trim_state trim_state, bool trim_return)
 {
        struct btrfs_fs_info *fs_info = block_group->fs_info;
        struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
@@ -2677,6 +2683,18 @@ link:
        if (ret)
                kmem_cache_free(btrfs_free_space_cachep, info);
 out:
+       /*
+        * Adding free space never credits stripe_claimable: some add paths
+        * re-add space that was never debited (the tail of
+        * btrfs_remove_free_space()'s middle split), and crediting would
+        * count it twice.  The counter may only err low (an early ENOSPC); an
+        * over-count admits reservations writeback cannot place.  The commit
+        * rescan is the only upward correction -- except for a trim's return,
+        * whose range was debited when the trim took it out (see
+        * stripe_trim_claimable()).
+        */
+       if (!ret && trim_return)
+               stripe_trim_claimable(block_group, offset, bytes, false);
        btrfs_discard_update_discardable(block_group);
        spin_unlock(&ctl->tree_lock);
 
@@ -2693,6 +2711,13 @@ out:
        return ret;
 }
 
+static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
+                                 u64 offset, u64 bytes,
+                                 enum btrfs_trim_state trim_state)
+{
+       return add_free_space(block_group, offset, bytes, trim_state, false);
+}
+
 static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
                                        u64 bytenr, u64 size, bool used)
 {
@@ -2756,6 +2781,133 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
 
 static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
 
+/*
+ * Debit the claimable whole-stripe supply for claims and removals.  Returned
+ * free space is never credited here (see add_free_space()), save a trim's
+ * return (stripe_trim_claimable()); the commit rescan restores it.  Caller
+ * holds ctl->tree_lock.
+ */
+static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta)
+{
+       struct btrfs_space_info *sinfo = bg->space_info;
+
+       if (!READ_ONCE(bg->stripe_unusable_ready) || !delta)
+               return;
+       if (delta < 0 && bg->stripe_claimable < (u64)-delta)
+               delta = -(s64)bg->stripe_claimable;
+       if (!delta)
+               return;
+       bg->stripe_claimable += delta;
+       if (!sinfo)
+               return;
+       spin_lock(&sinfo->lock);
+       if (delta < 0 && sinfo->bytes_stripe_claimable < (u64)-delta)
+               sinfo->bytes_stripe_claimable = 0;
+       else
+               btrfs_space_info_update_bytes_stripe_claimable(sinfo, delta);
+       spin_unlock(&sinfo->lock);
+}
+
+/* The whole-stripe span [bytenr, bytenr + size) touches at all. */
+static u64 stripe_touched_bytes(const struct btrfs_block_group *bg,
+                               u64 bytenr, u64 size)
+{
+       const u64 fsl = bg->full_stripe_len;
+       const u64 rel = bytenr - bg->start;
+       const u64 astart = div64_u64(rel, fsl) * fsl;
+       const u64 aend = div64_u64(rel + size + fsl - 1, fsl) * fsl;
+
+       return aend - astart;
+}
+
+/* Is all of [start, end) free?  Caller holds ctl->tree_lock. */
+static bool stripe_range_free(struct btrfs_free_space_ctl *ctl,
+                             u64 start, u64 end)
+{
+       const u32 unit = ctl->block_group->fs_info->sectorsize;
+       u64 pos = start;
+
+       while (pos < end) {
+               struct btrfs_free_space *e = tree_search_offset(ctl, pos, 0, 0);
+               unsigned long bit;
+
+               /*
+                * An extent entry that starts inside a bitmap's window and
+                * ends before pos hides that bitmap from the search above;
+                * look it up by its own offset, as btrfs_remove_free_space()
+                * does.
+                */
+               if (!e)
+                       e = tree_search_offset(ctl, offset_to_bitmap(ctl, pos),
+                                              1, 0);
+               if (!e)
+                       return false;
+               if (!e->bitmap) {
+                       /* An extent entry returned here covers pos. */
+                       pos = e->offset + e->bytes;
+                       continue;
+               }
+               bit = div_u64(pos - e->offset, unit);
+               if (!test_bit(bit, e->bitmap))
+                       return false;
+               pos = e->offset + (u64)find_next_zero_bit(e->bitmap,
+                               BITS_PER_BITMAP, bit) * unit;
+       }
+       return true;
+}
+
+/*
+ * The claimable stripes that [bytenr, bytenr + size) belongs to, counting
+ * the range itself as free: by the scan's rule (stripe_unusable_scan()),
+ * every stripe that is wholly free and not inside a live stripe run.
+ * Caller holds ctl->tree_lock; stripe_run_lock nests inside it.
+ */
+static u64 stripe_claimable_with_range(struct btrfs_block_group *bg,
+                                      u64 bytenr, u64 size)
+{
+       struct btrfs_free_space_ctl *ctl = bg->free_space_ctl;
+       const u64 fsl = bg->full_stripe_len;
+       const u64 end = bytenr + size;
+       const u64 bg_end = btrfs_block_group_end(bg);
+       u64 whole = 0;
+       u64 s;
+
+       for (s = bg->start + div64_u64(bytenr - bg->start, fsl) * fsl;
+            s < end && s + fsl <= bg_end; s += fsl) {
+               if (s < bytenr && !stripe_range_free(ctl, s, bytenr))
+                       continue;
+               if (s + fsl > end && !stripe_range_free(ctl, end, s + fsl))
+                       continue;
+               if (!btrfs_stripe_run_strands(bg, s))
+                       whole += fsl;
+       }
+       return whole;
+}
+
+/*
+ * A trim takes a free range out of the tree for the length of its discard
+ * (trim_no_bitmap(), trim_bitmaps()) and do_trimming() adds it back.  A
+ * rescan in between scans a tree without the range, so the incremental
+ * count must not include it either.  Each step changes exactly the stripes
+ * the range belongs to: taking it out (@out) makes every one of them that
+ * was claimable unclaimable, and adding it back makes claimable every one
+ * that is claimable now.  Debit and credit those, in the tree_lock section
+ * that unlinks or links the range, so the count stays as exact as it was.
+ * Caller holds ctl->tree_lock; for @out, the range is already unlinked.
+ */
+static void stripe_trim_claimable(struct btrfs_block_group *bg, u64 bytenr,
+                                 u64 size, bool out)
+{
+       s64 delta;
+
+       if (!btrfs_is_stripe_alloc_bg(bg))
+               return;
+       if (!READ_ONCE(bg->stripe_unusable_ready) || !size)
+               return;
+       delta = stripe_claimable_with_range(bg, bytenr, size);
+       stripe_claimable_mod(bg, out ? -delta : delta);
+}
+
 /*
  * Count the sub-stripe head and tail of a returning free range as trapped
  * at once: reservations read bytes_stripe_unusable mid-transaction, and the
@@ -2874,6 +3026,19 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group,
 
        spin_lock(&ctl->tree_lock);
 
+       /*
+        * The removed bytes leave free space; every whole stripe the range
+        * touches may lose wholeness (a boundary fragment removal breaks a
+        * fully free stripe as surely as an interior one empties it).
+        * Rounding the decrement OUT to touched stripes errs claimable-low.
+        * The trapped counter is deliberately not decremented for removed
+        * fragments: leaving it high is the safe direction, and the rescan
+        * settles both.
+        */
+       if (btrfs_is_stripe_alloc_bg(block_group))
+               stripe_claimable_mod(block_group,
+                       -(s64)stripe_touched_bytes(block_group, offset, bytes));
+
 again:
        ret = 0;
        if (!bytes)
@@ -3316,7 +3481,7 @@ static void stripe_return_clusters(struct btrfs_block_group *bg)
 void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
 {
        struct btrfs_free_space_ctl *ctl = bg->free_space_ctl;
-       u64 trapped, nstripes;
+       u64 trapped, claimable, nstripes;
        u32 *freep;
 
        if (!btrfs_is_stripe_alloc_bg(bg))
@@ -3338,14 +3503,19 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
        }
        trapped = stripe_unusable_scan(bg, freep, nstripes);
        bg->stripe_unusable = trapped;
+       /* Every free byte is claimable or trapped; the scan split them. */
+       bg->stripe_claimable = ctl->free_space - trapped;
+       claimable = bg->stripe_claimable;
        bg->stripe_unusable_ready = true;
        spin_unlock(&ctl->tree_lock);
        kvfree(freep);
 
-       if (trapped) {
+       if (trapped || claimable) {
                spin_lock(&bg->space_info->lock);
                btrfs_space_info_update_bytes_stripe_unusable(bg->space_info,
                                                              trapped);
+               btrfs_space_info_update_bytes_stripe_claimable(bg->space_info,
+                                                              claimable);
                spin_unlock(&bg->space_info->lock);
        }
 }
@@ -3362,6 +3532,7 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
 {
        struct btrfs_free_space_ctl *ctl = bg->free_space_ctl;
        u64 trapped;
+       u64 claimable;
 
        if (!btrfs_is_stripe_alloc_bg(bg))
                return;
@@ -3372,13 +3543,17 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
                return;
        }
        trapped = bg->stripe_unusable;
+       claimable = bg->stripe_claimable;
+       bg->stripe_claimable = 0;
        bg->stripe_unusable_ready = false;
        spin_unlock(&ctl->tree_lock);
 
-       if (trapped) {
+       if (trapped || claimable) {
                spin_lock(&bg->space_info->lock);
                btrfs_space_info_update_bytes_stripe_unusable(bg->space_info,
                                                              -(s64)trapped);
+               btrfs_space_info_update_bytes_stripe_claimable(bg->space_info,
+                                                              -(s64)claimable);
                spin_unlock(&bg->space_info->lock);
        }
 }
@@ -3407,8 +3582,23 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
 
        stripe_return_clusters(bg);
        spin_lock(&ctl->tree_lock);
-       if (bg->stripe_unusable_ready)          /* skip if disarmed (read-only) */
+       if (bg->stripe_unusable_ready) {        /* skip if disarmed (read-only) */
+               u64 scanned;
+
                bg->stripe_unusable = stripe_unusable_scan(bg, freep, nstripes);
+               scanned = ctl->free_space - bg->stripe_unusable;
+               /*
+                * The incremental rules may only under-count claimable
+                * supply; more than the scan finds means a missed debit,
+                * which admits reservations writeback cannot honor.  Rate
+                * limited, not _ONCE, because such a gap recurs every commit.
+                * The assignment below keeps the rescan authoritative.
+                */
+               WARN_RATELIMIT(bg->stripe_claimable > scanned,
+                         "bg %llu incremental stripe_claimable %llu above scanned %llu",
+                         bg->start, bg->stripe_claimable, scanned);
+               bg->stripe_claimable = scanned;
+       }
        spin_unlock(&ctl->tree_lock);
        kvfree(freep);
        /*
@@ -3826,6 +4016,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
                }
                spare_used = claim_stripe_run_pieces(block_group, run_start,
                                                     run_len, spare);
+               stripe_claimable_mod(block_group, -(s64)run_len);
                *start = run_start;
                *len = run_len;
                ret = 0;
@@ -3865,6 +4056,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
                        head_len = 0;
                }
        }
+       stripe_claimable_mod(block_group, -(s64)run_len);
        *start = run_start;
        *len = run_len;
        ret = 0;
@@ -4423,13 +4615,12 @@ static int do_trimming(struct btrfs_block_group *block_group,
 
        mutex_lock(&ctl->cache_writeout_mutex);
        if (reserved_start < start)
-               __btrfs_add_free_space(block_group, reserved_start,
-                                      start - reserved_start,
-                                      reserved_trim_state);
+               add_free_space(block_group, reserved_start,
+                              start - reserved_start, reserved_trim_state, true);
        if (end < reserved_end)
-               __btrfs_add_free_space(block_group, end, reserved_end - end,
-                                      reserved_trim_state);
-       __btrfs_add_free_space(block_group, start, bytes, trim_state);
+               add_free_space(block_group, end, reserved_end - end,
+                              reserved_trim_state, true);
+       add_free_space(block_group, start, bytes, trim_state, true);
        list_del(&trim_entry->list);
        mutex_unlock(&ctl->cache_writeout_mutex);
 
@@ -4534,6 +4725,8 @@ static int trim_no_bitmap(struct btrfs_block_group *block_group,
                        unlink_free_space(ctl, entry, true);
                        kmem_cache_free(btrfs_free_space_cachep, entry);
                }
+               stripe_trim_claimable(block_group, extent_start, extent_bytes,
+                                     true);
 
                spin_unlock(&ctl->tree_lock);
                trim_entry.start = extent_start;
@@ -4765,6 +4958,7 @@ static int trim_bitmaps(struct btrfs_block_group *block_group,
                bitmap_clear_bits(ctl, entry, start, bytes, true);
                if (entry->bytes == 0)
                        free_bitmap(ctl, entry);
+               stripe_trim_claimable(block_group, start, bytes, true);
 
                spin_unlock(&ctl->tree_lock);
                trim_entry.start = start;
index cf354c1d38270e1b3c2db37ef45e450fb48c5945..d67a80b02fe0011cccc1a5781e0bc43172d22cc4 100644 (file)
@@ -715,11 +715,12 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
                   (s64)(info->total_bytes - btrfs_space_info_used(info, true)),
                   info->full ? "" : "not ");
        btrfs_info(fs_info,
-"space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu zone_unusable=%llu stripe_unusable=%llu stripe_open=%llu stripe_margin=%llu",
+"space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu zone_unusable=%llu stripe_unusable=%llu stripe_open=%llu stripe_margin=%llu stripe_claimable=%llu",
                info->total_bytes, info->bytes_used, info->bytes_pinned,
                info->bytes_reserved, info->bytes_may_use,
                info->bytes_readonly, info->bytes_zone_unusable,
                info->bytes_stripe_unusable, info->bytes_stripe_open,
+               info->bytes_stripe_claimable,
                info->bytes_stripe_margin);
 }
 
index 0f8aad3db40b7fd3eb40847d2759904d8c02b44a..85a9edfdc7d9b89aa25cb66802a261b8a08201b8 100644 (file)
@@ -160,6 +160,10 @@ struct btrfs_space_info {
                                           stripes stranded behind live runs.
                                           Counted as used, and subtracted in
                                           statfs. */
+       u64 bytes_stripe_claimable;     /* sum of armed groups' directly
+                                          measured claimable whole-stripe
+                                          bytes; see stripe_claimable in
+                                          struct btrfs_block_group */
        u64 bytes_stripe_open;          /* sum of open stripe runs' unallocated
                                           remainders.  Claimed out of the free
                                           space cache but not yet allocated;
@@ -328,6 +332,7 @@ DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info");
 DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
 DECLARE_SPACE_INFO_UPDATE(bytes_zone_unusable, "zone_unusable");
 DECLARE_SPACE_INFO_UPDATE(bytes_stripe_unusable, "stripe_unusable");
+DECLARE_SPACE_INFO_UPDATE(bytes_stripe_claimable, "stripe_claimable");
 
 static inline u64 btrfs_space_info_used(const struct btrfs_space_info *s_info,
                                        bool may_use_included)
index 7e15044b408d37e67c47c15aafc769f4b18be53f..d254f3cc9e64d9a00e0ee4c96e6d550fef16dc2f 100644 (file)
@@ -930,6 +930,7 @@ SPACE_INFO_ATTR(bytes_may_use);
 SPACE_INFO_ATTR(bytes_readonly);
 SPACE_INFO_ATTR(bytes_zone_unusable);
 SPACE_INFO_ATTR(bytes_stripe_unusable);
+SPACE_INFO_ATTR(bytes_stripe_claimable);
 SPACE_INFO_ATTR(bytes_stripe_open);
 SPACE_INFO_ATTR(bytes_stripe_margin);
 SPACE_INFO_ATTR(disk_used);
@@ -1062,6 +1063,7 @@ static struct attribute *space_info_attrs[] = {
        BTRFS_ATTR_PTR(space_info, bytes_readonly),
        BTRFS_ATTR_PTR(space_info, bytes_zone_unusable),
        BTRFS_ATTR_PTR(space_info, bytes_stripe_unusable),
+       BTRFS_ATTR_PTR(space_info, bytes_stripe_claimable),
        BTRFS_ATTR_PTR(space_info, bytes_stripe_open),
        BTRFS_ATTR_PTR(space_info, bytes_stripe_margin),
        BTRFS_ATTR_PTR(space_info, disk_used),
index db541d70e964098279fec6e51b1fe6cbcf186117..e95f1b3a8a0c56fad0a33866dcd0a16179e41e2f 100644 (file)
@@ -3299,6 +3299,14 @@ DEFINE_EVENT(btrfs__space_info_update, update_bytes_stripe_unusable,
        TP_ARGS(fs_info, sinfo, old, diff)
 );
 
+DEFINE_EVENT(btrfs__space_info_update, update_bytes_stripe_claimable,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_space_info *sinfo, u64 old, s64 diff),
+
+       TP_ARGS(fs_info, sinfo, old, diff)
+);
+
 TRACE_EVENT(btrfs_stripe_pad_decline,
 
        TP_PROTO(const struct btrfs_fs_info *fs_info, u64 full_stripe,