]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
e66a85f7a9a3d954cdac1d32a793e2fd380613d0
[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     cur_bucket;
13         u64     buckets_seen;
14         u64     skipped_open;
15         u64     skipped_need_journal_commit;
16         u64     skipped_nouse;
17 };
18
19 struct ec_bucket_buf;
20
21 #define BCH_ALLOC_RESERVES()            \
22         x(btree_movinggc)               \
23         x(btree)                        \
24         x(movinggc)                     \
25         x(none)
26
27 enum alloc_reserve {
28 #define x(name) RESERVE_##name,
29         BCH_ALLOC_RESERVES()
30 #undef x
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:8;
55         unsigned                valid:1;
56         unsigned                on_partial_list:1;
57         unsigned                alloc_reserve:3;
58
59         u8                      dev;
60         u8                      gen;
61         u32                     sectors_free;
62         u64                     bucket;
63         struct ec_stripe_new    *ec;
64 };
65
66 #define OPEN_BUCKET_LIST_MAX    15
67
68 struct open_buckets {
69         open_bucket_idx_t       nr;
70         open_bucket_idx_t       v[OPEN_BUCKET_LIST_MAX];
71 };
72
73 struct dev_stripe_state {
74         u64                     next_alloc[BCH_SB_MEMBERS_MAX];
75 };
76
77 struct write_point {
78         struct hlist_node       node;
79         struct mutex            lock;
80         u64                     last_used;
81         unsigned long           write_point;
82         enum bch_data_type      data_type;
83
84         /* calculated based on how many pointers we're actually going to use: */
85         unsigned                sectors_free;
86
87         struct open_buckets     ptrs;
88         struct dev_stripe_state stripe;
89
90         struct work_struct      index_update_work;
91
92         struct list_head        writes;
93         spinlock_t              writes_lock;
94 };
95
96 struct write_point_specifier {
97         unsigned long           v;
98 };
99
100 #endif /* _BCACHEFS_ALLOC_TYPES_H */