]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
Update bcachefs sources to 259ff91605 bcachefs: Don't keep around btree_paths unneces...
[bcachefs-tools-debian] / libbcachefs / alloc_types.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_ALLOC_TYPES_H
3 #define _BCACHEFS_ALLOC_TYPES_H
4
5 #include <linux/mutex.h>
6 #include <linux/spinlock.h>
7
8 #include "clock_types.h"
9 #include "fifo.h"
10
11 struct ec_bucket_buf;
12
13 #define ALLOC_THREAD_STATES()           \
14         x(stopped)                      \
15         x(running)                      \
16         x(blocked)                      \
17         x(blocked_full)
18
19 enum allocator_states {
20 #define x(n)    ALLOCATOR_##n,
21         ALLOC_THREAD_STATES()
22 #undef x
23 };
24
25 enum alloc_reserve {
26         RESERVE_BTREE_MOVINGGC  = -2,
27         RESERVE_BTREE           = -1,
28         RESERVE_MOVINGGC        = 0,
29         RESERVE_NONE            = 1,
30         RESERVE_NR              = 2,
31 };
32
33 typedef FIFO(long)      alloc_fifo;
34
35 #define OPEN_BUCKETS_COUNT      1024
36
37 #define WRITE_POINT_HASH_NR     32
38 #define WRITE_POINT_MAX         32
39
40 /*
41  * 0 is never a valid open_bucket_idx_t:
42  */
43 typedef u16                     open_bucket_idx_t;
44
45 struct open_bucket {
46         spinlock_t              lock;
47         atomic_t                pin;
48         open_bucket_idx_t       freelist;
49         open_bucket_idx_t       hash;
50
51         /*
52          * When an open bucket has an ec_stripe attached, this is the index of
53          * the block in the stripe this open_bucket corresponds to:
54          */
55         u8                      ec_idx;
56         enum bch_data_type      data_type:3;
57         unsigned                valid:1;
58         unsigned                on_partial_list:1;
59         int                     alloc_reserve:3;
60
61         unsigned                sectors_free;
62         u8                      dev;
63         u8                      gen;
64         u64                     bucket;
65         struct ec_stripe_new    *ec;
66 };
67
68 #define OPEN_BUCKET_LIST_MAX    15
69
70 struct open_buckets {
71         open_bucket_idx_t       nr;
72         open_bucket_idx_t       v[OPEN_BUCKET_LIST_MAX];
73 };
74
75 struct dev_stripe_state {
76         u64                     next_alloc[BCH_SB_MEMBERS_MAX];
77 };
78
79 struct write_point {
80         struct hlist_node       node;
81         struct mutex            lock;
82         u64                     last_used;
83         unsigned long           write_point;
84         enum bch_data_type      data_type;
85
86         /* calculated based on how many pointers we're actually going to use: */
87         unsigned                sectors_free;
88
89         struct open_buckets     ptrs;
90         struct dev_stripe_state stripe;
91 };
92
93 struct write_point_specifier {
94         unsigned long           v;
95 };
96
97 struct alloc_heap_entry {
98         size_t                  bucket;
99         size_t                  nr;
100         unsigned long           key;
101 };
102
103 typedef HEAP(struct alloc_heap_entry) alloc_heap;
104
105 #endif /* _BCACHEFS_ALLOC_TYPES_H */