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 /* How out of date a pointer gen is allowed to be: */
17 #define BUCKET_GC_GEN_MAX 96U
19 /* returns true if not equal */
20 static inline bool bkey_alloc_unpacked_cmp(struct bkey_alloc_unpacked l,
21 struct bkey_alloc_unpacked r)
24 #define x(_name, _bits) || l._name != r._name
30 struct bkey_alloc_unpacked bch2_alloc_unpack(struct bkey_s_c);
31 void bch2_alloc_pack(struct bkey_i_alloc *,
32 const struct bkey_alloc_unpacked);
34 int bch2_bucket_io_time_reset(struct btree_trans *, unsigned, size_t, int);
36 static inline struct bkey_alloc_unpacked
37 alloc_mem_to_key(struct bucket *g, struct bucket_mark m)
39 return (struct bkey_alloc_unpacked) {
41 .oldest_gen = g->oldest_gen,
42 .data_type = m.data_type,
43 .dirty_sectors = m.dirty_sectors,
44 .cached_sectors = m.cached_sectors,
45 .read_time = g->io_time[READ],
46 .write_time = g->io_time[WRITE],
50 #define ALLOC_SCAN_BATCH(ca) max_t(size_t, 1, (ca)->mi.nbuckets >> 9)
52 const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);
53 void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
55 #define bch2_bkey_ops_alloc (struct bkey_ops) { \
56 .key_invalid = bch2_alloc_invalid, \
57 .val_to_text = bch2_alloc_to_text, \
61 int bch2_alloc_read(struct bch_fs *, struct journal_keys *);
63 static inline void bch2_wake_allocator(struct bch_dev *ca)
65 struct task_struct *p;
68 p = rcu_dereference(ca->alloc_thread);
71 ca->allocator_state = ALLOCATOR_RUNNING;
76 static inline void verify_not_on_freelist(struct bch_fs *c, struct bch_dev *ca,
79 if (expensive_debug_checks(c)) {
84 for (j = 0; j < RESERVE_NR; j++)
85 fifo_for_each_entry(i, &ca->free[j], iter)
87 fifo_for_each_entry(i, &ca->free_inc, iter)
92 void bch2_recalc_capacity(struct bch_fs *);
94 void bch2_dev_allocator_remove(struct bch_fs *, struct bch_dev *);
95 void bch2_dev_allocator_add(struct bch_fs *, struct bch_dev *);
97 void bch2_dev_allocator_quiesce(struct bch_fs *, struct bch_dev *);
98 void bch2_dev_allocator_stop(struct bch_dev *);
99 int bch2_dev_allocator_start(struct bch_dev *);
101 int bch2_dev_alloc_write(struct bch_fs *, struct bch_dev *, unsigned);
102 int bch2_alloc_write(struct bch_fs *, unsigned);
103 void bch2_fs_allocator_background_init(struct bch_fs *);
105 #endif /* _BCACHEFS_ALLOC_BACKGROUND_H */