1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_ALLOC_BACKGROUND_H
3 #define _BCACHEFS_ALLOC_BACKGROUND_H
6 #include "alloc_types.h"
9 struct bkey_alloc_unpacked {
11 #define x(_name, _bits) u##_bits _name;
16 struct bkey_alloc_unpacked bch2_alloc_unpack(struct bkey_s_c);
17 void bch2_alloc_pack(struct bkey_i_alloc *,
18 const struct bkey_alloc_unpacked);
20 #define ALLOC_SCAN_BATCH(ca) max_t(size_t, 1, (ca)->mi.nbuckets >> 9)
22 const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);
23 void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
25 #define bch2_bkey_ops_alloc (struct bkey_ops) { \
26 .key_invalid = bch2_alloc_invalid, \
27 .val_to_text = bch2_alloc_to_text, \
31 int bch2_alloc_read(struct bch_fs *, struct journal_keys *);
32 int bch2_alloc_replay_key(struct bch_fs *, struct bkey_i *);
34 static inline void bch2_wake_allocator(struct bch_dev *ca)
36 struct task_struct *p;
39 p = rcu_dereference(ca->alloc_thread);
45 static inline void verify_not_on_freelist(struct bch_fs *c, struct bch_dev *ca,
48 if (expensive_debug_checks(c) &&
49 test_bit(BCH_FS_ALLOCATOR_STARTED, &c->flags)) {
54 for (j = 0; j < RESERVE_NR; j++)
55 fifo_for_each_entry(i, &ca->free[j], iter)
57 fifo_for_each_entry(i, &ca->free_inc, iter)
62 void bch2_recalc_capacity(struct bch_fs *);
64 void bch2_dev_allocator_remove(struct bch_fs *, struct bch_dev *);
65 void bch2_dev_allocator_add(struct bch_fs *, struct bch_dev *);
67 void bch2_dev_allocator_quiesce(struct bch_fs *, struct bch_dev *);
68 void bch2_dev_allocator_stop(struct bch_dev *);
69 int bch2_dev_allocator_start(struct bch_dev *);
71 int bch2_alloc_write(struct bch_fs *, unsigned, bool *);
72 int bch2_fs_allocator_start(struct bch_fs *);
73 void bch2_fs_allocator_background_init(struct bch_fs *);
75 #endif /* _BCACHEFS_ALLOC_BACKGROUND_H */