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