@@ -162,15 +162,21 @@ void bch2_btree_node_hash_remove(struct btree_cache *bc, struct btree *b)
162162
163163 /* Cause future lookups for this node to fail: */
164164 b -> hash_val = 0 ;
165+
166+ if (b -> c .btree_id < BTREE_ID_NR )
167+ -- bc -> used_by_btree [b -> c .btree_id ];
165168}
166169
167170int __bch2_btree_node_hash_insert (struct btree_cache * bc , struct btree * b )
168171{
169172 BUG_ON (b -> hash_val );
170173 b -> hash_val = btree_ptr_hash_val (& b -> key );
171174
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 ;
174180}
175181
176182int 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
12691275 stats .failed );
12701276}
12711277
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+
12721286void bch2_btree_cache_to_text (struct printbuf * out , const struct bch_fs * c )
12731287{
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 ]);
12771300}
0 commit comments