1 #ifndef _BCACHE_ALLOC_H
2 #define _BCACHE_ALLOC_H
4 #include "alloc_types.h"
12 static inline size_t prios_per_bucket(const struct bch_dev *ca)
14 return (bucket_bytes(ca) - sizeof(struct prio_set)) /
15 sizeof(struct bucket_disk);
18 static inline size_t prio_buckets(const struct bch_dev *ca)
20 return DIV_ROUND_UP((size_t) (ca)->mi.nbuckets, prios_per_bucket(ca));
23 void bch2_dev_group_remove(struct dev_group *, struct bch_dev *);
24 void bch2_dev_group_add(struct dev_group *, struct bch_dev *);
26 int bch2_prio_read(struct bch_dev *);
28 size_t bch2_bucket_alloc(struct bch_dev *, enum alloc_reserve);
30 void bch2_open_bucket_put(struct bch_fs *, struct open_bucket *);
32 struct open_bucket *bch2_alloc_sectors_start(struct bch_fs *,
38 void bch2_alloc_sectors_append_ptrs(struct bch_fs *, struct bkey_i_extent *,
39 unsigned, struct open_bucket *, unsigned);
40 void bch2_alloc_sectors_done(struct bch_fs *, struct write_point *,
41 struct open_bucket *);
43 struct open_bucket *bch2_alloc_sectors(struct bch_fs *, struct write_point *,
44 struct bkey_i_extent *, unsigned, unsigned,
45 enum alloc_reserve, struct closure *);
47 static inline void bch2_wake_allocator(struct bch_dev *ca)
49 struct task_struct *p;
52 if ((p = ACCESS_ONCE(ca->alloc_thread)))
57 static inline struct bch_dev *dev_group_next(struct dev_group *devs,
60 struct bch_dev *ret = NULL;
62 while (*iter < devs->nr &&
63 !(ret = rcu_dereference_check(devs->d[*iter].dev,
64 lockdep_is_held(&devs->lock))))
70 #define group_for_each_dev(ca, devs, iter) \
72 ((ca) = dev_group_next((devs), &(iter))); \
75 #define open_bucket_for_each_ptr(_ob, _ptr) \
76 for ((_ptr) = (_ob)->ptrs; \
77 (_ptr) < (_ob)->ptrs + (_ob)->nr_ptrs; \
80 void bch2_recalc_capacity(struct bch_fs *);
81 void bch2_dev_allocator_stop(struct bch_dev *);
82 int bch2_dev_allocator_start(struct bch_dev *);
83 void bch2_fs_allocator_init(struct bch_fs *);
85 #endif /* _BCACHE_ALLOC_H */