Commit 862bfd50 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Update sysfs compression_stats for snapshots

 - BTREE_ITER_ALL_SNAPSHOTS flag is required here
 - change it to also walk the reflink btree
 - change it to accumulate stats for all pointers in an extent
 - change it to account for incompressible data
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 13f914ec
...@@ -266,8 +266,12 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c ...@@ -266,8 +266,12 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c
struct btree_trans trans; struct btree_trans trans;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
u64 nr_uncompressed_extents = 0, uncompressed_sectors = 0, enum btree_id id;
u64 nr_uncompressed_extents = 0,
nr_compressed_extents = 0, nr_compressed_extents = 0,
nr_incompressible_extents = 0,
uncompressed_sectors = 0,
incompressible_sectors = 0,
compressed_sectors_compressed = 0, compressed_sectors_compressed = 0,
compressed_sectors_uncompressed = 0; compressed_sectors_uncompressed = 0;
int ret; int ret;
...@@ -277,47 +281,72 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c ...@@ -277,47 +281,72 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_extents, POS_MIN, 0, k, ret) for (id = 0; id < BTREE_ID_NR; id++) {
if (k.k->type == KEY_TYPE_extent) { if (!((1U << id) & BTREE_ID_HAS_PTRS))
struct bkey_s_c_extent e = bkey_s_c_to_extent(k); continue;
for_each_btree_key(&trans, iter, id, POS_MIN,
BTREE_ITER_ALL_SNAPSHOTS, k, ret) {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const union bch_extent_entry *entry; const union bch_extent_entry *entry;
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
bool compressed = false, uncompressed = false, incompressible = false;
extent_for_each_ptr_decode(e, p, entry) { bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
if (!crc_is_compressed(p.crc)) { switch (p.crc.compression_type) {
nr_uncompressed_extents++; case BCH_COMPRESSION_TYPE_none:
uncompressed_sectors += e.k->size; uncompressed = true;
} else { uncompressed_sectors += k.k->size;
nr_compressed_extents++; break;
case BCH_COMPRESSION_TYPE_incompressible:
incompressible = true;
incompressible_sectors += k.k->size;
break;
default:
compressed_sectors_compressed += compressed_sectors_compressed +=
p.crc.compressed_size; p.crc.compressed_size;
compressed_sectors_uncompressed += compressed_sectors_uncompressed +=
p.crc.uncompressed_size; p.crc.uncompressed_size;
} compressed = true;
/* only looking at the first ptr */
break; break;
} }
} }
if (incompressible)
nr_incompressible_extents++;
else if (uncompressed)
nr_uncompressed_extents++;
else if (compressed)
nr_compressed_extents++;
}
bch2_trans_iter_exit(&trans, &iter); bch2_trans_iter_exit(&trans, &iter);
}
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) if (ret)
return ret; return ret;
pr_buf(out, pr_buf(out, "uncompressed:\n");
"uncompressed data:\n" pr_buf(out, " nr extents: %llu\n", nr_uncompressed_extents);
" nr extents: %llu\n" pr_buf(out, " size: ");
" size (bytes): %llu\n" bch2_hprint(out, uncompressed_sectors << 9);
"compressed data:\n" pr_buf(out, "\n");
" nr extents: %llu\n"
" compressed size (bytes): %llu\n" pr_buf(out, "compressed:\n");
" uncompressed size (bytes): %llu\n", pr_buf(out, " nr extents: %llu\n", nr_compressed_extents);
nr_uncompressed_extents, pr_buf(out, " compressed size: ");
uncompressed_sectors << 9, bch2_hprint(out, compressed_sectors_compressed << 9);
nr_compressed_extents, pr_buf(out, "\n");
compressed_sectors_compressed << 9, pr_buf(out, " uncompressed size: ");
compressed_sectors_uncompressed << 9); bch2_hprint(out, compressed_sectors_uncompressed << 9);
pr_buf(out, "\n");
pr_buf(out, "incompressible:\n");
pr_buf(out, " nr extents: %llu\n", nr_incompressible_extents);
pr_buf(out, " size: ");
bch2_hprint(out, incompressible_sectors << 9);
pr_buf(out, "\n");
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment