2022-10-24 00:39:22 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2020-06-14 02:31:45 +03:00
|
|
|
#ifndef _BCACHEFS_BTREE_KEY_CACHE_H
|
|
|
|
#define _BCACHEFS_BTREE_KEY_CACHE_H
|
|
|
|
|
2020-11-30 07:55:51 +03:00
|
|
|
static inline size_t bch2_nr_btree_keys_need_flush(struct bch_fs *c)
|
|
|
|
{
|
2021-03-29 00:38:28 +03:00
|
|
|
size_t nr_dirty = atomic_long_read(&c->btree_key_cache.nr_dirty);
|
|
|
|
size_t nr_keys = atomic_long_read(&c->btree_key_cache.nr_keys);
|
2020-12-20 02:05:09 +03:00
|
|
|
size_t max_dirty = 1024 + nr_keys / 2;
|
2020-11-30 07:55:51 +03:00
|
|
|
|
|
|
|
return max_t(ssize_t, 0, nr_dirty - max_dirty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool bch2_btree_key_cache_must_wait(struct bch_fs *c)
|
|
|
|
{
|
2021-03-29 00:38:28 +03:00
|
|
|
size_t nr_dirty = atomic_long_read(&c->btree_key_cache.nr_dirty);
|
|
|
|
size_t nr_keys = atomic_long_read(&c->btree_key_cache.nr_keys);
|
2020-11-30 07:55:51 +03:00
|
|
|
size_t max_dirty = 4096 + (nr_keys * 3) / 4;
|
|
|
|
|
2022-01-02 05:22:24 +03:00
|
|
|
return nr_dirty > max_dirty;
|
2020-11-30 07:55:51 +03:00
|
|
|
}
|
|
|
|
|
2021-04-05 05:12:56 +03:00
|
|
|
int bch2_btree_key_cache_journal_flush(struct journal *,
|
|
|
|
struct journal_entry_pin *, u64);
|
|
|
|
|
2020-11-07 19:26:00 +03:00
|
|
|
struct bkey_cached *
|
|
|
|
bch2_btree_key_cache_find(struct bch_fs *, enum btree_id, struct bpos);
|
|
|
|
|
2021-09-10 02:06:29 +03:00
|
|
|
int bch2_btree_path_traverse_cached(struct btree_trans *, struct btree_path *,
|
|
|
|
unsigned);
|
2020-06-14 02:31:45 +03:00
|
|
|
|
2023-02-10 02:34:08 +03:00
|
|
|
bool bch2_btree_insert_key_cached(struct btree_trans *, unsigned,
|
2023-03-14 19:56:38 +03:00
|
|
|
struct btree_insert_entry *);
|
2022-06-06 00:42:24 +03:00
|
|
|
void bch2_btree_key_cache_drop(struct btree_trans *,
|
|
|
|
struct btree_path *);
|
2020-06-14 02:31:45 +03:00
|
|
|
|
|
|
|
void bch2_fs_btree_key_cache_exit(struct btree_key_cache *);
|
|
|
|
void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *);
|
|
|
|
int bch2_fs_btree_key_cache_init(struct btree_key_cache *);
|
|
|
|
|
2020-06-26 21:51:58 +03:00
|
|
|
void bch2_btree_key_cache_to_text(struct printbuf *, struct btree_key_cache *);
|
|
|
|
|
2020-11-30 07:55:51 +03:00
|
|
|
void bch2_btree_key_cache_exit(void);
|
|
|
|
int __init bch2_btree_key_cache_init(void);
|
|
|
|
|
2020-06-14 02:31:45 +03:00
|
|
|
#endif /* _BCACHEFS_BTREE_KEY_CACHE_H */
|