]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/alloc_types.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / libbcache / 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_PRIO,
39         RESERVE_BTREE,
40         RESERVE_METADATA_LAST = RESERVE_BTREE,
41         RESERVE_MOVINGGC,
42
43         RESERVE_NONE,
44         RESERVE_NR,
45 };
46
47 static inline bool allocation_is_metadata(enum alloc_reserve id)
48 {
49         return id <= RESERVE_METADATA_LAST;
50 }
51
52 struct cache_group {
53         spinlock_t              lock;
54         unsigned                nr_devices;
55         unsigned                cur_device;
56         struct {
57                 u64             weight;
58                 struct cache    *dev;
59         }                       d[MAX_CACHES_PER_SET];
60 };
61
62 /* Enough for 16 cache devices, 2 tiers and some left over for pipelining */
63 #define OPEN_BUCKETS_COUNT      256
64
65 #define WRITE_POINT_COUNT       16
66
67 struct open_bucket {
68         struct list_head        list;
69         struct mutex            lock;
70         atomic_t                pin;
71         bool                    has_full_ptrs;
72         /*
73          * recalculated every time we allocate from this open_bucket based on
74          * how many pointers we're actually going to use:
75          */
76         unsigned                sectors_free;
77         unsigned                nr_ptrs;
78         struct bch_extent_ptr   ptrs[BCH_REPLICAS_MAX];
79         unsigned                ptr_offset[BCH_REPLICAS_MAX];
80 };
81
82 struct write_point {
83         struct open_bucket      *b;
84
85         /*
86          * Throttle writes to this write point if tier 0 is full?
87          */
88         bool                    throttle;
89
90         /*
91          * If not NULL, cache group for tiering, promotion and moving GC -
92          * always allocates a single replica
93          */
94         struct cache_group      *group;
95
96         /*
97          * Otherwise do a normal replicated bucket allocation that could come
98          * from any device in tier 0 (foreground write)
99          */
100 };
101
102 #endif /* _BCACHE_ALLOC_TYPES_H */