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;
69 unsigned sectors_free;
70 struct bch_extent_ptr ptr;
71 struct ec_stripe_new *ec;
74 #define OPEN_BUCKET_LIST_MAX 15
78 open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX];
81 struct dev_stripe_state {
82 u64 next_alloc[BCH_SB_MEMBERS_MAX];
86 struct hlist_node node;
89 unsigned long write_point;
90 enum bch_data_type type;
93 /* calculated based on how many pointers we're actually going to use: */
94 unsigned sectors_free;
96 struct open_buckets ptrs;
97 struct dev_stripe_state stripe;
100 struct write_point_specifier {
104 struct alloc_heap_entry {
110 typedef HEAP(struct alloc_heap_entry) alloc_heap;
112 #endif /* _BCACHEFS_ALLOC_TYPES_H */