~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/bcachefs/btree_cache.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _BCACHEFS_BTREE_CACHE_H
  3 #define _BCACHEFS_BTREE_CACHE_H
  4 
  5 #include "bcachefs.h"
  6 #include "btree_types.h"
  7 #include "bkey_methods.h"
  8 
  9 extern const char * const bch2_btree_node_flags[];
 10 
 11 struct btree_iter;
 12 
 13 void bch2_recalc_btree_reserve(struct bch_fs *);
 14 
 15 void bch2_btree_node_to_freelist(struct bch_fs *, struct btree *);
 16 
 17 void bch2_btree_node_hash_remove(struct btree_cache *, struct btree *);
 18 int __bch2_btree_node_hash_insert(struct btree_cache *, struct btree *);
 19 int bch2_btree_node_hash_insert(struct btree_cache *, struct btree *,
 20                                 unsigned, enum btree_id);
 21 
 22 void bch2_btree_node_update_key_early(struct btree_trans *, enum btree_id, unsigned,
 23                                       struct bkey_s_c, struct bkey_i *);
 24 
 25 void bch2_btree_cache_cannibalize_unlock(struct btree_trans *);
 26 int bch2_btree_cache_cannibalize_lock(struct btree_trans *, struct closure *);
 27 
 28 struct btree *__bch2_btree_node_mem_alloc(struct bch_fs *);
 29 struct btree *bch2_btree_node_mem_alloc(struct btree_trans *, bool);
 30 
 31 struct btree *bch2_btree_node_get(struct btree_trans *, struct btree_path *,
 32                                   const struct bkey_i *, unsigned,
 33                                   enum six_lock_type, unsigned long);
 34 
 35 struct btree *bch2_btree_node_get_noiter(struct btree_trans *, const struct bkey_i *,
 36                                          enum btree_id, unsigned, bool);
 37 
 38 int bch2_btree_node_prefetch(struct btree_trans *, struct btree_path *,
 39                              const struct bkey_i *, enum btree_id, unsigned);
 40 
 41 void bch2_btree_node_evict(struct btree_trans *, const struct bkey_i *);
 42 
 43 void bch2_fs_btree_cache_exit(struct bch_fs *);
 44 int bch2_fs_btree_cache_init(struct bch_fs *);
 45 void bch2_fs_btree_cache_init_early(struct btree_cache *);
 46 
 47 static inline u64 btree_ptr_hash_val(const struct bkey_i *k)
 48 {
 49         switch (k->k.type) {
 50         case KEY_TYPE_btree_ptr:
 51                 return *((u64 *) bkey_i_to_btree_ptr_c(k)->v.start);
 52         case KEY_TYPE_btree_ptr_v2:
 53                 /*
 54                  * The cast/deref is only necessary to avoid sparse endianness
 55                  * warnings:
 56                  */
 57                 return *((u64 *) &bkey_i_to_btree_ptr_v2_c(k)->v.seq);
 58         default:
 59                 return 0;
 60         }
 61 }
 62 
 63 static inline struct btree *btree_node_mem_ptr(const struct bkey_i *k)
 64 {
 65         return k->k.type == KEY_TYPE_btree_ptr_v2
 66                 ? (void *)(unsigned long)bkey_i_to_btree_ptr_v2_c(k)->v.mem_ptr
 67                 : NULL;
 68 }
 69 
 70 /* is btree node in hash table? */
 71 static inline bool btree_node_hashed(struct btree *b)
 72 {
 73         return b->hash_val != 0;
 74 }
 75 
 76 #define for_each_cached_btree(_b, _c, _tbl, _iter, _pos)                \
 77         for ((_tbl) = rht_dereference_rcu((_c)->btree_cache.table.tbl,  \
 78                                           &(_c)->btree_cache.table),    \
 79              _iter = 0; _iter < (_tbl)->size; _iter++)                  \
 80                 rht_for_each_entry_rcu((_b), (_pos), _tbl, _iter, hash)
 81 
 82 static inline size_t btree_buf_bytes(const struct btree *b)
 83 {
 84         return 1UL << b->byte_order;
 85 }
 86 
 87 static inline size_t btree_buf_max_u64s(const struct btree *b)
 88 {
 89         return (btree_buf_bytes(b) - sizeof(struct btree_node)) / sizeof(u64);
 90 }
 91 
 92 static inline size_t btree_max_u64s(const struct bch_fs *c)
 93 {
 94         return (c->opts.btree_node_size - sizeof(struct btree_node)) / sizeof(u64);
 95 }
 96 
 97 static inline size_t btree_sectors(const struct bch_fs *c)
 98 {
 99         return c->opts.btree_node_size >> SECTOR_SHIFT;
100 }
101 
102 static inline unsigned btree_blocks(const struct bch_fs *c)
103 {
104         return btree_sectors(c) >> c->block_bits;
105 }
106 
107 #define BTREE_SPLIT_THRESHOLD(c)                (btree_max_u64s(c) * 2 / 3)
108 
109 #define BTREE_FOREGROUND_MERGE_THRESHOLD(c)     (btree_max_u64s(c) * 1 / 3)
110 #define BTREE_FOREGROUND_MERGE_HYSTERESIS(c)                    \
111         (BTREE_FOREGROUND_MERGE_THRESHOLD(c) +                  \
112          (BTREE_FOREGROUND_MERGE_THRESHOLD(c) >> 2))
113 
114 static inline unsigned btree_id_nr_alive(struct bch_fs *c)
115 {
116         return BTREE_ID_NR + c->btree_roots_extra.nr;
117 }
118 
119 static inline struct btree_root *bch2_btree_id_root(struct bch_fs *c, unsigned id)
120 {
121         if (likely(id < BTREE_ID_NR)) {
122                 return &c->btree_roots_known[id];
123         } else {
124                 unsigned idx = id - BTREE_ID_NR;
125 
126                 EBUG_ON(idx >= c->btree_roots_extra.nr);
127                 return &c->btree_roots_extra.data[idx];
128         }
129 }
130 
131 static inline struct btree *btree_node_root(struct bch_fs *c, struct btree *b)
132 {
133         return bch2_btree_id_root(c, b->c.btree_id)->b;
134 }
135 
136 const char *bch2_btree_id_str(enum btree_id);
137 void bch2_btree_id_to_text(struct printbuf *, enum btree_id);
138 
139 void bch2_btree_pos_to_text(struct printbuf *, struct bch_fs *, const struct btree *);
140 void bch2_btree_node_to_text(struct printbuf *, struct bch_fs *, const struct btree *);
141 void bch2_btree_cache_to_text(struct printbuf *, const struct btree_cache *);
142 
143 #endif /* _BCACHEFS_BTREE_CACHE_H */
144 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php