int raid;
if (!(sinfo->flags & (BTRFS_BLOCK_GROUP_DATA |
- BTRFS_BLOCK_GROUP_METADATA)))
+ BTRFS_BLOCK_GROUP_METADATA |
+ BTRFS_BLOCK_GROUP_SYSTEM)))
continue;
/*
* Metadata: the scan that maintains the stripe_meta margin
}
}
-/*
- * stripe_alloc covers raid56 *data* block groups only. A filesystem whose
- * metadata is also raid56 keeps the write hole there. The data guarantee is
- * easy to read as a filesystem-wide one, so say once, when the policy turns
- * on, what is not covered. That is btrfs_enable_stripe_alloc(): at mount the
- * property applies after the block groups are read, so a report from
- * btrfs_read_block_groups() would find the flag still clear. (Mixed block
- * groups cannot get here: the property refuses them.)
- */
-static void warn_stripe_alloc_uncovered(struct btrfs_fs_info *info)
-{
- if (!btrfs_test_opt(info, STRIPE_ALLOC))
- return;
-
- /*
- * raid56 metadata is covered now that the policy follows the chunk
- * profile. System chunks are not: btrfs_is_stripe_meta_bg() tests
- * the METADATA flag, and a system chunk does not carry it, so a
- * raid56 system chunk keeps the legacy read-modify-write and its
- * write hole. They are small and rewritten rarely, but say so
- * rather than let the earlier "covered" message imply otherwise.
- */
- if (info->avail_system_alloc_bits & BTRFS_BLOCK_GROUP_RAID56_MASK)
- btrfs_warn(info,
-"stripe_alloc does not cover raid56 system chunks: the write hole remains for them, consider converting to raid1c3/raid1c4");
-}
-
/*
* Drain the writes the legacy allocator placed before stripe_alloc was
* enabled on a live filesystem, then arm the write-hole invariant check.
if (live)
set_bit(BTRFS_FS_STRIPE_ALLOC_ENABLING, &fs_info->flags);
btrfs_set_opt(fs_info->mount_opt, STRIPE_ALLOC);
- warn_stripe_alloc_uncovered(fs_info);
/*
* Arm stripe_unusable accounting for raid56 data groups whose caches
* loaded before the policy was enabled: block groups are read before
bg = list_first_entry(&retire_list, struct btrfs_block_group,
open_stripe_retire_list);
list_del_init(&bg->open_stripe_retire_list);
- if (!(bg->flags & BTRFS_BLOCK_GROUP_METADATA))
+ if (!(bg->flags & (BTRFS_BLOCK_GROUP_METADATA |
+ BTRFS_BLOCK_GROUP_SYSTEM)))
continue;
while (again) {
* both carry trapped free space. Mixed groups are refused.
*/
if (!(sinfo->flags & (BTRFS_BLOCK_GROUP_DATA |
- BTRFS_BLOCK_GROUP_METADATA)))
+ BTRFS_BLOCK_GROUP_METADATA |
+ BTRFS_BLOCK_GROUP_SYSTEM)))
continue;
down_read(&sinfo->groups_sem);
for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) {
int raid;
if (!(sinfo->flags & (BTRFS_BLOCK_GROUP_DATA |
- BTRFS_BLOCK_GROUP_METADATA)))
+ BTRFS_BLOCK_GROUP_METADATA |
+ BTRFS_BLOCK_GROUP_SYSTEM)))
continue;
if (READ_ONCE(sinfo->bg_reclaim_threshold) <= 0)
continue;
{
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_space_info *info;
+ u64 headroom = 0;
u64 left;
int ret = 0;
left = info->total_bytes - btrfs_space_info_used(info, true);
spin_unlock(&info->lock);
- if (left < bytes && btrfs_test_opt(fs_info, ENOSPC_DEBUG)) {
- btrfs_info(fs_info, "left=%llu, need=%llu, flags=%llu",
- left, bytes, type);
+ /*
+ * Under stripe_alloc a raid56 system chunk places its tree blocks by
+ * whole stripes (btrfs_is_stripe_meta_bg()), and the bytes trapped in
+ * partial stripes and the open run's remainder are already counted
+ * as used above. What is left is whole free stripes, but the request
+ * is sized in tree blocks: a chunk tree COW that needs a fresh run
+ * takes a whole stripe for its first block, so demand one stripe of
+ * headroom beyond the request, or the chunk item for the very system
+ * chunk this would allocate finds no stripe to land in. The headroom
+ * decides when to allocate; it is not reserved.
+ */
+ if (btrfs_test_opt(fs_info, STRIPE_ALLOC)) {
+ int raid;
+
+ down_read(&info->groups_sem);
+ for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) {
+ struct btrfs_block_group *bg;
+
+ if (!(btrfs_raid_array[raid].bg_flag &
+ BTRFS_BLOCK_GROUP_RAID56_MASK))
+ continue;
+ list_for_each_entry(bg, &info->block_groups[raid], list)
+ headroom = max_t(u64, headroom,
+ bg->full_stripe_len);
+ }
+ up_read(&info->groups_sem);
+ }
+
+ if (left < bytes + headroom && btrfs_test_opt(fs_info, ENOSPC_DEBUG)) {
+ btrfs_info(fs_info, "left=%llu, need=%llu, headroom=%llu, flags=%llu",
+ left, bytes, headroom, type);
btrfs_dump_space_info(info, 0, false);
}
- if (left < bytes) {
+ if (left < bytes + headroom) {
u64 flags = btrfs_system_alloc_profile(fs_info);
struct btrfs_block_group *bg;
struct btrfs_space_info *space_info;
/*
* Should this block group allocate tree blocks by whole stripes?
*
- * The same rule data follows: only fully free stripes are claimed, and the
- * partial stripe left at the end of a commit is padded out rather than
- * revisited, so no tree block write ever lands in a stripe holding earlier
- * committed data. Not separately gated: the chunk profile already decides
- * it. raid56 metadata has the same write hole as raid56 data and gets the
- * same protection at the same time; metadata on any other profile has no
- * write hole to close, and the RAID56_MASK test below means the policy
- * simply does not apply to it. The costs metadata brings -- a stranded
- * stripe tail per commit, and an allocation failure that aborts the
- * transaction rather than failing one write -- are the price of covering
- * raid56 metadata at all, and a filesystem that does not want them wants
- * raid1c3/raid1c4 metadata instead, which is the better answer anyway.
+ * The same rule as data: only fully free stripes are claimed, and the
+ * partial stripe left at the end of a commit is padded rather than
+ * revisited, so no tree block lands in a stripe holding committed blocks.
+ * It applies to every raid56 metadata and system group while stripe_alloc
+ * is on. The costs are a stranded stripe tail per commit, and an
+ * allocation failure aborts the transaction instead of failing one write.
+ * System chunks carry no METADATA bit but hold the chunk tree, so they are
+ * named explicitly.
*/
bool btrfs_is_stripe_meta_bg(const struct btrfs_block_group *bg)
{
return btrfs_test_opt(bg->fs_info, STRIPE_ALLOC) &&
- (bg->flags & BTRFS_BLOCK_GROUP_METADATA) &&
+ (bg->flags & (BTRFS_BLOCK_GROUP_METADATA |
+ BTRFS_BLOCK_GROUP_SYSTEM)) &&
!(bg->flags & BTRFS_BLOCK_GROUP_DATA) &&
(bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
!test_bit(BLOCK_GROUP_FLAG_RAID56_MIRRORED, &bg->runtime_flags);