summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-02-28 22:37:21 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-04-05 23:43:22 -0400
commitb25c15214ea7c5d3add870119d3c5ff943bee5ae (patch)
tree5e04927097a05fd210990e21a79582b94bd4d862
parentd46939d673482171e2f34ca213fa0d7e30a24112 (diff)
bcachefs: bch_acct_btree
Add counters for how much disk space we're using per btree. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/buckets.c10
-rw-r--r--fs/bcachefs/disk_accounting.c4
-rw-r--r--fs/bcachefs/disk_accounting_format.h8
3 files changed, 21 insertions, 1 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index 2ccf5297ef49..e09ff5bbcd54 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -597,6 +597,16 @@ static int __trigger_extent(struct btree_trans *trans,
return ret;
}
+ if (level) {
+ struct disk_accounting_pos acc_btree_key = {
+ .type = BCH_DISK_ACCOUNTING_btree,
+ .btree.id = btree_id,
+ };
+ ret = bch2_disk_accounting_mod(trans, &acc_btree_key, &dirty_sectors, 1, gc);
+ if (ret)
+ return ret;
+ }
+
return 0;
}
diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c
index 289008fda441..1e549862133f 100644
--- a/fs/bcachefs/disk_accounting.c
+++ b/fs/bcachefs/disk_accounting.c
@@ -2,6 +2,7 @@
#include "bcachefs.h"
#include "bcachefs_ioctl.h"
+#include "btree_cache.h"
#include "btree_update.h"
#include "btree_write_buffer.h"
#include "buckets.h"
@@ -146,6 +147,9 @@ void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_po
case BCH_DISK_ACCOUNTING_snapshot:
prt_printf(out, "id=%u", k->snapshot.id);
break;
+ case BCH_DISK_ACCOUNTING_btree:
+ prt_printf(out, "btree=%s", bch2_btree_id_str(k->btree.id));
+ break;
}
}
diff --git a/fs/bcachefs/disk_accounting_format.h b/fs/bcachefs/disk_accounting_format.h
index 090108a4e0a5..f95f6ab07aaa 100644
--- a/fs/bcachefs/disk_accounting_format.h
+++ b/fs/bcachefs/disk_accounting_format.h
@@ -101,7 +101,8 @@ static inline bool data_type_is_hidden(enum bch_data_type type)
x(dev_data_type, 3) \
x(dev_stripe_buckets, 4) \
x(compression, 5) \
- x(snapshot, 6)
+ x(snapshot, 6) \
+ x(btree, 7)
enum disk_accounting_type {
#define x(f, nr) BCH_DISK_ACCOUNTING_##f = nr,
@@ -134,6 +135,10 @@ struct bch_acct_snapshot {
__u32 id;
};
+struct bch_acct_btree {
+ __u32 id;
+};
+
struct disk_accounting_pos {
union {
struct {
@@ -146,6 +151,7 @@ struct disk_accounting_pos {
struct bch_dev_stripe_buckets dev_stripe_buckets;
struct bch_acct_compression compression;
struct bch_acct_snapshot snapshot;
+ struct bch_acct_btree btree;
};
};
struct bpos _pad;