return false;
}
-bool btrfs_stripe_run_incomplete(struct btrfs_fs_info *fs_info,
- u64 stripe_start, u64 stripe_len)
+/*
+ * As btrfs_stripe_run_incomplete(), returning the class of the run that
+ * leaves the stripe incomplete, or -1 if none does.
+ */
+int btrfs_stripe_run_incomplete_class(struct btrfs_fs_info *fs_info,
+ u64 stripe_start, u64 stripe_len)
{
struct btrfs_block_group *bg;
struct btrfs_open_stripe_run *run;
unsigned long flags;
- bool ret = false;
+ int ret = -1;
if (list_empty_careful(&fs_info->open_stripe_bgs))
- return false;
+ return -1;
bg = btrfs_lookup_block_group(fs_info, stripe_start);
if (!bg)
- return false;
+ return -1;
spin_lock_irqsave(&bg->stripe_run_lock, flags);
list_for_each_entry(run, &bg->open_stripe_runs, list) {
- if (run->open && run->offset > stripe_start &&
- run->offset < stripe_start + stripe_len) {
- ret = true;
- break;
- }
- if (run_unwritten_in(run, stripe_start, stripe_len)) {
- ret = true;
+ if ((run->open && run->offset > stripe_start &&
+ run->offset < stripe_start + stripe_len) ||
+ run_unwritten_in(run, stripe_start, stripe_len)) {
+ ret = run->class;
break;
}
}
return ret;
}
+/*
+ * Is [stripe_start, stripe_start + stripe_len) still waiting for writes from
+ * a stripe run? Two ways:
+ *
+ * - an open run's allocation frontier lies strictly inside it: the run will
+ * allocate and write the rest of the stripe later, although every sector
+ * allocated so far may already be written;
+ * - a run covering it has sectors allocated (live) but not yet written: the
+ * frontier has moved past, and the writes are still in flight (writeback
+ * allocates a whole range before any of its bios complete).
+ *
+ * Either way the stripe has been written in part, and the rest will arrive
+ * as a sub-stripe write that needs the part already written.
+ */
+bool btrfs_stripe_run_incomplete(struct btrfs_fs_info *fs_info,
+ u64 stripe_start, u64 stripe_len)
+{
+ return btrfs_stripe_run_incomplete_class(fs_info, stripe_start,
+ stripe_len) >= 0;
+}
+
+/* Open stripe runs by class, for sysfs: @counts has NR_CLASSES entries. */
+void btrfs_count_open_stripe_runs(struct btrfs_fs_info *fs_info, int *counts)
+{
+ struct btrfs_block_group *bg;
+ struct btrfs_open_stripe_run *run;
+ unsigned long flags;
+
+ memset(counts, 0, sizeof(*counts) * BTRFS_STRIPE_RUN_NR_CLASSES);
+ spin_lock(&fs_info->open_stripe_lock);
+ list_for_each_entry(bg, &fs_info->open_stripe_bgs, open_stripe_bg_list) {
+ spin_lock_irqsave(&bg->stripe_run_lock, flags);
+ list_for_each_entry(run, &bg->open_stripe_runs, list)
+ if (run->open && run->class < BTRFS_STRIPE_RUN_NR_CLASSES)
+ counts[run->class]++;
+ spin_unlock_irqrestore(&bg->stripe_run_lock, flags);
+ }
+ spin_unlock(&fs_info->open_stripe_lock);
+}
+
+/*
+ * Like btrfs_stripe_in_open_run(), also reporting the covering run's
+ * class: the raid56 parking gate treats NOCOW-class runs specially
+ * (sync writes into them never park; see rbio_try_park()).
+ */
bool btrfs_stripe_open_run_class(struct btrfs_fs_info *fs_info, u64 logical,
enum btrfs_stripe_run_class *class)
{
u64 len);
bool btrfs_stripe_run_incomplete(struct btrfs_fs_info *fs_info,
u64 stripe_start, u64 stripe_len);
+int btrfs_stripe_run_incomplete_class(struct btrfs_fs_info *fs_info,
+ u64 stripe_start, u64 stripe_len);
+void btrfs_count_open_stripe_runs(struct btrfs_fs_info *fs_info, int *counts);
bool btrfs_stripe_open_run_class(struct btrfs_fs_info *fs_info, u64 logical,
enum btrfs_stripe_run_class *class);
u64 btrfs_stripe_run_stranded_stripes(struct btrfs_block_group *bg, u32 *freep,
* eviction or a re-cache finds it.
*/
void btrfs_rbio_cache_usage(struct btrfs_fs_info *fs_info, int *cached,
- int *pinned, int *live)
+ int *pinned, int *live, int *live_by_class)
{
struct btrfs_stripe_hash_table *table = fs_info->stripe_hash_table;
struct btrfs_raid_bio *rbio;
+ int class;
*cached = 0;
*pinned = 0;
*live = 0;
+ memset(live_by_class, 0, sizeof(*live_by_class) * BTRFS_STRIPE_RUN_NR_CLASSES);
if (!table)
return;
spin_lock(&table->cache_lock);
*cached = table->cache_size;
*pinned = table->nr_pinned;
- list_for_each_entry(rbio, &table->stripe_cache, stripe_cache)
- if (rbio_pin_live(rbio))
- *live += 1;
+ list_for_each_entry(rbio, &table->stripe_cache, stripe_cache) {
+ if (!test_bit(RBIO_PINNED_BIT, &rbio->flags) ||
+ !btrfs_test_opt(fs_info, STRIPE_ALLOC))
+ continue;
+ class = btrfs_stripe_run_incomplete_class(fs_info,
+ rbio->bioc->full_stripe_logical,
+ (u64)rbio->nr_data * BTRFS_STRIPE_LEN);
+ if (class < 0)
+ continue;
+ *live += 1;
+ if (class < BTRFS_STRIPE_RUN_NR_CLASSES)
+ live_by_class[class] += 1;
+ }
spin_unlock(&table->cache_lock);
}
u64 num_bytes, bool force);
void btrfs_stop_parked_rbios(struct btrfs_fs_info *fs_info);
void btrfs_rbio_cache_usage(struct btrfs_fs_info *fs_info, int *cached,
- int *pinned, int *live);
+ int *pinned, int *live, int *live_by_class);
void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info);
#endif
struct kobj_attribute *a, char *buf)
{
struct btrfs_fs_info *fs_info = to_fs_info(kobj);
- int cached, pinned, live;
-
- btrfs_rbio_cache_usage(fs_info, &cached, &pinned, &live);
- return sysfs_emit(buf,
+ /* Indexed by enum btrfs_stripe_run_class. */
+ static const char * const class_names[] = {
+ "cow", "reloc", "log", "nocow",
+ };
+ int live_by_class[BTRFS_STRIPE_RUN_NR_CLASSES];
+ int open_runs[BTRFS_STRIPE_RUN_NR_CLASSES];
+ int cached, pinned, live, class;
+ ssize_t len;
+
+ BUILD_BUG_ON(ARRAY_SIZE(class_names) != BTRFS_STRIPE_RUN_NR_CLASSES);
+ btrfs_rbio_cache_usage(fs_info, &cached, &pinned, &live, live_by_class);
+ btrfs_count_open_stripe_runs(fs_info, open_runs);
+ len = sysfs_emit(buf,
"parked %lld\n"
"merged_bytes %lld\n"
"filled %lld\n"
atomic64_read(&fs_info->stripe_park_stats.rbio_pin_swept),
atomic64_read(&fs_info->stripe_park_stats.rbio_pin_commit_requests),
atomic64_read(&fs_info->stripe_park_stats.meta_rmw_reads));
+ for (class = 0; class < BTRFS_STRIPE_RUN_NR_CLASSES; class++)
+ len += sysfs_emit_at(buf, len, "rbio_pinned_live_%s %d\n",
+ class_names[class], live_by_class[class]);
+ for (class = 0; class < BTRFS_STRIPE_RUN_NR_CLASSES; class++)
+ len += sysfs_emit_at(buf, len, "open_runs_%s %d\n",
+ class_names[class], open_runs[class]);
+ return len;
}
BTRFS_ATTR(, stripe_park_stats, btrfs_stripe_park_stats_show);