1 #ifndef _BCACHE_BTREE_CACHE_H
2 #define _BCACHE_BTREE_CACHE_H
5 #include "btree_types.h"
9 extern const char * const bch2_btree_ids[];
11 void bch2_recalc_btree_reserve(struct bch_fs *);
13 void bch2_btree_node_hash_remove(struct bch_fs *, struct btree *);
14 int bch2_btree_node_hash_insert(struct bch_fs *, struct btree *,
15 unsigned, enum btree_id);
17 void bch2_btree_node_cannibalize_unlock(struct bch_fs *);
18 int bch2_btree_node_cannibalize_lock(struct bch_fs *, struct closure *);
20 struct btree *bch2_btree_node_mem_alloc(struct bch_fs *);
22 struct btree *bch2_btree_node_get(struct btree_iter *, const struct bkey_i *,
23 unsigned, enum six_lock_type);
25 void bch2_btree_node_prefetch(struct btree_iter *, const struct bkey_i *,
28 void bch2_fs_btree_exit(struct bch_fs *);
29 int bch2_fs_btree_init(struct bch_fs *);
31 #define for_each_cached_btree(_b, _c, _tbl, _iter, _pos) \
32 for ((_tbl) = rht_dereference_rcu((_c)->btree_cache_table.tbl, \
33 &(_c)->btree_cache_table), \
34 _iter = 0; _iter < (_tbl)->size; _iter++) \
35 rht_for_each_entry_rcu((_b), (_pos), _tbl, _iter, hash)
37 static inline size_t btree_bytes(struct bch_fs *c)
39 return c->sb.btree_node_size << 9;
42 static inline size_t btree_max_u64s(struct bch_fs *c)
44 return (btree_bytes(c) - sizeof(struct btree_node)) / sizeof(u64);
47 static inline size_t btree_pages(struct bch_fs *c)
49 return c->sb.btree_node_size >> (PAGE_SHIFT - 9);
52 static inline size_t btree_page_order(struct bch_fs *c)
54 return ilog2(btree_pages(c));
57 static inline unsigned btree_blocks(struct bch_fs *c)
59 return c->sb.btree_node_size >> c->block_bits;
62 #define BTREE_SPLIT_THRESHOLD(c) (btree_blocks(c) * 3 / 4)
64 #define BTREE_FOREGROUND_MERGE_THRESHOLD(c) (btree_max_u64s(c) * 1 / 3)
65 #define BTREE_FOREGROUND_MERGE_HYSTERESIS(c) \
66 (BTREE_FOREGROUND_MERGE_THRESHOLD(c) + \
67 (BTREE_FOREGROUND_MERGE_THRESHOLD(c) << 2))
69 #define btree_node_root(_c, _b) ((_c)->btree_roots[(_b)->btree_id].b)
71 int bch2_print_btree_node(struct bch_fs *, struct btree *,
74 #endif /* _BCACHE_BTREE_CACHE_H */