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