X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libbcachefs%2Fbtree_cache.h;h=00c9b92183e7969839d48240e3e4b05498a98ed7;hb=5e215654da7e97a6395de6e7592fbaa426697897;hp=bc24d92678d3f2713b0ee3c05eaff3aa80867ab4;hpb=dbb99e492daa3ffe623685f3871dfcb97c01cd4f;p=bcachefs-tools-debian diff --git a/libbcachefs/btree_cache.h b/libbcachefs/btree_cache.h index bc24d92..00c9b92 100644 --- a/libbcachefs/btree_cache.h +++ b/libbcachefs/btree_cache.h @@ -4,10 +4,11 @@ #include "bcachefs.h" #include "btree_types.h" +#include "bkey_methods.h" -struct btree_iter; +extern const char * const bch2_btree_node_flags[]; -extern const char * const bch2_btree_ids[]; +struct btree_iter; void bch2_recalc_btree_reserve(struct bch_fs *); @@ -19,17 +20,20 @@ int bch2_btree_node_hash_insert(struct btree_cache *, struct btree *, void bch2_btree_cache_cannibalize_unlock(struct bch_fs *); int bch2_btree_cache_cannibalize_lock(struct bch_fs *, struct closure *); -struct btree *bch2_btree_node_mem_alloc(struct bch_fs *); +struct btree *__bch2_btree_node_mem_alloc(struct bch_fs *); +struct btree *bch2_btree_node_mem_alloc(struct btree_trans *, bool); -struct btree *bch2_btree_node_get(struct bch_fs *, struct btree_iter *, +struct btree *bch2_btree_node_get(struct btree_trans *, struct btree_path *, const struct bkey_i *, unsigned, - enum six_lock_type); + enum six_lock_type, unsigned long); -struct btree *bch2_btree_node_get_sibling(struct bch_fs *, struct btree_iter *, - struct btree *, enum btree_node_sibling); +struct btree *bch2_btree_node_get_noiter(struct btree_trans *, const struct bkey_i *, + enum btree_id, unsigned, bool); -void bch2_btree_node_prefetch(struct bch_fs *, struct btree_iter *, - const struct bkey_i *, unsigned); +int bch2_btree_node_prefetch(struct btree_trans *, struct btree_path *, + const struct bkey_i *, enum btree_id, unsigned); + +void bch2_btree_node_evict(struct btree_trans *, const struct bkey_i *); void bch2_fs_btree_cache_exit(struct bch_fs *); int bch2_fs_btree_cache_init(struct bch_fs *); @@ -41,7 +45,11 @@ static inline u64 btree_ptr_hash_val(const struct bkey_i *k) case KEY_TYPE_btree_ptr: return *((u64 *) bkey_i_to_btree_ptr_c(k)->v.start); case KEY_TYPE_btree_ptr_v2: - return bkey_i_to_btree_ptr_v2_c(k)->v.seq; + /* + * The cast/deref is only necessary to avoid sparse endianness + * warnings: + */ + return *((u64 *) &bkey_i_to_btree_ptr_v2_c(k)->v.seq); default: return 0; } @@ -68,7 +76,7 @@ static inline bool btree_node_hashed(struct btree *b) static inline size_t btree_bytes(struct bch_fs *c) { - return c->opts.btree_node_size << 9; + return c->opts.btree_node_size; } static inline size_t btree_max_u64s(struct bch_fs *c) @@ -76,31 +84,47 @@ static inline size_t btree_max_u64s(struct bch_fs *c) return (btree_bytes(c) - sizeof(struct btree_node)) / sizeof(u64); } -static inline size_t btree_page_order(struct bch_fs *c) -{ - return get_order(btree_bytes(c)); -} - static inline size_t btree_pages(struct bch_fs *c) { - return 1 << btree_page_order(c); + return btree_bytes(c) / PAGE_SIZE; } static inline unsigned btree_blocks(struct bch_fs *c) { - return c->opts.btree_node_size >> c->block_bits; + return btree_sectors(c) >> c->block_bits; } -#define BTREE_SPLIT_THRESHOLD(c) (btree_max_u64s(c) * 3 / 4) +#define BTREE_SPLIT_THRESHOLD(c) (btree_max_u64s(c) * 2 / 3) #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)) + (BTREE_FOREGROUND_MERGE_THRESHOLD(c) >> 2)) + +static inline unsigned btree_id_nr_alive(struct bch_fs *c) +{ + return BTREE_ID_NR + c->btree_roots_extra.nr; +} + +static inline struct btree_root *bch2_btree_id_root(struct bch_fs *c, unsigned id) +{ + if (likely(id < BTREE_ID_NR)) { + return &c->btree_roots_known[id]; + } else { + unsigned idx = id - BTREE_ID_NR; + + EBUG_ON(idx >= c->btree_roots_extra.nr); + return &c->btree_roots_extra.data[idx]; + } +} -#define btree_node_root(_c, _b) ((_c)->btree_roots[(_b)->btree_id].b) +static inline struct btree *btree_node_root(struct bch_fs *c, struct btree *b) +{ + return bch2_btree_id_root(c, b->c.btree_id)->b; +} void bch2_btree_node_to_text(struct printbuf *, struct bch_fs *, - struct btree *); + const struct btree *); +void bch2_btree_cache_to_text(struct printbuf *, const struct btree_cache *); #endif /* _BCACHEFS_BTREE_CACHE_H */