Commit 58474f76 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: bcachefs_metadata_version_disk_accounting_inum



This adds another disk accounting counter to track usage per inode
number (any snapshot ID).

This will be used for a couple things:

- It'll give us a way to tell the user how much space a given file ista
  consuming in all snapshots; i.e. how much extra space it's consuming
  due to snapshot versioning.

- It counts number of extents and total size of extents (both in btree
  keyspace sectors and actual disk usage), meaning it gives us average
  extent size: that is, it'll let us cheaply find fragmented files that
  should be defragmented.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5132b99b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -676,7 +676,8 @@ struct bch_sb_field_ext {
	x(mi_btree_bitmap,		BCH_VERSION(1,  7))		\
	x(bucket_stripe_sectors,	BCH_VERSION(1,  8))		\
	x(disk_accounting_v2,		BCH_VERSION(1,  9))		\
	x(disk_accounting_v3,		BCH_VERSION(1, 10))
	x(disk_accounting_v3,		BCH_VERSION(1, 10))		\
	x(disk_accounting_inum,		BCH_VERSION(1, 11))

enum bcachefs_metadata_version {
	bcachefs_metadata_version_min = 9,
+14 −0
Original line number Diff line number Diff line
@@ -810,6 +810,20 @@ static int __trigger_extent(struct btree_trans *trans,
		ret = bch2_disk_accounting_mod(trans, &acc_btree_key, &replicas_sectors, 1, gc);
		if (ret)
			return ret;
	} else {
		bool insert = !(flags & BTREE_TRIGGER_overwrite);
		struct disk_accounting_pos acc_inum_key = {
			.type		= BCH_DISK_ACCOUNTING_inum,
			.inum.inum	= k.k->p.inode,
		};
		s64 v[3] = {
			insert ? 1 : -1,
			insert ? k.k->size : -((s64) k.k->size),
			replicas_sectors,
		};
		ret = bch2_disk_accounting_mod(trans, &acc_inum_key, v, ARRAY_SIZE(v), gc);
		if (ret)
			return ret;
	}

	if (bch2_bkey_rebalance_opts(k)) {
+3 −0
Original line number Diff line number Diff line
@@ -768,6 +768,9 @@ void bch2_verify_accounting_clean(struct bch_fs *c)
			if (acc_k.type >= BCH_DISK_ACCOUNTING_TYPE_NR)
				continue;

			if (acc_k.type == BCH_DISK_ACCOUNTING_inum)
				continue;

			bch2_accounting_mem_read(c, k.k->p, v, nr);

			if (memcmp(a.v->d, v, nr * sizeof(u64))) {
+3 −0
Original line number Diff line number Diff line
@@ -116,6 +116,9 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, stru
	struct disk_accounting_pos acc_k;
	bpos_to_disk_accounting_pos(&acc_k, a.k->p);

	if (acc_k.type == BCH_DISK_ACCOUNTING_inum)
		return 0;

	if (!gc && !read) {
		switch (acc_k.type) {
		case BCH_DISK_ACCOUNTING_persistent_reserved:
+7 −1
Original line number Diff line number Diff line
@@ -103,7 +103,8 @@ static inline bool data_type_is_hidden(enum bch_data_type type)
	x(compression,		4)		\
	x(snapshot,		5)		\
	x(btree,		6)		\
	x(rebalance_work,	7)
	x(rebalance_work,	7)		\
	x(inum,			8)

enum disk_accounting_type {
#define x(f, nr)	BCH_DISK_ACCOUNTING_##f	= nr,
@@ -136,6 +137,10 @@ struct bch_acct_btree {
	__u32			id;
} __packed;

struct bch_acct_inum {
	__u64			inum;
} __packed;

struct bch_acct_rebalance_work {
};

@@ -152,6 +157,7 @@ struct disk_accounting_pos {
		struct bch_acct_snapshot	snapshot;
		struct bch_acct_btree		btree;
		struct bch_acct_rebalance_work	rebalance_work;
		struct bch_acct_inum		inum;
		} __packed;
	} __packed;
		struct bpos			_pad;
Loading