@@ -162,15 +162,21 @@ void bch2_btree_node_hash_remove(struct btree_cache *bc, struct btree *b)
162
162
163
163
/* Cause future lookups for this node to fail: */
164
164
b -> hash_val = 0 ;
165
+
166
+ if (b -> c .btree_id < BTREE_ID_NR )
167
+ -- bc -> used_by_btree [b -> c .btree_id ];
165
168
}
166
169
167
170
int __bch2_btree_node_hash_insert (struct btree_cache * bc , struct btree * b )
168
171
{
169
172
BUG_ON (b -> hash_val );
170
173
b -> hash_val = btree_ptr_hash_val (& b -> key );
171
174
172
- return rhashtable_lookup_insert_fast (& bc -> table , & b -> hash ,
173
- bch_btree_cache_params );
175
+ int ret = rhashtable_lookup_insert_fast (& bc -> table , & b -> hash ,
176
+ bch_btree_cache_params );
177
+ if (!ret && b -> c .btree_id < BTREE_ID_NR )
178
+ bc -> used_by_btree [b -> c .btree_id ]++ ;
179
+ return ret ;
174
180
}
175
181
176
182
int bch2_btree_node_hash_insert (struct btree_cache * bc , struct btree * b ,
@@ -1269,9 +1275,26 @@ void bch2_btree_node_to_text(struct printbuf *out, struct bch_fs *c, const struc
1269
1275
stats .failed );
1270
1276
}
1271
1277
1278
+ static void prt_btree_cache_line (struct printbuf * out , const struct bch_fs * c ,
1279
+ const char * label , unsigned nr )
1280
+ {
1281
+ prt_printf (out , "%s\t" , label );
1282
+ prt_human_readable_u64 (out , nr * c -> opts .btree_node_size );
1283
+ prt_printf (out , " (%u)\n" , nr );
1284
+ }
1285
+
1272
1286
void bch2_btree_cache_to_text (struct printbuf * out , const struct bch_fs * c )
1273
1287
{
1274
- prt_printf (out , "nr nodes:\t\t%u\n" , c -> btree_cache .used );
1275
- prt_printf (out , "nr dirty:\t\t%u\n" , atomic_read (& c -> btree_cache .dirty ));
1276
- prt_printf (out , "cannibalize lock:\t%p\n" , c -> btree_cache .alloc_lock );
1288
+ const struct btree_cache * bc = & c -> btree_cache ;
1289
+
1290
+ if (!out -> nr_tabstops )
1291
+ printbuf_tabstop_push (out , 24 );
1292
+
1293
+ prt_btree_cache_line (out , c , "total:" , bc -> used );
1294
+ prt_btree_cache_line (out , c , "nr dirty:" , atomic_read (& bc -> dirty ));
1295
+ prt_printf (out , "cannibalize lock:\t%p\n" , bc -> alloc_lock );
1296
+ prt_newline (out );
1297
+
1298
+ for (unsigned i = 0 ; i < ARRAY_SIZE (bc -> used_by_btree ); i ++ )
1299
+ prt_btree_cache_line (out , c , bch2_btree_id_str (i ), bc -> used_by_btree [i ]);
1277
1300
}
0 commit comments