]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_types.h
Update bcachefs sources to c7defb5793 bcachefs: Split btree_iter_traverse and bch2_bt...
[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 enum alloc_reserve {
14         RESERVE_BTREE_MOVINGGC  = -2,
15         RESERVE_BTREE           = -1,
16         RESERVE_MOVINGGC        = 0,
17         RESERVE_NONE            = 1,
18         RESERVE_NR              = 2,
19 };
20
21 typedef FIFO(long)      alloc_fifo;
22
23 #define OPEN_BUCKETS_COUNT      1024
24
25 #define WRITE_POINT_HASH_NR     32
26 #define WRITE_POINT_MAX         32
27
28 typedef u16                     open_bucket_idx_t;
29
30 struct open_bucket {
31         spinlock_t              lock;
32         atomic_t                pin;
33         open_bucket_idx_t       freelist;
34
35         /*
36          * When an open bucket has an ec_stripe attached, this is the index of
37          * the block in the stripe this open_bucket corresponds to:
38          */
39         u8                      ec_idx;
40         u8                      type;
41         unsigned                valid:1;
42         unsigned                on_partial_list:1;
43         int                     alloc_reserve:3;
44         unsigned                sectors_free;
45         struct bch_extent_ptr   ptr;
46         struct ec_stripe_new    *ec;
47 };
48
49 #define OPEN_BUCKET_LIST_MAX    15
50
51 struct open_buckets {
52         open_bucket_idx_t       nr;
53         open_bucket_idx_t       v[OPEN_BUCKET_LIST_MAX];
54 };
55
56 struct dev_stripe_state {
57         u64                     next_alloc[BCH_SB_MEMBERS_MAX];
58 };
59
60 struct write_point {
61         struct hlist_node       node;
62         struct mutex            lock;
63         u64                     last_used;
64         unsigned long           write_point;
65         enum bch_data_type      type;
66
67         /* calculated based on how many pointers we're actually going to use: */
68         unsigned                sectors_free;
69
70         struct open_buckets     ptrs;
71         struct dev_stripe_state stripe;
72 };
73
74 struct write_point_specifier {
75         unsigned long           v;
76 };
77
78 struct alloc_heap_entry {
79         size_t                  bucket;
80         size_t                  nr;
81         unsigned long           key;
82 };
83
84 typedef HEAP(struct alloc_heap_entry) alloc_heap;
85
86 #endif /* _BCACHEFS_ALLOC_TYPES_H */