@@ -136,6 +136,7 @@ enum bch_accounting_mode {
136
136
};
137
137
138
138
int bch2_accounting_mem_insert (struct bch_fs * , struct bkey_s_c_accounting , enum bch_accounting_mode );
139
+ int bch2_accounting_mem_insert_locked (struct bch_fs * , struct bkey_s_c_accounting , enum bch_accounting_mode );
139
140
void bch2_accounting_mem_gc (struct bch_fs * );
140
141
141
142
static inline bool bch2_accounting_is_mem (struct disk_accounting_pos acc )
@@ -150,7 +151,8 @@ static inline bool bch2_accounting_is_mem(struct disk_accounting_pos acc)
150
151
*/
151
152
static inline int bch2_accounting_mem_mod_locked (struct btree_trans * trans ,
152
153
struct bkey_s_c_accounting a ,
153
- enum bch_accounting_mode mode )
154
+ enum bch_accounting_mode mode ,
155
+ bool write_locked )
154
156
{
155
157
struct bch_fs * c = trans -> c ;
156
158
struct bch_accounting_mem * acc = & c -> accounting ;
@@ -189,7 +191,11 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans,
189
191
190
192
while ((idx = eytzinger0_find (acc -> k .data , acc -> k .nr , sizeof (acc -> k .data [0 ]),
191
193
accounting_pos_cmp , & a .k -> p )) >= acc -> k .nr ) {
192
- int ret = bch2_accounting_mem_insert (c , a , mode );
194
+ int ret = 0 ;
195
+ if (unlikely (write_locked ))
196
+ ret = bch2_accounting_mem_insert_locked (c , a , mode );
197
+ else
198
+ ret = bch2_accounting_mem_insert (c , a , mode );
193
199
if (ret )
194
200
return ret ;
195
201
}
@@ -206,7 +212,7 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans,
206
212
static inline int bch2_accounting_mem_add (struct btree_trans * trans , struct bkey_s_c_accounting a , bool gc )
207
213
{
208
214
percpu_down_read (& trans -> c -> mark_lock );
209
- int ret = bch2_accounting_mem_mod_locked (trans , a , gc ? BCH_ACCOUNTING_gc : BCH_ACCOUNTING_normal );
215
+ int ret = bch2_accounting_mem_mod_locked (trans , a , gc ? BCH_ACCOUNTING_gc : BCH_ACCOUNTING_normal , false );
210
216
percpu_up_read (& trans -> c -> mark_lock );
211
217
return ret ;
212
218
}
@@ -259,7 +265,7 @@ static inline int bch2_accounting_trans_commit_hook(struct btree_trans *trans,
259
265
EBUG_ON (bversion_zero (a -> k .bversion ));
260
266
261
267
return likely (!(commit_flags & BCH_TRANS_COMMIT_skip_accounting_apply ))
262
- ? bch2_accounting_mem_mod_locked (trans , accounting_i_to_s_c (a ), BCH_ACCOUNTING_normal )
268
+ ? bch2_accounting_mem_mod_locked (trans , accounting_i_to_s_c (a ), BCH_ACCOUNTING_normal , false )
263
269
: 0 ;
264
270
}
265
271
@@ -271,7 +277,7 @@ static inline void bch2_accounting_trans_commit_revert(struct btree_trans *trans
271
277
struct bkey_s_accounting a = accounting_i_to_s (a_i );
272
278
273
279
bch2_accounting_neg (a );
274
- bch2_accounting_mem_mod_locked (trans , a .c , BCH_ACCOUNTING_normal );
280
+ bch2_accounting_mem_mod_locked (trans , a .c , BCH_ACCOUNTING_normal , false );
275
281
bch2_accounting_neg (a );
276
282
}
277
283
}
0 commit comments