bool compacted = false;
/*
- * A stripe_alloc group's live extents can only move into
+ * A stripe_alloc / stripe_meta group's live extents can only move into
* whole free stripes. When the rest of the space_info has too few
* claimable bytes for them, allocate a chunk to relocate into, once per
* attempt. Done here rather than in the reservation path so that a
* device shrink, which relocates without spare room by design, still
* fails cleanly.
*/
- if (btrfs_is_stripe_alloc_bg(bg)) {
+ if (btrfs_is_stripe_alloc_bg(bg) || btrfs_is_stripe_meta_bg(bg)) {
u64 elsewhere = READ_ONCE(space_info->bytes_stripe_claimable);
u64 need = READ_ONCE(bg->used);
bg->stripe_reclaim_forced = STRIPE_RECLAIM_NONE;
if (bg->ro ||
((bg->reserved || bg->pinned) &&
- !btrfs_is_stripe_alloc_bg(bg))) {
+ !btrfs_is_stripe_alloc_bg(bg) &&
+ !btrfs_is_stripe_meta_bg(bg))) {
/*
* We want to bail if we made new allocations or have
* outstanding allocations in this block group. We do
* the ro check in case balance is currently acting on
* this block group.
*
- * Not for a stripe_alloc group: under
+ * Not for a stripe_alloc or stripe_meta group: under
* COW churn it always has blocks reserved or pinned,
* so the bail-out would defer it forever, while the
* trapped free space it was queued for only grows.
compact = (forced == STRIPE_RECLAIM_COMPACT);
} else if (!should_reclaim_block_group(bg, bg->length)) {
/*
- * Too full to relocate whole. A stripe_alloc
+ * Too full to relocate whole. A stripe_alloc / stripe_meta
* group whose free space is trapped in partially used stripes
* can still be compacted: only the extents in those stripes
* move.
}
/*
- * Periodic re-evaluation of stripe_alloc groups from the
+ * Periodic re-evaluation of stripe_alloc / stripe_meta groups from the
* cleaner. The commit-time rescan only sees groups whose free space changed
* in that transaction, and only when there is a transaction: a mark that
* did not land (the group was on another list) or a group the worker dropped
list_for_each_entry(sinfo, &fs_info->space_info, list) {
int raid;
- if (!(sinfo->flags & BTRFS_BLOCK_GROUP_DATA))
+ if (!(sinfo->flags & (BTRFS_BLOCK_GROUP_DATA |
+ BTRFS_BLOCK_GROUP_METADATA)))
continue;
if (READ_ONCE(sinfo->bg_reclaim_threshold) <= 0)
continue;
}
/*
- * /sys/fs/btrfs/<uuid>/stripe_reclaim_now: reclaim stripe_alloc
+ * /sys/fs/btrfs/<uuid>/stripe_reclaim_now: reclaim stripe_alloc / stripe_meta
* raid56 block groups now, e.g. from an idle-time job, rather than waiting
* for the commit-time rescan and its five-minute hysteresis. The threshold
* is the space_info's bg_reclaim_threshold, or BTRFS_DEFAULT_RECLAIM_THRESH
* Otherwise @start names one group (its logical start): it is reclaimed
* whatever the trapped minimums say, compacted if it is above the threshold
* and has trapped stripes, relocated otherwise. -ENOENT: no group starts
- * there; -EINVAL: not a stripe_alloc raid56 group (relocate
+ * there; -EINVAL: not a stripe_alloc / stripe_meta raid56 group (relocate
* any other group with balance's vrange filter); -EBUSY: the group is
* read-only (balance or scrub hold it); -EAGAIN: it is already on a list
* (queued, unused or new); -ENOSPC: the other groups' claimable stripes plus
return -ENOENT;
if (bg->start != start) {
ret = -ENOENT;
- } else if (!btrfs_is_stripe_alloc_bg(bg)) {
+ } else if (!btrfs_is_stripe_alloc_bg(bg) &&
+ !btrfs_is_stripe_meta_bg(bg)) {
ret = -EINVAL;
} else if (READ_ONCE(bg->ro)) {
ret = -EBUSY;
BTRFS_BLOCK_GROUP_RAID56_MASK))
continue;
list_for_each_entry(bg, &sinfo->block_groups[raid], list) {
- if (!btrfs_is_stripe_alloc_bg(bg))
+ if (!btrfs_is_stripe_alloc_bg(bg) &&
+ !btrfs_is_stripe_meta_bg(bg))
continue;
kind = btrfs_stripe_bg_reclaim_now_kind(bg, thresh,
false, stripe_reclaim_chunk_room(bg));
};
/*
- * Stripe compaction. A stripe_alloc group whose free space is
+ * Stripe compaction. A stripe_alloc / stripe_meta group whose free space is
* trapped in partially used stripes, but whose live data mostly fills whole
* ones, does not need all of that data moved to get the space back: only the
* extents in the partial stripes, and -- since moving an extent frees its
* bytes in every stripe it spans -- the extents sharing a stripe with those,
* transitively. compact_plan() selects that closure, find_next_extent()
* skips every extent outside it, and the group is kept and made writable
- * again instead of removed.
+ * again instead of removed. A tree block never spans a stripe, so for a
+ * metadata group the closure is the partial stripes themselves.
*/
static bool compact_selected(const struct reloc_control *rc, u64 start, u64 len)
{
static int compact_plan(struct reloc_control *rc, u64 *moved, u64 *nsel)
{
struct btrfs_block_group *bg = rc->block_group;
+ struct btrfs_fs_info *fs_info = bg->fs_info;
const u64 fsl = bg->full_stripe_len;
const u64 end = bg->start + bg->length;
BTRFS_PATH_AUTO_FREE(path);
break;
if (key.type == BTRFS_EXTENT_ITEM_KEY)
len = key.offset;
+ else if (key.type == BTRFS_METADATA_ITEM_KEY)
+ len = fs_info->nodesize;
else
continue;
if (key.objectid < bg->start || !len)