]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
a01fddfba004127d40ec40c9cb811a33fcc5e0c5
[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 #define BCH_WATERMARKS()                \
20         x(btree_copygc)                 \
21         x(btree)                        \
22         x(copygc)                       \
23         x(normal)                       \
24         x(stripe)
25
26 enum bch_watermark {
27 #define x(name) BCH_WATERMARK_##name,
28         BCH_WATERMARKS()
29 #undef x
30         BCH_WATERMARK_NR,
31 };
32
33 #define OPEN_BUCKETS_COUNT      1024
34
35 #define WRITE_POINT_HASH_NR     32
36 #define WRITE_POINT_MAX         32
37
38 /*
39  * 0 is never a valid open_bucket_idx_t:
40  */
41 typedef u16                     open_bucket_idx_t;
42
43 struct open_bucket {
44         spinlock_t              lock;
45         atomic_t                pin;
46         open_bucket_idx_t       freelist;
47         open_bucket_idx_t       hash;
48
49         /*
50          * When an open bucket has an ec_stripe attached, this is the index of
51          * the block in the stripe this open_bucket corresponds to:
52          */
53         u8                      ec_idx;
54         enum bch_data_type      data_type:6;
55         unsigned                valid:1;
56         unsigned                on_partial_list:1;
57
58         u8                      dev;
59         u8                      gen;
60         u32                     sectors_free;
61         u64                     bucket;
62         struct ec_stripe_new    *ec;
63 };
64
65 #define OPEN_BUCKET_LIST_MAX    15
66
67 struct open_buckets {
68         open_bucket_idx_t       nr;
69         open_bucket_idx_t       v[OPEN_BUCKET_LIST_MAX];
70 };
71
72 struct dev_stripe_state {
73         u64                     next_alloc[BCH_SB_MEMBERS_MAX];
74 };
75
76 #define WRITE_POINT_STATES()            \
77         x(stopped)                      \
78         x(waiting_io)                   \
79         x(waiting_work)                 \
80         x(running)
81
82 enum write_point_state {
83 #define x(n)    WRITE_POINT_##n,
84         WRITE_POINT_STATES()
85 #undef x
86         WRITE_POINT_STATE_NR
87 };
88
89 struct write_point {
90         struct {
91                 struct hlist_node       node;
92                 struct mutex            lock;
93                 u64                     last_used;
94                 unsigned long           write_point;
95                 enum bch_data_type      data_type;
96
97                 /* calculated based on how many pointers we're actually going to use: */
98                 unsigned                sectors_free;
99
100                 struct open_buckets     ptrs;
101                 struct dev_stripe_state stripe;
102
103                 u64                     sectors_allocated;
104         } __attribute__((__aligned__(SMP_CACHE_BYTES)));
105
106         struct {
107                 struct work_struct      index_update_work;
108
109                 struct list_head        writes;
110                 spinlock_t              writes_lock;
111
112                 enum write_point_state  state;
113                 u64                     last_state_change;
114                 u64                     time[WRITE_POINT_STATE_NR];
115         } __attribute__((__aligned__(SMP_CACHE_BYTES)));
116 };
117
118 struct write_point_specifier {
119         unsigned long           v;
120 };
121
122 #endif /* _BCACHEFS_ALLOC_TYPES_H */