1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_ALLOC_TYPES_H
3 #define _BCACHEFS_ALLOC_TYPES_H
5 #include <linux/mutex.h>
6 #include <linux/spinlock.h>
8 #include "clock_types.h"
13 /* There's two of these clocks, one for reads and one for writes: */
16 * "now" in (read/write) IO time - incremented whenever we do X amount
19 * Goes with the bucket read/write prios: when we read or write to a
20 * bucket we reset the bucket's prio to the current hand; thus hand -
21 * prio = time since bucket was last read/written.
23 * The units are some amount (bytes/sectors) of data read/written, and
24 * the units can change on the fly if we need to rescale to fit
25 * everything in a u16 - your only guarantee is that the units are
33 struct io_timer rescale;
37 /* There is one reserve for each type of btree, one for prios and gens
38 * and one for moving GC */
47 typedef FIFO(long) alloc_fifo;
49 #define OPEN_BUCKETS_COUNT 1024
51 #define WRITE_POINT_HASH_NR 32
52 #define WRITE_POINT_MAX 32
54 typedef u16 open_bucket_idx_t;
59 open_bucket_idx_t freelist;
62 * When an open bucket has an ec_stripe attached, this is the index of
63 * the block in the stripe this open_bucket corresponds to:
68 unsigned on_partial_list:1;
70 unsigned sectors_free;
71 struct bch_extent_ptr ptr;
72 struct ec_stripe_new *ec;
75 #define OPEN_BUCKET_LIST_MAX 15
79 open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX];
82 struct dev_stripe_state {
83 u64 next_alloc[BCH_SB_MEMBERS_MAX];
87 struct hlist_node node;
90 unsigned long write_point;
91 enum bch_data_type type;
94 /* calculated based on how many pointers we're actually going to use: */
95 unsigned sectors_free;
97 struct open_buckets ptrs;
98 struct dev_stripe_state stripe;
101 struct write_point_specifier {
105 struct alloc_heap_entry {
111 typedef HEAP(struct alloc_heap_entry) alloc_heap;
113 #endif /* _BCACHEFS_ALLOC_TYPES_H */