]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
Merge remote-tracking branch 'holmanb/holmanb/keyutils-dep-check'
[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 ec_bucket_buf;
12
13 #define BCH_ALLOC_RESERVES()            \
14         x(btree_movinggc)               \
15         x(btree)                        \
16         x(movinggc)                     \
17         x(none)
18
19 enum alloc_reserve {
20 #define x(name) RESERVE_##name,
21         BCH_ALLOC_RESERVES()
22 #undef x
23 };
24
25 #define OPEN_BUCKETS_COUNT      1024
26
27 #define WRITE_POINT_HASH_NR     32
28 #define WRITE_POINT_MAX         32
29
30 /*
31  * 0 is never a valid open_bucket_idx_t:
32  */
33 typedef u16                     open_bucket_idx_t;
34
35 struct open_bucket {
36         spinlock_t              lock;
37         atomic_t                pin;
38         open_bucket_idx_t       freelist;
39         open_bucket_idx_t       hash;
40
41         /*
42          * When an open bucket has an ec_stripe attached, this is the index of
43          * the block in the stripe this open_bucket corresponds to:
44          */
45         u8                      ec_idx;
46         enum bch_data_type      data_type:3;
47         unsigned                valid:1;
48         unsigned                on_partial_list:1;
49         int                     alloc_reserve:3;
50
51         unsigned                sectors_free;
52         u8                      dev;
53         u8                      gen;
54         u64                     bucket;
55         struct ec_stripe_new    *ec;
56 };
57
58 #define OPEN_BUCKET_LIST_MAX    15
59
60 struct open_buckets {
61         open_bucket_idx_t       nr;
62         open_bucket_idx_t       v[OPEN_BUCKET_LIST_MAX];
63 };
64
65 struct dev_stripe_state {
66         u64                     next_alloc[BCH_SB_MEMBERS_MAX];
67 };
68
69 struct write_point {
70         struct hlist_node       node;
71         struct mutex            lock;
72         u64                     last_used;
73         unsigned long           write_point;
74         enum bch_data_type      data_type;
75
76         /* calculated based on how many pointers we're actually going to use: */
77         unsigned                sectors_free;
78
79         struct open_buckets     ptrs;
80         struct dev_stripe_state stripe;
81 };
82
83 struct write_point_specifier {
84         unsigned long           v;
85 };
86
87 #endif /* _BCACHEFS_ALLOC_TYPES_H */