Skip to content

Commit 5132b99

Browse files
author
Kent Overstreet
committed
bcachefs: Kill __bch2_accounting_mem_mod()
The next patch will be adding a disk accounting counter type which is not kept in the in-memory eytzinger tree. As prep, fold __bch2_accounting_mem_mod() into bch2_accounting_mem_mod_locked() so that we can check for that counter type and bail out without calling bpos_to_disk_accounting_pos() twice. Signed-off-by: Kent Overstreet <[email protected]>
1 parent d97de0d commit 5132b99

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

fs/bcachefs/btree_trans_commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
712712
a->k.version = journal_pos_to_bversion(&trans->journal_res,
713713
(u64 *) entry - (u64 *) trans->journal_entries);
714714
BUG_ON(bversion_zero(a->k.version));
715-
ret = bch2_accounting_mem_mod_locked(trans, accounting_i_to_s_c(a), false);
715+
ret = bch2_accounting_mem_mod_locked(trans, accounting_i_to_s_c(a), false, false);
716716
if (ret)
717717
goto revert_fs_usage;
718718
}
@@ -798,7 +798,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
798798
struct bkey_s_accounting a = bkey_i_to_s_accounting(entry2->start);
799799

800800
bch2_accounting_neg(a);
801-
bch2_accounting_mem_mod_locked(trans, a.c, false);
801+
bch2_accounting_mem_mod_locked(trans, a.c, false, false);
802802
bch2_accounting_neg(a);
803803
}
804804
percpu_up_read(&c->mark_lock);

fs/bcachefs/disk_accounting.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ int bch2_gc_accounting_done(struct bch_fs *c)
566566
struct { __BKEY_PADDED(k, BCH_ACCOUNTING_MAX_COUNTERS); } k_i;
567567

568568
accounting_key_init(&k_i.k, &acc_k, src_v, nr);
569-
bch2_accounting_mem_mod_locked(trans, bkey_i_to_s_c_accounting(&k_i.k), false);
569+
bch2_accounting_mem_mod_locked(trans, bkey_i_to_s_c_accounting(&k_i.k), false, false);
570570

571571
preempt_disable();
572572
struct bch_fs_usage_base *dst = this_cpu_ptr(c->usage);
@@ -595,7 +595,7 @@ static int accounting_read_key(struct btree_trans *trans, struct bkey_s_c k)
595595
return 0;
596596

597597
percpu_down_read(&c->mark_lock);
598-
int ret = __bch2_accounting_mem_mod(c, bkey_s_c_to_accounting(k), false);
598+
int ret = bch2_accounting_mem_mod_locked(trans, bkey_s_c_to_accounting(k), false, true);
599599
percpu_up_read(&c->mark_lock);
600600

601601
if (bch2_accounting_key_is_zero(bkey_s_c_to_accounting(k)) &&

fs/bcachefs/disk_accounting.h

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -106,41 +106,17 @@ static inline int accounting_pos_cmp(const void *_l, const void *_r)
106106
int bch2_accounting_mem_insert(struct bch_fs *, struct bkey_s_c_accounting, bool);
107107
void bch2_accounting_mem_gc(struct bch_fs *);
108108

109-
static inline int __bch2_accounting_mem_mod(struct bch_fs *c, struct bkey_s_c_accounting a, bool gc)
110-
{
111-
struct bch_accounting_mem *acc = &c->accounting;
112-
unsigned idx;
113-
114-
EBUG_ON(gc && !acc->gc_running);
115-
116-
while ((idx = eytzinger0_find(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]),
117-
accounting_pos_cmp, &a.k->p)) >= acc->k.nr) {
118-
int ret = bch2_accounting_mem_insert(c, a, gc);
119-
if (ret)
120-
return ret;
121-
}
122-
123-
struct accounting_mem_entry *e = &acc->k.data[idx];
124-
125-
EBUG_ON(bch2_accounting_counters(a.k) != e->nr_counters);
126-
127-
for (unsigned i = 0; i < bch2_accounting_counters(a.k); i++)
128-
this_cpu_add(e->v[gc][i], a.v->d[i]);
129-
return 0;
130-
}
131-
132109
/*
133110
* Update in memory counters so they match the btree update we're doing; called
134111
* from transaction commit path
135112
*/
136-
static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc)
113+
static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc, bool read)
137114
{
138115
struct bch_fs *c = trans->c;
116+
struct disk_accounting_pos acc_k;
117+
bpos_to_disk_accounting_pos(&acc_k, a.k->p);
139118

140-
if (!gc) {
141-
struct disk_accounting_pos acc_k;
142-
bpos_to_disk_accounting_pos(&acc_k, a.k->p);
143-
119+
if (!gc && !read) {
144120
switch (acc_k.type) {
145121
case BCH_DISK_ACCOUNTING_persistent_reserved:
146122
trans->fs_usage_delta.reserved += acc_k.persistent_reserved.nr_replicas * a.v->d[0];
@@ -161,13 +137,31 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, stru
161137
}
162138
}
163139

164-
return __bch2_accounting_mem_mod(c, a, gc);
140+
struct bch_accounting_mem *acc = &c->accounting;
141+
unsigned idx;
142+
143+
EBUG_ON(gc && !acc->gc_running);
144+
145+
while ((idx = eytzinger0_find(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]),
146+
accounting_pos_cmp, &a.k->p)) >= acc->k.nr) {
147+
int ret = bch2_accounting_mem_insert(c, a, gc);
148+
if (ret)
149+
return ret;
150+
}
151+
152+
struct accounting_mem_entry *e = &acc->k.data[idx];
153+
154+
EBUG_ON(bch2_accounting_counters(a.k) != e->nr_counters);
155+
156+
for (unsigned i = 0; i < bch2_accounting_counters(a.k); i++)
157+
this_cpu_add(e->v[gc][i], a.v->d[i]);
158+
return 0;
165159
}
166160

167161
static inline int bch2_accounting_mem_add(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc)
168162
{
169163
percpu_down_read(&trans->c->mark_lock);
170-
int ret = bch2_accounting_mem_mod_locked(trans, a, gc);
164+
int ret = bch2_accounting_mem_mod_locked(trans, a, gc, false);
171165
percpu_up_read(&trans->c->mark_lock);
172166
return ret;
173167
}

0 commit comments

Comments
 (0)