Linux 6.13-rc4
[linux.git] / fs / bcachefs / alloc_types.h
blob9bbb28e90b934fa27618537e85c901e0bf8efbda
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_ALLOC_TYPES_H
3 #define _BCACHEFS_ALLOC_TYPES_H
5 #include <linux/mutex.h>
6 #include <linux/spinlock.h>
8 #include "clock_types.h"
9 #include "fifo.h"
11 struct bucket_alloc_state {
12 enum {
13 BTREE_BITMAP_NO,
14 BTREE_BITMAP_YES,
15 BTREE_BITMAP_ANY,
16 } btree_bitmap;
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;
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)
35 enum bch_watermark {
36 #define x(name) BCH_WATERMARK_##name,
37 BCH_WATERMARKS()
38 #undef x
39 BCH_WATERMARK_NR,
42 #define BCH_WATERMARK_BITS 3
43 #define BCH_WATERMARK_MASK ~(~0U << BCH_WATERMARK_BITS)
45 #define OPEN_BUCKETS_COUNT 1024
47 #define WRITE_POINT_HASH_NR 32
48 #define WRITE_POINT_MAX 32
51 * 0 is never a valid open_bucket_idx_t:
53 typedef u16 open_bucket_idx_t;
55 struct open_bucket {
56 spinlock_t lock;
57 atomic_t pin;
58 open_bucket_idx_t freelist;
59 open_bucket_idx_t hash;
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:
65 u8 ec_idx;
66 enum bch_data_type data_type:6;
67 unsigned valid:1;
68 unsigned on_partial_list:1;
70 u8 dev;
71 u8 gen;
72 u32 sectors_free;
73 u64 bucket;
74 struct ec_stripe_new *ec;
77 #define OPEN_BUCKET_LIST_MAX 15
79 struct open_buckets {
80 open_bucket_idx_t nr;
81 open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX];
84 struct dev_stripe_state {
85 u64 next_alloc[BCH_SB_MEMBERS_MAX];
88 #define WRITE_POINT_STATES() \
89 x(stopped) \
90 x(waiting_io) \
91 x(waiting_work) \
92 x(running)
94 enum write_point_state {
95 #define x(n) WRITE_POINT_##n,
96 WRITE_POINT_STATES()
97 #undef x
98 WRITE_POINT_STATE_NR
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;
109 /* calculated based on how many pointers we're actually going to use: */
110 unsigned sectors_free;
112 struct open_buckets ptrs;
113 struct dev_stripe_state stripe;
115 u64 sectors_allocated;
116 } __aligned(SMP_CACHE_BYTES);
118 struct {
119 struct work_struct index_update_work;
121 struct list_head writes;
122 spinlock_t writes_lock;
124 enum write_point_state state;
125 u64 last_state_change;
126 u64 time[WRITE_POINT_STATE_NR];
127 } __aligned(SMP_CACHE_BYTES);
130 struct write_point_specifier {
131 unsigned long v;
134 #endif /* _BCACHEFS_ALLOC_TYPES_H */