Skip to content

Commit 6af9114

Browse files
author
Kent Overstreet
committed
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>
1 parent 6675c37 commit 6af9114

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

fs/bcachefs/buckets.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,16 @@ static int __trigger_extent(struct btree_trans *trans,
798798
return ret;
799799
}
800800

801+
if (level) {
802+
struct disk_accounting_pos acc_btree_key = {
803+
.type = BCH_DISK_ACCOUNTING_btree,
804+
.btree.id = btree_id,
805+
};
806+
ret = bch2_disk_accounting_mod(trans, &acc_btree_key, &replicas_sectors, 1, gc);
807+
if (ret)
808+
return ret;
809+
}
810+
801811
return 0;
802812
}
803813

fs/bcachefs/disk_accounting.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "bcachefs.h"
44
#include "bcachefs_ioctl.h"
5+
#include "btree_cache.h"
56
#include "btree_journal_iter.h"
67
#include "btree_update.h"
78
#include "btree_write_buffer.h"
@@ -149,6 +150,9 @@ void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_po
149150
case BCH_DISK_ACCOUNTING_snapshot:
150151
prt_printf(out, "id=%u", k->snapshot.id);
151152
break;
153+
case BCH_DISK_ACCOUNTING_btree:
154+
prt_printf(out, "btree=%s", bch2_btree_id_str(k->btree.id));
155+
break;
152156
}
153157
}
154158

fs/bcachefs/disk_accounting_format.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ static inline bool data_type_is_hidden(enum bch_data_type type)
101101
x(replicas, 2) \
102102
x(dev_data_type, 3) \
103103
x(compression, 4) \
104-
x(snapshot, 5)
104+
x(snapshot, 5) \
105+
x(btree, 6)
105106

106107
enum disk_accounting_type {
107108
#define x(f, nr) BCH_DISK_ACCOUNTING_##f = nr,
@@ -134,6 +135,10 @@ struct bch_acct_snapshot {
134135
__u32 id;
135136
};
136137

138+
struct bch_acct_btree {
139+
__u32 id;
140+
};
141+
137142
struct disk_accounting_pos {
138143
union {
139144
struct {
@@ -146,6 +151,7 @@ struct disk_accounting_pos {
146151
struct bch_dev_stripe_buckets dev_stripe_buckets;
147152
struct bch_acct_compression compression;
148153
struct bch_acct_snapshot snapshot;
154+
struct bch_acct_btree btree;
149155
};
150156
};
151157
struct bpos _pad;

0 commit comments

Comments
 (0)