bcachefs: Track nr_inodes with the key marking machinery

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2018-11-29 02:14:31 -05:00 committed by Kent Overstreet
parent 26609b619f
commit f0cfb963ec
8 changed files with 11 additions and 19 deletions

View File

@ -721,9 +721,6 @@ struct bch_fs {
struct mutex fsck_error_lock;
bool fsck_alloc_err;
/* FILESYSTEM */
atomic_long_t nr_inodes;
/* QUOTAS */
struct bch_memquota_type quotas[QTYP_NR];

View File

@ -685,6 +685,7 @@ static void bch2_gc_done(struct bch_fs *c, bool initial)
for (b = 0; b < BCH_DATA_NR; b++)
copy_fs_field(buckets[b],
"buckets[%s]", bch2_data_types[b]);
copy_fs_field(nr_inodes, "nr_inodes");
for_each_possible_cpu(cpu) {
p = per_cpu_ptr(c->usage[0], cpu);

View File

@ -439,6 +439,7 @@ static inline bool btree_node_type_needs_gc(enum btree_node_type type)
switch (type) {
case BKEY_TYPE_BTREE:
case BKEY_TYPE_EXTENTS:
case BKEY_TYPE_INODES:
case BKEY_TYPE_EC:
return true;
default:

View File

@ -862,6 +862,12 @@ static int __bch2_mark_key(struct bch_fs *c, struct bkey_s_c k,
ret = bch2_mark_stripe(c, k, inserting,
stats, journal_seq, flags, gc);
break;
case KEY_TYPE_alloc:
if (inserting)
stats->nr_inodes++;
else
stats->nr_inodes--;
break;
case KEY_TYPE_reservation: {
unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;

View File

@ -73,6 +73,8 @@ struct bch_fs_usage {
u64 buckets[BCH_DATA_NR];
u64 nr_inodes;
/* fields starting here aren't touched by gc: */
u64 online_reserved;
u64 available_cache;

View File

@ -400,8 +400,6 @@ retry:
if (unlikely(ret))
goto err_trans;
atomic_long_inc(&c->nr_inodes);
if (!tmpfile) {
bch2_inode_update_after_write(c, dir, &dir_u,
ATTR_MTIME|ATTR_CTIME);
@ -1418,9 +1416,6 @@ static void bch2_evict_inode(struct inode *vinode)
bch2_quota_acct(c, inode->ei_qid, Q_INO, -1,
KEY_TYPE_QUOTA_WARN);
bch2_inode_rm(c, inode->v.i_ino);
WARN_ONCE(atomic_long_dec_return(&c->nr_inodes) < 0,
"nr_inodes < 0");
}
}
@ -1439,7 +1434,7 @@ static int bch2_statfs(struct dentry *dentry, struct kstatfs *buf)
buf->f_blocks = (c->capacity - hidden_metadata) >> shift;
buf->f_bfree = (c->capacity - bch2_fs_sectors_used(c, usage)) >> shift;
buf->f_bavail = buf->f_bfree;
buf->f_files = atomic_long_read(&c->nr_inodes);
buf->f_files = usage.nr_inodes;
buf->f_ffree = U64_MAX;
fsid = le64_to_cpup((void *) c->sb.user_uuid.b) ^

View File

@ -1314,9 +1314,6 @@ peek_nlinks: link = genradix_iter_peek(&nlinks_iter, links);
BUG_ON(ret == -EINTR);
if (ret)
break;
if (link->count)
atomic_long_inc(&c->nr_inodes);
} else {
/* Should have been caught by dirents pass: */
need_fsck_err_on(link->count, c,
@ -1380,7 +1377,6 @@ static int check_inodes_fast(struct bch_fs *c)
struct btree_iter iter;
struct bkey_s_c k;
struct bkey_s_c_inode inode;
unsigned long nr_inodes = 0;
int ret = 0;
for_each_btree_key(&iter, c, BTREE_ID_INODES, POS_MIN, 0, k) {
@ -1389,9 +1385,6 @@ static int check_inodes_fast(struct bch_fs *c)
inode = bkey_s_c_to_inode(k);
if (!(inode.v->bi_flags & BCH_INODE_UNLINKED))
nr_inodes++;
if (inode.v->bi_flags &
(BCH_INODE_I_SIZE_DIRTY|
BCH_INODE_I_SECTORS_DIRTY|
@ -1405,7 +1398,6 @@ static int check_inodes_fast(struct bch_fs *c)
break;
}
}
atomic_long_set(&c->nr_inodes, nr_inodes);
fsck_err:
return bch2_btree_iter_unlock(&iter) ?: ret;
}

View File

@ -375,8 +375,6 @@ int bch2_fs_initialize(struct bch_fs *c)
if (ret)
goto err;
atomic_long_set(&c->nr_inodes, 2);
if (enabled_qtypes(c)) {
ret = bch2_fs_quota_read(c);
if (ret)