@@ -106,41 +106,17 @@ static inline int accounting_pos_cmp(const void *_l, const void *_r)
106
106
int bch2_accounting_mem_insert (struct bch_fs * , struct bkey_s_c_accounting , bool );
107
107
void bch2_accounting_mem_gc (struct bch_fs * );
108
108
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
-
132
109
/*
133
110
* Update in memory counters so they match the btree update we're doing; called
134
111
* from transaction commit path
135
112
*/
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 )
137
114
{
138
115
struct bch_fs * c = trans -> c ;
116
+ struct disk_accounting_pos acc_k ;
117
+ bpos_to_disk_accounting_pos (& acc_k , a .k -> p );
139
118
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 ) {
144
120
switch (acc_k .type ) {
145
121
case BCH_DISK_ACCOUNTING_persistent_reserved :
146
122
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
161
137
}
162
138
}
163
139
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 ;
165
159
}
166
160
167
161
static inline int bch2_accounting_mem_add (struct btree_trans * trans , struct bkey_s_c_accounting a , bool gc )
168
162
{
169
163
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 );
171
165
percpu_up_read (& trans -> c -> mark_lock );
172
166
return ret ;
173
167
}
0 commit comments