]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/btree_key_cache.h
New upstream snapshot
[bcachefs-tools-debian] / libbcachefs / btree_key_cache.h
1 #ifndef _BCACHEFS_BTREE_KEY_CACHE_H
2 #define _BCACHEFS_BTREE_KEY_CACHE_H
3
4 static inline size_t bch2_nr_btree_keys_need_flush(struct bch_fs *c)
5 {
6         size_t nr_dirty = atomic_long_read(&c->btree_key_cache.nr_dirty);
7         size_t nr_keys = atomic_long_read(&c->btree_key_cache.nr_keys);
8         size_t max_dirty = 1024 + nr_keys  / 2;
9
10         return max_t(ssize_t, 0, nr_dirty - max_dirty);
11 }
12
13 static inline bool bch2_btree_key_cache_must_wait(struct bch_fs *c)
14 {
15         size_t nr_dirty = atomic_long_read(&c->btree_key_cache.nr_dirty);
16         size_t nr_keys = atomic_long_read(&c->btree_key_cache.nr_keys);
17         size_t max_dirty = 4096 + (nr_keys * 3) / 4;
18
19         return nr_dirty > max_dirty &&
20                 test_bit(JOURNAL_RECLAIM_STARTED, &c->journal.flags);
21 }
22
23 int bch2_btree_key_cache_journal_flush(struct journal *,
24                                 struct journal_entry_pin *, u64);
25
26 struct bkey_cached *
27 bch2_btree_key_cache_find(struct bch_fs *, enum btree_id, struct bpos);
28
29 int bch2_btree_iter_traverse_cached(struct btree_iter *);
30
31 bool bch2_btree_insert_key_cached(struct btree_trans *,
32                         struct btree_iter *, struct bkey_i *);
33 int bch2_btree_key_cache_flush(struct btree_trans *,
34                                enum btree_id, struct bpos);
35 #ifdef CONFIG_BCACHEFS_DEBUG
36 void bch2_btree_key_cache_verify_clean(struct btree_trans *,
37                                 enum btree_id, struct bpos);
38 #else
39 static inline void
40 bch2_btree_key_cache_verify_clean(struct btree_trans *trans,
41                                 enum btree_id id, struct bpos pos) {}
42 #endif
43
44 void bch2_fs_btree_key_cache_exit(struct btree_key_cache *);
45 void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *);
46 int bch2_fs_btree_key_cache_init(struct btree_key_cache *);
47
48 void bch2_btree_key_cache_to_text(struct printbuf *, struct btree_key_cache *);
49
50 void bch2_btree_key_cache_exit(void);
51 int __init bch2_btree_key_cache_init(void);
52
53 #endif /* _BCACHEFS_BTREE_KEY_CACHE_H */