]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/buckets_types.h
Update bcachefs sources to 078a1a596a bcachefs: Optimize bucket reuse
[bcachefs-tools-debian] / libbcachefs / buckets_types.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BUCKETS_TYPES_H
3 #define _BUCKETS_TYPES_H
4
5 #include "bcachefs_format.h"
6 #include "util.h"
7
8 #define BUCKET_JOURNAL_SEQ_BITS         16
9
10 struct bucket_mark {
11         union {
12         atomic64_t      v;
13
14         struct {
15         u8              gen;
16         u8              data_type:3,
17                         owned_by_allocator:1,
18                         journal_seq_valid:1,
19                         stripe:1;
20         u16             dirty_sectors;
21         u16             cached_sectors;
22
23         /*
24          * low bits of journal sequence number when this bucket was most
25          * recently modified: if journal_seq_valid is set, this bucket can't be
26          * reused until the journal sequence number written to disk is >= the
27          * bucket's journal sequence number:
28          */
29         u16             journal_seq;
30         };
31         };
32 };
33
34 struct bucket {
35         union {
36                 struct bucket_mark      _mark;
37                 const struct bucket_mark mark;
38         };
39
40         u64                             io_time[2];
41         u8                              oldest_gen;
42         u8                              gc_gen;
43         unsigned                        gen_valid:1;
44         u8                              stripe_redundancy;
45         u32                             stripe;
46 };
47
48 struct bucket_array {
49         struct rcu_head         rcu;
50         u16                     first_bucket;
51         size_t                  nbuckets;
52         struct bucket           b[];
53 };
54
55 struct bucket_gens {
56         struct rcu_head         rcu;
57         u16                     first_bucket;
58         size_t                  nbuckets;
59         u8                      b[];
60 };
61
62 struct bch_dev_usage {
63         u64                     buckets_ec;
64         u64                     buckets_unavailable;
65
66         struct {
67                 u64             buckets;
68                 u64             sectors; /* _compressed_ sectors: */
69                 /*
70                  * XXX
71                  * Why do we have this? Isn't it just buckets * bucket_size -
72                  * sectors?
73                  */
74                 u64             fragmented;
75         }                       d[BCH_DATA_NR];
76 };
77
78 struct bch_fs_usage {
79         /* all fields are in units of 512 byte sectors: */
80         u64                     hidden;
81         u64                     btree;
82         u64                     data;
83         u64                     cached;
84         u64                     reserved;
85         u64                     nr_inodes;
86
87         /* XXX: add stats for compression ratio */
88 #if 0
89         u64                     uncompressed;
90         u64                     compressed;
91 #endif
92
93         /* broken out: */
94
95         u64                     persistent_reserved[BCH_REPLICAS_MAX];
96         u64                     replicas[];
97 };
98
99 struct bch_fs_usage_online {
100         u64                     online_reserved;
101         struct bch_fs_usage     u;
102 };
103
104 struct bch_fs_usage_short {
105         u64                     capacity;
106         u64                     used;
107         u64                     free;
108         u64                     nr_inodes;
109 };
110
111 /*
112  * A reservation for space on disk:
113  */
114 struct disk_reservation {
115         u64                     sectors;
116         u32                     gen;
117         unsigned                nr_replicas;
118 };
119
120 struct copygc_heap_entry {
121         u8                      dev;
122         u8                      gen;
123         u8                      replicas;
124         u16                     fragmentation;
125         u32                     sectors;
126         u64                     offset;
127 };
128
129 typedef HEAP(struct copygc_heap_entry) copygc_heap;
130
131 #endif /* _BUCKETS_TYPES_H */