]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
6f17f094c21e47f6547d61fed45097c0f766649e
[bcachefs-tools-debian] / libbcachefs / alloc_types.h
1 #ifndef _BCACHEFS_ALLOC_TYPES_H
2 #define _BCACHEFS_ALLOC_TYPES_H
3
4 #include <linux/mutex.h>
5 #include <linux/spinlock.h>
6
7 #include "clock_types.h"
8 #include "fifo.h"
9
10 struct ec_bucket_buf;
11
12 /* There's two of these clocks, one for reads and one for writes: */
13 struct bucket_clock {
14         /*
15          * "now" in (read/write) IO time - incremented whenever we do X amount
16          * of reads or writes.
17          *
18          * Goes with the bucket read/write prios: when we read or write to a
19          * bucket we reset the bucket's prio to the current hand; thus hand -
20          * prio = time since bucket was last read/written.
21          *
22          * The units are some amount (bytes/sectors) of data read/written, and
23          * the units can change on the fly if we need to rescale to fit
24          * everything in a u16 - your only guarantee is that the units are
25          * consistent.
26          */
27         u16                     hand;
28         u16                     max_last_io;
29
30         int                     rw;
31
32         struct io_timer         rescale;
33         struct mutex            lock;
34 };
35
36 /* There is one reserve for each type of btree, one for prios and gens
37  * and one for moving GC */
38 enum alloc_reserve {
39         RESERVE_ALLOC           = -1,
40         RESERVE_BTREE           = 0,
41         RESERVE_MOVINGGC        = 1,
42         RESERVE_NONE            = 2,
43         RESERVE_NR              = 3,
44 };
45
46 typedef FIFO(long)      alloc_fifo;
47
48 /* Enough for 16 cache devices, 2 tiers and some left over for pipelining */
49 #define OPEN_BUCKETS_COUNT      256
50
51 #define WRITE_POINT_HASH_NR     32
52 #define WRITE_POINT_MAX         32
53
54 struct open_bucket {
55         spinlock_t              lock;
56         atomic_t                pin;
57         u8                      freelist;
58         bool                    valid;
59         bool                    on_partial_list;
60         u8                      ec_idx;
61         unsigned                sectors_free;
62         struct bch_extent_ptr   ptr;
63         struct ec_stripe_new    *ec;
64 };
65
66 #define OPEN_BUCKET_LIST_MAX    15
67
68 struct open_buckets {
69         u8                      nr;
70         u8                      v[OPEN_BUCKET_LIST_MAX];
71 };
72
73 struct dev_stripe_state {
74         u64                     next_alloc[BCH_SB_MEMBERS_MAX];
75 };
76
77 struct write_point {
78         struct hlist_node       node;
79         struct mutex            lock;
80         u64                     last_used;
81         unsigned long           write_point;
82         enum bch_data_type      type;
83         bool                    is_ec;
84
85         /* calculated based on how many pointers we're actually going to use: */
86         unsigned                sectors_free;
87
88         struct open_buckets     ptrs;
89         struct dev_stripe_state stripe;
90 };
91
92 struct write_point_specifier {
93         unsigned long           v;
94 };
95
96 struct alloc_heap_entry {
97         size_t                  bucket;
98         size_t                  nr;
99         unsigned long           key;
100 };
101
102 typedef HEAP(struct alloc_heap_entry) alloc_heap;
103
104 #endif /* _BCACHEFS_ALLOC_TYPES_H */