]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
Update bcachefs sources to 9ceb982d77 bcachefs: Store bucket gens in a btree
[bcachefs-tools-debian] / libbcachefs / alloc_types.h
1 #ifndef _BCACHE_ALLOC_TYPES_H
2 #define _BCACHE_ALLOC_TYPES_H
3
4 #include <linux/mutex.h>
5
6 #include "clock_types.h"
7
8 /*
9  * There's two of these clocks, one for reads and one for writes:
10  *
11  * All fields protected by bucket_lock
12  */
13 struct prio_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                     min_prio;
29
30         int                     rw;
31
32         struct io_timer         rescale;
33 };
34
35 /* There is one reserve for each type of btree, one for prios and gens
36  * and one for moving GC */
37 enum alloc_reserve {
38         RESERVE_ALLOC           = -1,
39         RESERVE_BTREE           = 0,
40         RESERVE_MOVINGGC        = 1,
41         RESERVE_NONE            = 2,
42         RESERVE_NR              = 3,
43 };
44
45 struct dev_group {
46         spinlock_t              lock;
47         unsigned                nr;
48         unsigned                cur_device;
49         struct {
50                 u64             weight;
51                 struct bch_dev  *dev;
52         }                       d[BCH_SB_MEMBERS_MAX];
53 };
54
55 /* Enough for 16 cache devices, 2 tiers and some left over for pipelining */
56 #define OPEN_BUCKETS_COUNT      256
57
58 #define WRITE_POINT_COUNT       16
59
60 struct open_bucket {
61         struct list_head        list;
62         struct mutex            lock;
63         atomic_t                pin;
64         bool                    has_full_ptrs;
65         /*
66          * recalculated every time we allocate from this open_bucket based on
67          * how many pointers we're actually going to use:
68          */
69         unsigned                sectors_free;
70         unsigned                nr_ptrs;
71         struct bch_extent_ptr   ptrs[BCH_REPLICAS_MAX];
72         unsigned                ptr_offset[BCH_REPLICAS_MAX];
73 };
74
75 struct write_point {
76         struct open_bucket      *b;
77
78         /*
79          * Throttle writes to this write point if tier 0 is full?
80          */
81         bool                    throttle;
82
83         /*
84          * If not NULL, cache group for tiering, promotion and moving GC -
85          * always allocates a single replica
86          */
87         struct dev_group        *group;
88
89         /*
90          * Otherwise do a normal replicated bucket allocation that could come
91          * from any device in tier 0 (foreground write)
92          */
93 };
94
95 struct alloc_heap_entry {
96         size_t                  bucket;
97         unsigned long           key;
98 };
99
100 typedef HEAP(struct alloc_heap_entry) alloc_heap;
101
102 #endif /* _BCACHE_ALLOC_TYPES_H */