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 /* returns true if not equal */
17 static inline bool bkey_alloc_unpacked_cmp(struct bkey_alloc_unpacked l,
18 struct bkey_alloc_unpacked r)
21 #define x(_name, _bits) || l._name != r._name
27 struct bkey_alloc_unpacked bch2_alloc_unpack(struct bkey_s_c);
28 void bch2_alloc_pack(struct bkey_i_alloc *,
29 const struct bkey_alloc_unpacked);
31 static inline struct bkey_alloc_unpacked
32 alloc_mem_to_key(struct bucket *g, struct bucket_mark m)
34 return (struct bkey_alloc_unpacked) {
36 .oldest_gen = g->oldest_gen,
37 .data_type = m.data_type,
38 .dirty_sectors = m.dirty_sectors,
39 .cached_sectors = m.cached_sectors,
40 .read_time = g->io_time[READ],
41 .write_time = g->io_time[WRITE],
45 #define ALLOC_SCAN_BATCH(ca) max_t(size_t, 1, (ca)->mi.nbuckets >> 9)
47 const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);
48 void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
50 #define bch2_bkey_ops_alloc (struct bkey_ops) { \
51 .key_invalid = bch2_alloc_invalid, \
52 .val_to_text = bch2_alloc_to_text, \
56 int bch2_alloc_read(struct bch_fs *, struct journal_keys *);
57 int bch2_alloc_replay_key(struct bch_fs *, struct bkey_i *);
59 static inline void bch2_wake_allocator(struct bch_dev *ca)
61 struct task_struct *p;
64 p = rcu_dereference(ca->alloc_thread);
70 static inline void verify_not_on_freelist(struct bch_fs *c, struct bch_dev *ca,
73 if (expensive_debug_checks(c) &&
74 test_bit(BCH_FS_ALLOCATOR_STARTED, &c->flags)) {
79 for (j = 0; j < RESERVE_NR; j++)
80 fifo_for_each_entry(i, &ca->free[j], iter)
82 fifo_for_each_entry(i, &ca->free_inc, iter)
87 void bch2_recalc_capacity(struct bch_fs *);
89 void bch2_dev_allocator_remove(struct bch_fs *, struct bch_dev *);
90 void bch2_dev_allocator_add(struct bch_fs *, struct bch_dev *);
92 void bch2_dev_allocator_quiesce(struct bch_fs *, struct bch_dev *);
93 void bch2_dev_allocator_stop(struct bch_dev *);
94 int bch2_dev_allocator_start(struct bch_dev *);
96 int bch2_alloc_write(struct bch_fs *, unsigned, bool *);
97 int bch2_fs_allocator_start(struct bch_fs *);
98 void bch2_fs_allocator_background_init(struct bch_fs *);
100 #endif /* _BCACHEFS_ALLOC_BACKGROUND_H */