diff options
| author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-06 21:42:36 -0500 |
|---|---|---|
| committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-07-14 19:00:13 -0400 |
| commit | bfcaa9079d91cb843630403e7379bbb86d2f73b0 (patch) | |
| tree | 8f919a7fdff7878c389a744d4eb602315b2ebf39 /fs/bcachefs/buckets.c | |
| parent | 5668e5deec253dc4674aea00997716cc3a66aaac (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>
Diffstat (limited to 'fs/bcachefs/buckets.c')
| -rw-r--r-- | fs/bcachefs/buckets.c | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index e3bf7ed5c073..06e968d98018 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -707,13 +707,18 @@ static int __trigger_extent(struct btree_trans *trans, s64 replicas_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 = 0; ret = bch2_trigger_pointer(trans, btree_id, level, k, p, entry, &disk_sectors, flags); @@ -722,15 +727,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) { replicas_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) @@ -741,12 +747,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_key.replicas.nr_devs) { + ret = bch2_disk_accounting_mod(trans, &acc_replicas_key, &replicas_sectors, 1, gc); + if (ret) + return ret; } - if (acc.replicas.nr_devs) { - ret = bch2_disk_accounting_mod(trans, &acc, &replicas_sectors, 1, gc); + 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; } |
