Skip to content

Commit e11ecc6

Browse files
author
Kent Overstreet
committed
bcachefs: Improve sysfs internal/btree_cache
Signed-off-by: Kent Overstreet <[email protected]>
1 parent c670509 commit e11ecc6

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

fs/bcachefs/btree_cache.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

167170
int __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

176182
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
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+
12721286
void 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
}

fs/bcachefs/btree_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ struct btree_cache {
166166
atomic_t dirty;
167167
struct shrinker *shrink;
168168

169+
unsigned used_by_btree[BTREE_ID_NR];
170+
169171
/*
170172
* If we need to allocate memory for a new btree node and that
171173
* allocation fails, we can cannibalize another node in the btree cache

0 commit comments

Comments
 (0)