bcachefs-tools/libbcachefs/btree_cache.h

90 lines
2.5 KiB
C
Raw Normal View History

#ifndef _BCACHEFS_BTREE_CACHE_H
#define _BCACHEFS_BTREE_CACHE_H
2017-01-08 12:13:18 +03:00
#include "bcachefs.h"
2017-01-08 12:13:18 +03:00
#include "btree_types.h"
#include "extents.h"
2017-01-08 12:13:18 +03:00
struct btree_iter;
extern const char * const bch2_btree_ids[];
2017-01-08 12:13:18 +03:00
void bch2_recalc_btree_reserve(struct bch_fs *);
2017-01-08 12:13:18 +03:00
void bch2_btree_node_hash_remove(struct bch_fs *, struct btree *);
int __bch2_btree_node_hash_insert(struct bch_fs *, struct btree *);
int bch2_btree_node_hash_insert(struct bch_fs *, struct btree *,
unsigned, enum btree_id);
2017-01-08 12:13:18 +03:00
void bch2_btree_node_cannibalize_unlock(struct bch_fs *);
int bch2_btree_node_cannibalize_lock(struct bch_fs *, struct closure *);
2017-01-08 12:13:18 +03:00
struct btree *bch2_btree_node_mem_alloc(struct bch_fs *);
2017-01-08 12:13:18 +03:00
struct btree *bch2_btree_node_get(struct bch_fs *, struct btree_iter *,
const struct bkey_i *, unsigned,
enum six_lock_type);
2017-01-08 12:13:18 +03:00
struct btree *bch2_btree_node_get_sibling(struct bch_fs *, struct btree_iter *,
struct btree *,
enum btree_node_sibling);
void bch2_btree_node_prefetch(struct bch_fs *, const struct bkey_i *,
unsigned, enum btree_id);
2017-04-24 08:56:57 +03:00
void bch2_fs_btree_exit(struct bch_fs *);
int bch2_fs_btree_init(struct bch_fs *);
2017-01-08 12:13:18 +03:00
#define PTR_HASH(_k) (bkey_i_to_extent_c(_k)->v._data[0])
/* is btree node in hash table? */
static inline bool btree_node_hashed(struct btree *b)
{
return bkey_extent_is_data(&b->key.k) && PTR_HASH(&b->key);
}
2017-01-08 12:13:18 +03:00
#define for_each_cached_btree(_b, _c, _tbl, _iter, _pos) \
for ((_tbl) = rht_dereference_rcu((_c)->btree_cache_table.tbl, \
&(_c)->btree_cache_table), \
_iter = 0; _iter < (_tbl)->size; _iter++) \
rht_for_each_entry_rcu((_b), (_pos), _tbl, _iter, hash)
2017-03-11 00:40:01 +03:00
static inline size_t btree_bytes(struct bch_fs *c)
2017-01-08 12:13:18 +03:00
{
return c->opts.btree_node_size << 9;
2017-01-08 12:13:18 +03:00
}
2017-03-11 00:40:01 +03:00
static inline size_t btree_max_u64s(struct bch_fs *c)
2017-01-08 12:13:18 +03:00
{
return (btree_bytes(c) - sizeof(struct btree_node)) / sizeof(u64);
}
static inline size_t btree_page_order(struct bch_fs *c)
2017-01-08 12:13:18 +03:00
{
return get_order(btree_bytes(c));
2017-01-08 12:13:18 +03:00
}
static inline size_t btree_pages(struct bch_fs *c)
2017-01-08 12:13:18 +03:00
{
return 1 << btree_page_order(c);
2017-01-08 12:13:18 +03:00
}
2017-03-11 00:40:01 +03:00
static inline unsigned btree_blocks(struct bch_fs *c)
2017-01-08 12:13:18 +03:00
{
return c->opts.btree_node_size >> c->block_bits;
2017-01-08 12:13:18 +03:00
}
2017-02-02 06:16:42 +03:00
#define BTREE_SPLIT_THRESHOLD(c) (btree_blocks(c) * 3 / 4)
#define BTREE_FOREGROUND_MERGE_THRESHOLD(c) (btree_max_u64s(c) * 1 / 3)
#define BTREE_FOREGROUND_MERGE_HYSTERESIS(c) \
(BTREE_FOREGROUND_MERGE_THRESHOLD(c) + \
(BTREE_FOREGROUND_MERGE_THRESHOLD(c) << 2))
2017-01-08 12:13:18 +03:00
#define btree_node_root(_c, _b) ((_c)->btree_roots[(_b)->btree_id].b)
int bch2_print_btree_node(struct bch_fs *, struct btree *,
2017-02-02 06:16:42 +03:00
char *, size_t);
#endif /* _BCACHEFS_BTREE_CACHE_H */