diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-06 21:42:36 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-04-05 23:43:22 -0400 |
commit | 5f40acfc743d377f8008c4cc69405a96e728880e (patch) | |
tree | cdb279288aa5176e85672e54d9949270de4466ac | |
parent | 7fb5373d1371a189213d6a2f69a028a14ebf89a1 (diff) |
bcachefs: bch_acct_compression
This adds per-compression-type accounting of compressed and uncompressed
size as well as number of extents - meaning we can now see compression
ratio (without walking the whole filesystem).
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/buckets.c | 57 | ||||
-rw-r--r-- | fs/bcachefs/disk_accounting.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/disk_accounting_format.h | 8 |
3 files changed, 58 insertions, 11 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index c3328d038a33..b0d88c40b373 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -506,13 +506,18 @@ static int __trigger_extent(struct btree_trans *trans, s64 dirty_sectors = 0; int ret = 0; - struct disk_accounting_pos acc = { + struct disk_accounting_pos acc_replicas_key = { .type = BCH_DISK_ACCOUNTING_replicas, .replicas.data_type = data_type, .replicas.nr_devs = 0, .replicas.nr_required = 1, }; + struct disk_accounting_pos acct_compression_key = { + .type = BCH_DISK_ACCOUNTING_compression, + }; + u64 compression_acct[3] = { 1, 0, 0 }; + bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { s64 disk_sectors; ret = bch2_trigger_pointer(trans, btree_id, level, k, p, entry, &disk_sectors, flags); @@ -521,15 +526,16 @@ static int __trigger_extent(struct btree_trans *trans, bool stale = ret > 0; + if (p.ptr.cached && stale) + continue; + if (p.ptr.cached) { - if (!stale) { - ret = bch2_mod_dev_cached_sectors(trans, p.ptr.dev, disk_sectors, gc); - if (ret) - return ret; - } + ret = bch2_mod_dev_cached_sectors(trans, p.ptr.dev, disk_sectors, gc); + if (ret) + return ret; } else if (!p.has_ec) { dirty_sectors += disk_sectors; - acc.replicas.devs[acc.replicas.nr_devs++] = p.ptr.dev; + acc_replicas_key.replicas.devs[acc_replicas_key.replicas.nr_devs++] = p.ptr.dev; } else { ret = bch2_trigger_stripe_ptr(trans, k, p, data_type, disk_sectors, flags); if (ret) @@ -540,12 +546,43 @@ static int __trigger_extent(struct btree_trans *trans, * if so they're not required for mounting if we have an * erasure coded pointer in this extent: */ - acc.replicas.nr_required = 0; + acc_replicas_key.replicas.nr_required = 0; + } + + if (acct_compression_key.compression.type && + acct_compression_key.compression.type != p.crc.compression_type) { + if (flags & BTREE_TRIGGER_OVERWRITE) + bch2_u64s_neg(compression_acct, ARRAY_SIZE(compression_acct)); + + ret = bch2_disk_accounting_mod(trans, &acct_compression_key, compression_acct, + ARRAY_SIZE(compression_acct), gc); + if (ret) + return ret; + + compression_acct[0] = 1; + compression_acct[1] = 0; + compression_acct[2] = 0; + } + + acct_compression_key.compression.type = p.crc.compression_type; + if (p.crc.compression_type) { + compression_acct[1] += p.crc.uncompressed_size; + compression_acct[2] += p.crc.compressed_size; } } - if (acc.replicas.nr_devs) { - ret = bch2_disk_accounting_mod(trans, &acc, &dirty_sectors, 1, gc); + if (acc_replicas_key.replicas.nr_devs) { + ret = bch2_disk_accounting_mod(trans, &acc_replicas_key, &dirty_sectors, 1, gc); + if (ret) + return ret; + } + + if (acct_compression_key.compression.type) { + if (flags & BTREE_TRIGGER_OVERWRITE) + bch2_u64s_neg(compression_acct, ARRAY_SIZE(compression_acct)); + + ret = bch2_disk_accounting_mod(trans, &acct_compression_key, compression_acct, + ARRAY_SIZE(compression_acct), gc); if (ret) return ret; } diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index ff51fe46fc77..3d469114c25d 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -5,6 +5,7 @@ #include "btree_update.h" #include "btree_write_buffer.h" #include "buckets.h" +#include "compress.h" #include "disk_accounting.h" #include "error.h" #include "journal_io.h" @@ -139,6 +140,9 @@ void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_po case BCH_DISK_ACCOUNTING_dev_stripe_buckets: prt_printf(out, "dev=%u", k->dev_stripe_buckets.dev); break; + case BCH_DISK_ACCOUNTING_compression: + bch2_prt_compression_type(out, k->compression.type); + break; } } diff --git a/fs/bcachefs/disk_accounting_format.h b/fs/bcachefs/disk_accounting_format.h index 10e899eb7394..3feee34ceb9d 100644 --- a/fs/bcachefs/disk_accounting_format.h +++ b/fs/bcachefs/disk_accounting_format.h @@ -99,7 +99,8 @@ static inline bool data_type_is_hidden(enum bch_data_type type) x(persistent_reserved, 1) \ x(replicas, 2) \ x(dev_data_type, 3) \ - x(dev_stripe_buckets, 4) + x(dev_stripe_buckets, 4) \ + x(compression, 5) enum disk_accounting_type { #define x(f, nr) BCH_DISK_ACCOUNTING_##f = nr, @@ -124,6 +125,10 @@ struct bch_dev_stripe_buckets { __u8 dev; }; +struct bch_acct_compression { + __u8 type; +}; + struct disk_accounting_pos { union { struct { @@ -134,6 +139,7 @@ struct disk_accounting_pos { struct bch_replicas_entry_v1 replicas; struct bch_dev_data_type dev_data_type; struct bch_dev_stripe_buckets dev_stripe_buckets; + struct bch_acct_compression compression; }; }; struct bpos _pad; |