* The pessimistic reservation margin should make a data
* writeback allocation failure impossible: admission held
* back a full stripe per delalloc extent. If it happens
- * anyway the pages are dropped, so say so loudly.
+ * anyway the pages are dropped, so say so loudly, with the
+ * counters admission decided on (and, on debug builds, every
+ * group's view of its stripes): a drop seen once with nothing
+ * else logged cannot be explained afterwards.
*/
- if (is_data && delalloc && btrfs_test_opt(fs_info, STRIPE_ALLOC))
- btrfs_warn_rl(fs_info,
- "stripe_alloc: data writeback allocation of %llu bytes returned ENOSPC despite reservation margin; buffered data in this range will be dropped",
- num_bytes);
+ if (is_data && delalloc && btrfs_test_opt(fs_info, STRIPE_ALLOC)) {
+ static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
+ DEFAULT_RATELIMIT_BURST);
+ struct btrfs_space_info *sinfo;
+
+ sinfo = btrfs_find_space_info(fs_info, flags);
+ if (sinfo && __ratelimit(&rs)) {
+ btrfs_warn(fs_info,
+ "stripe_alloc: data writeback allocation of %llu bytes returned ENOSPC despite reservation margin; buffered data in this range will be dropped: claimable %llu claimable_reloc %llu open %llu trapped %llu stranded %llu may_use %llu margin %llu unmanaged_free %lld reserved %llu total %llu unit %llu",
+ num_bytes,
+ sinfo->bytes_stripe_claimable,
+ sinfo->bytes_stripe_claimable_reloc,
+ sinfo->bytes_stripe_open,
+ sinfo->bytes_stripe_unusable,
+ sinfo->bytes_stripe_stranded,
+ sinfo->bytes_may_use,
+ sinfo->bytes_stripe_margin,
+ (s64)atomic64_read(&sinfo->bytes_unmanaged_free),
+ sinfo->bytes_reserved,
+ sinfo->total_bytes,
+ READ_ONCE(fs_info->stripe_margin_unit));
+ if (IS_ENABLED(CONFIG_BTRFS_DEBUG))
+ btrfs_dump_stripe_groups(sinfo);
+ }
+ }
}
return ret;
btrfs_info(fs_info, "%llu bytes available across all block groups", total_avail);
}
+/*
+ * One line per block group of what stripe_alloc's allocator sees: the
+ * stripe width, the whole-stripe supply and the largest run a claim may
+ * find, the open remainder and the trapped and stranded bytes. Cheap
+ * enough for a failed writeback allocation, unlike btrfs_dump_space_info()
+ * with its free space entries.
+ */
+void btrfs_dump_stripe_groups(struct btrfs_space_info *info)
+{
+ struct btrfs_fs_info *fs_info = info->fs_info;
+ const u64 reloc_bg = READ_ONCE(fs_info->data_reloc_bg);
+ struct btrfs_block_group *cache;
+ int index;
+
+ down_read(&info->groups_sem);
+ for (index = 0; index < BTRFS_NR_RAID_TYPES; index++) {
+ list_for_each_entry(cache, &info->block_groups[index], list) {
+ spin_lock(&cache->lock);
+ btrfs_info(fs_info,
+"stripe group %llu len %llu fsl %lu used %llu reserved %llu pinned %llu claimable %llu max_run %lld open_rem %llu trapped %llu stranded %llu cached %d%s%s%s",
+ cache->start, cache->length,
+ cache->full_stripe_len, cache->used,
+ cache->reserved, cache->pinned,
+ READ_ONCE(cache->stripe_claimable),
+ (s64)READ_ONCE(cache->max_claimable_run),
+ READ_ONCE(cache->stripe_open_remainder),
+ READ_ONCE(cache->stripe_unusable_ready) ?
+ READ_ONCE(cache->stripe_unusable) : 0,
+ READ_ONCE(cache->stripe_stranded),
+ cache->cached,
+ cache->ro ? " ro" : "",
+ cache->start == reloc_bg ? " reloc" : "",
+ btrfs_is_stripe_alloc_bg(cache) ? "" : " unmanaged");
+ spin_unlock(&cache->lock);
+ }
+ }
+ up_read(&info->groups_sem);
+}
+
static inline u64 calc_reclaim_items_nr(const struct btrfs_fs_info *fs_info,
u64 to_reclaim)
{
void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
void btrfs_dump_space_info(struct btrfs_space_info *info, u64 bytes,
bool dump_block_groups);
+void btrfs_dump_stripe_groups(struct btrfs_space_info *info);
int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
u64 orig_bytes,
enum btrfs_reserve_flush_enum flush);