]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
Update bcachefs sources to fd381c355c bcachefs: Fix a null ptr deref in fsck check_ex...
[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 bucket_alloc_state {
12         u64     buckets_seen;
13         u64     skipped_open;
14         u64     skipped_need_journal_commit;
15         u64     skipped_nocow;
16         u64     skipped_nouse;
17 };
18
19 struct ec_bucket_buf;
20
21 #define BCH_ALLOC_RESERVES()            \
22         x(btree_movinggc)               \
23         x(btree)                        \
24         x(movinggc)                     \
25         x(none)                         \
26         x(stripe)
27
28 enum alloc_reserve {
29 #define x(name) RESERVE_##name,
30         BCH_ALLOC_RESERVES()
31 #undef x
32         RESERVE_NR,
33 };
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:6;
57         unsigned                valid:1;
58         unsigned                on_partial_list:1;
59
60         u8                      dev;
61         u8                      gen;
62         u32                     sectors_free;
63         u64                     bucket;
64         struct ec_stripe_new    *ec;
65 };
66
67 #define OPEN_BUCKET_LIST_MAX    15
68
69 struct open_buckets {
70         open_bucket_idx_t       nr;
71         open_bucket_idx_t       v[OPEN_BUCKET_LIST_MAX];
72 };
73
74 struct dev_stripe_state {
75         u64                     next_alloc[BCH_SB_MEMBERS_MAX];
76 };
77
78 #define WRITE_POINT_STATES()            \
79         x(stopped)                      \
80         x(waiting_io)                   \
81         x(waiting_work)                 \
82         x(running)
83
84 enum write_point_state {
85 #define x(n)    WRITE_POINT_##n,
86         WRITE_POINT_STATES()
87 #undef x
88         WRITE_POINT_STATE_NR
89 };
90
91 struct write_point {
92         struct {
93                 struct hlist_node       node;
94                 struct mutex            lock;
95                 u64                     last_used;
96                 unsigned long           write_point;
97                 enum bch_data_type      data_type;
98
99                 /* calculated based on how many pointers we're actually going to use: */
100                 unsigned                sectors_free;
101
102                 struct open_buckets     ptrs;
103                 struct dev_stripe_state stripe;
104
105                 u64                     sectors_allocated;
106         } __attribute__((__aligned__(SMP_CACHE_BYTES)));
107
108         struct {
109                 struct work_struct      index_update_work;
110
111                 struct list_head        writes;
112                 spinlock_t              writes_lock;
113
114                 enum write_point_state  state;
115                 u64                     last_state_change;
116                 u64                     time[WRITE_POINT_STATE_NR];
117         } __attribute__((__aligned__(SMP_CACHE_BYTES)));
118 };
119
120 struct write_point_specifier {
121         unsigned long           v;
122 };
123
124 #endif /* _BCACHEFS_ALLOC_TYPES_H */