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