Loading fs/bcachefs/bcachefs.h +1 −2 Original line number Diff line number Diff line Loading @@ -891,8 +891,7 @@ struct bch_fs { struct percpu_rw_semaphore mark_lock; seqcount_t usage_lock; struct bch_fs_usage *usage_base; struct bch_fs_usage __percpu *usage[JOURNAL_BUF_NR]; struct bch_fs_usage_base __percpu *usage; struct bch_fs_usage __percpu *usage_gc; u64 __percpu *online_reserved; Loading fs/bcachefs/btree_gc.c +5 −4 Original line number Diff line number Diff line Loading @@ -769,10 +769,8 @@ static int bch2_gc_done(struct bch_fs *c) #define copy_fs_field(_err, _f, _msg, ...) \ copy_field(_err, _f, "fs has wrong " _msg, ##__VA_ARGS__) for (i = 0; i < ARRAY_SIZE(c->usage); i++) bch2_fs_usage_acc_to_base(c, i); __for_each_member_device(c, ca) { /* XXX */ struct bch_dev_usage *dst = this_cpu_ptr(ca->usage); struct bch_dev_usage *src = (void *) bch2_acc_percpu_u64s((u64 __percpu *) ca->usage_gc, Loading @@ -789,8 +787,10 @@ static int bch2_gc_done(struct bch_fs *c) } { #if 0 unsigned nr = fs_usage_u64s(c); struct bch_fs_usage *dst = c->usage_base; /* XX: */ struct bch_fs_usage *dst = this_cpu_ptr(c->usage); struct bch_fs_usage *src = (void *) bch2_acc_percpu_u64s((u64 __percpu *) c->usage_gc, nr); Loading Loading @@ -823,6 +823,7 @@ static int bch2_gc_done(struct bch_fs *c) copy_fs_field(fs_usage_replicas_wrong, replicas[i], "%s", buf.buf); } #endif } #undef copy_fs_field Loading fs/bcachefs/buckets.c +6 −55 Original line number Diff line number Diff line Loading @@ -26,61 +26,12 @@ #include <linux/preempt.h> static inline struct bch_fs_usage *fs_usage_ptr(struct bch_fs *c, unsigned journal_seq, bool gc) { percpu_rwsem_assert_held(&c->mark_lock); BUG_ON(!gc && !journal_seq); return this_cpu_ptr(gc ? c->usage_gc : c->usage[journal_seq & JOURNAL_BUF_MASK]); } void bch2_dev_usage_read_fast(struct bch_dev *ca, struct bch_dev_usage *usage) { memset(usage, 0, sizeof(*usage)); acc_u64s_percpu((u64 *) usage, (u64 __percpu *) ca->usage, dev_usage_u64s()); } u64 bch2_fs_usage_read_one(struct bch_fs *c, u64 *v) { ssize_t offset = v - (u64 *) c->usage_base; unsigned i, seq; u64 ret; BUG_ON(offset < 0 || offset >= fs_usage_u64s(c)); percpu_rwsem_assert_held(&c->mark_lock); do { seq = read_seqcount_begin(&c->usage_lock); ret = *v; for (i = 0; i < ARRAY_SIZE(c->usage); i++) ret += percpu_u64_get((u64 __percpu *) c->usage[i] + offset); } while (read_seqcount_retry(&c->usage_lock, seq)); return ret; } void bch2_fs_usage_acc_to_base(struct bch_fs *c, unsigned idx) { unsigned u64s = fs_usage_u64s(c); BUG_ON(idx >= ARRAY_SIZE(c->usage)); preempt_disable(); write_seqcount_begin(&c->usage_lock); acc_u64s_percpu((u64 *) c->usage_base, (u64 __percpu *) c->usage[idx], u64s); percpu_memset(c->usage[idx], 0, u64s * sizeof(u64)); write_seqcount_end(&c->usage_lock); preempt_enable(); } void bch2_fs_usage_to_text(struct printbuf *out, struct bch_fs *c, struct bch_fs_usage_online *fs_usage) Loading Loading @@ -142,17 +93,17 @@ __bch2_fs_usage_read_short(struct bch_fs *c) u64 data, reserved; ret.capacity = c->capacity - bch2_fs_usage_read_one(c, &c->usage_base->b.hidden); percpu_u64_get(&c->usage->hidden); data = bch2_fs_usage_read_one(c, &c->usage_base->b.data) + bch2_fs_usage_read_one(c, &c->usage_base->b.btree); reserved = bch2_fs_usage_read_one(c, &c->usage_base->b.reserved) + data = percpu_u64_get(&c->usage->data) + percpu_u64_get(&c->usage->btree); reserved = percpu_u64_get(&c->usage->reserved) + percpu_u64_get(c->online_reserved); ret.used = min(ret.capacity, data + reserve_factor(reserved)); ret.free = ret.capacity - ret.used; ret.nr_inodes = bch2_fs_usage_read_one(c, &c->usage_base->b.nr_inodes); ret.nr_inodes = percpu_u64_get(&c->usage->nr_inodes); return ret; } Loading Loading @@ -673,7 +624,7 @@ void bch2_trans_account_disk_usage_change(struct btree_trans *trans) percpu_down_read(&c->mark_lock); preempt_disable(); struct bch_fs_usage_base *dst = &fs_usage_ptr(c, trans->journal_res.seq, false)->b; struct bch_fs_usage_base *dst = this_cpu_ptr(c->usage); struct bch_fs_usage_base *src = &trans->fs_usage_delta; s64 added = src->btree + src->data + src->reserved; Loading fs/bcachefs/buckets.h +0 −4 Original line number Diff line number Diff line Loading @@ -298,10 +298,6 @@ static inline unsigned dev_usage_u64s(void) return sizeof(struct bch_dev_usage) / sizeof(u64); } u64 bch2_fs_usage_read_one(struct bch_fs *, u64 *); void bch2_fs_usage_acc_to_base(struct bch_fs *, unsigned); void bch2_fs_usage_to_text(struct printbuf *, struct bch_fs *, struct bch_fs_usage_online *); Loading fs/bcachefs/disk_accounting.c +1 −1 Original line number Diff line number Diff line Loading @@ -384,7 +384,7 @@ int bch2_accounting_read(struct bch_fs *c) percpu_down_read(&c->mark_lock); preempt_disable(); struct bch_fs_usage_base *usage = &c->usage_base->b; struct bch_fs_usage_base *usage = this_cpu_ptr(c->usage); for (unsigned i = 0; i < acc->k.nr; i++) { struct disk_accounting_pos k; Loading Loading
fs/bcachefs/bcachefs.h +1 −2 Original line number Diff line number Diff line Loading @@ -891,8 +891,7 @@ struct bch_fs { struct percpu_rw_semaphore mark_lock; seqcount_t usage_lock; struct bch_fs_usage *usage_base; struct bch_fs_usage __percpu *usage[JOURNAL_BUF_NR]; struct bch_fs_usage_base __percpu *usage; struct bch_fs_usage __percpu *usage_gc; u64 __percpu *online_reserved; Loading
fs/bcachefs/btree_gc.c +5 −4 Original line number Diff line number Diff line Loading @@ -769,10 +769,8 @@ static int bch2_gc_done(struct bch_fs *c) #define copy_fs_field(_err, _f, _msg, ...) \ copy_field(_err, _f, "fs has wrong " _msg, ##__VA_ARGS__) for (i = 0; i < ARRAY_SIZE(c->usage); i++) bch2_fs_usage_acc_to_base(c, i); __for_each_member_device(c, ca) { /* XXX */ struct bch_dev_usage *dst = this_cpu_ptr(ca->usage); struct bch_dev_usage *src = (void *) bch2_acc_percpu_u64s((u64 __percpu *) ca->usage_gc, Loading @@ -789,8 +787,10 @@ static int bch2_gc_done(struct bch_fs *c) } { #if 0 unsigned nr = fs_usage_u64s(c); struct bch_fs_usage *dst = c->usage_base; /* XX: */ struct bch_fs_usage *dst = this_cpu_ptr(c->usage); struct bch_fs_usage *src = (void *) bch2_acc_percpu_u64s((u64 __percpu *) c->usage_gc, nr); Loading Loading @@ -823,6 +823,7 @@ static int bch2_gc_done(struct bch_fs *c) copy_fs_field(fs_usage_replicas_wrong, replicas[i], "%s", buf.buf); } #endif } #undef copy_fs_field Loading
fs/bcachefs/buckets.c +6 −55 Original line number Diff line number Diff line Loading @@ -26,61 +26,12 @@ #include <linux/preempt.h> static inline struct bch_fs_usage *fs_usage_ptr(struct bch_fs *c, unsigned journal_seq, bool gc) { percpu_rwsem_assert_held(&c->mark_lock); BUG_ON(!gc && !journal_seq); return this_cpu_ptr(gc ? c->usage_gc : c->usage[journal_seq & JOURNAL_BUF_MASK]); } void bch2_dev_usage_read_fast(struct bch_dev *ca, struct bch_dev_usage *usage) { memset(usage, 0, sizeof(*usage)); acc_u64s_percpu((u64 *) usage, (u64 __percpu *) ca->usage, dev_usage_u64s()); } u64 bch2_fs_usage_read_one(struct bch_fs *c, u64 *v) { ssize_t offset = v - (u64 *) c->usage_base; unsigned i, seq; u64 ret; BUG_ON(offset < 0 || offset >= fs_usage_u64s(c)); percpu_rwsem_assert_held(&c->mark_lock); do { seq = read_seqcount_begin(&c->usage_lock); ret = *v; for (i = 0; i < ARRAY_SIZE(c->usage); i++) ret += percpu_u64_get((u64 __percpu *) c->usage[i] + offset); } while (read_seqcount_retry(&c->usage_lock, seq)); return ret; } void bch2_fs_usage_acc_to_base(struct bch_fs *c, unsigned idx) { unsigned u64s = fs_usage_u64s(c); BUG_ON(idx >= ARRAY_SIZE(c->usage)); preempt_disable(); write_seqcount_begin(&c->usage_lock); acc_u64s_percpu((u64 *) c->usage_base, (u64 __percpu *) c->usage[idx], u64s); percpu_memset(c->usage[idx], 0, u64s * sizeof(u64)); write_seqcount_end(&c->usage_lock); preempt_enable(); } void bch2_fs_usage_to_text(struct printbuf *out, struct bch_fs *c, struct bch_fs_usage_online *fs_usage) Loading Loading @@ -142,17 +93,17 @@ __bch2_fs_usage_read_short(struct bch_fs *c) u64 data, reserved; ret.capacity = c->capacity - bch2_fs_usage_read_one(c, &c->usage_base->b.hidden); percpu_u64_get(&c->usage->hidden); data = bch2_fs_usage_read_one(c, &c->usage_base->b.data) + bch2_fs_usage_read_one(c, &c->usage_base->b.btree); reserved = bch2_fs_usage_read_one(c, &c->usage_base->b.reserved) + data = percpu_u64_get(&c->usage->data) + percpu_u64_get(&c->usage->btree); reserved = percpu_u64_get(&c->usage->reserved) + percpu_u64_get(c->online_reserved); ret.used = min(ret.capacity, data + reserve_factor(reserved)); ret.free = ret.capacity - ret.used; ret.nr_inodes = bch2_fs_usage_read_one(c, &c->usage_base->b.nr_inodes); ret.nr_inodes = percpu_u64_get(&c->usage->nr_inodes); return ret; } Loading Loading @@ -673,7 +624,7 @@ void bch2_trans_account_disk_usage_change(struct btree_trans *trans) percpu_down_read(&c->mark_lock); preempt_disable(); struct bch_fs_usage_base *dst = &fs_usage_ptr(c, trans->journal_res.seq, false)->b; struct bch_fs_usage_base *dst = this_cpu_ptr(c->usage); struct bch_fs_usage_base *src = &trans->fs_usage_delta; s64 added = src->btree + src->data + src->reserved; Loading
fs/bcachefs/buckets.h +0 −4 Original line number Diff line number Diff line Loading @@ -298,10 +298,6 @@ static inline unsigned dev_usage_u64s(void) return sizeof(struct bch_dev_usage) / sizeof(u64); } u64 bch2_fs_usage_read_one(struct bch_fs *, u64 *); void bch2_fs_usage_acc_to_base(struct bch_fs *, unsigned); void bch2_fs_usage_to_text(struct printbuf *, struct bch_fs *, struct bch_fs_usage_online *); Loading
fs/bcachefs/disk_accounting.c +1 −1 Original line number Diff line number Diff line Loading @@ -384,7 +384,7 @@ int bch2_accounting_read(struct bch_fs *c) percpu_down_read(&c->mark_lock); preempt_disable(); struct bch_fs_usage_base *usage = &c->usage_base->b; struct bch_fs_usage_base *usage = this_cpu_ptr(c->usage); for (unsigned i = 0; i < acc->k.nr; i++) { struct disk_accounting_pos k; Loading