/*
* Reclaim gives up on a space_info for a while after this many reclaims in a
- * row failed with -ENOSPC. Relocating a group needs room for
+ * row failed with -ENOSPC. Relocating or compacting a group needs room for
* its live data (and metadata reservations for moving it); at the fill edge
* there is none, every attempt fails after doing its work, and retrying each
* failed group on every worker run held the balance exclusive operation for
/*
* Backing off: drop the group rather than requeue it. The
* rescans and usage updates queue it again once reclaim may
- * succeed.
+ * succeed. A stripe_reclaim_now request is tried regardless.
*/
- if (btrfs_reclaim_backoff_active(space_info)) {
+ if (!READ_ONCE(bg->stripe_reclaim_forced) &&
+ btrfs_reclaim_backoff_active(space_info)) {
ret = 0;
} else {
int before = reclaimed;
continue;
if (!btrfs_stripe_bg_wants_reclaim(bg))
continue;
+ if (btrfs_reclaim_backoff_active(sinfo))
+ break;
spin_lock(&bg->lock);
if (btrfs_mark_bg_to_reclaim(bg))
bg->stripe_reclaim_jiffies = jiffies ?: 1;
* and queueing a group with nowhere to move it only costs writers read-only
* transitions. Counters are read unlocked; the worker re-checks.
*/
+/*
+ * Relocation reserves metadata before it moves anything: 256 tree blocks
+ * up front (RELOCATION_RESERVED_NODES), doubled on its first shortfall. When
+ * the metadata space_info can neither hold nor overcommit that, relocating
+ * or compacting a data group fails with -ENOSPC after the group was made
+ * read-only, while the worker held the exclusive operation (octopus P1 at the
+ * fill edge, bhive 2026-10-20: the data side had room, metadata had none).
+ */
+#define STRIPE_RECLAIM_META_NODES 512
+
+static bool stripe_reclaim_meta_room(struct btrfs_fs_info *fs_info)
+{
+ struct btrfs_space_info *meta;
+ const u64 bytes = (u64)fs_info->nodesize * STRIPE_RECLAIM_META_NODES;
+
+ bool ok;
+
+ meta = btrfs_find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
+ if (!meta)
+ return true;
+ spin_lock(&meta->lock);
+ ok = btrfs_space_info_used(meta, true) + bytes <= meta->total_bytes ||
+ btrfs_can_overcommit(meta, bytes, BTRFS_RESERVE_FLUSH_ALL);
+ spin_unlock(&meta->lock);
+ return ok;
+}
+
static enum stripe_reclaim_kind __stripe_bg_reclaim_kind(struct btrfs_block_group *bg,
int thresh, bool force,
bool check_room,
READ_ONCE(sinfo->bytes_stripe_margin);
elsewhere -= min(elsewhere, READ_ONCE(bg->stripe_claimable));
elsewhere -= min(elsewhere, promised);
- return elsewhere + extra_room >= need ? kind : STRIPE_RECLAIM_NONE;
+ if (elsewhere + extra_room < need)
+ return STRIPE_RECLAIM_NONE;
+ return stripe_reclaim_meta_room(bg->fs_info) ? kind : STRIPE_RECLAIM_NONE;
}
static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group *bg,
}
spin_unlock(&ctl->tree_lock);
kvfree(freep);
+ /* Reclaim backing off after ENOSPC: leave the group, the stamp too. */
+ if (reclaim && btrfs_reclaim_backoff_active(bg->space_info))
+ reclaim = false;
if (reclaim) {
/*
* Stamp the hysteresis only if the mark lands: a group still on