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