Merge tag 'pinctrl-v6.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[linux-block.git] / fs / bcachefs / alloc_types.h
CommitLineData
1c6fdbd8
KO
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
ae10fe01
KO
11struct bucket_alloc_state {
12 u64 buckets_seen;
13 u64 skipped_open;
14 u64 skipped_need_journal_commit;
a8b3a677 15 u64 skipped_nocow;
ae10fe01
KO
16 u64 skipped_nouse;
17};
18
e53a961c 19#define BCH_WATERMARKS() \
ec14fc60 20 x(stripe) \
e53a961c 21 x(normal) \
ec14fc60
KO
22 x(copygc) \
23 x(btree) \
24 x(btree_copygc) \
e2a316b3
KO
25 x(reclaim) \
26 x(interior_updates)
3e154711 27
e53a961c
KO
28enum bch_watermark {
29#define x(name) BCH_WATERMARK_##name,
30 BCH_WATERMARKS()
3e154711 31#undef x
e53a961c 32 BCH_WATERMARK_NR,
1c6fdbd8
KO
33};
34
ec14fc60 35#define BCH_WATERMARK_BITS 3
bf5a261c 36#define BCH_WATERMARK_MASK ~(~0U << BCH_WATERMARK_BITS)
ec14fc60 37
374153c2 38#define OPEN_BUCKETS_COUNT 1024
b092dadd
KO
39
40#define WRITE_POINT_HASH_NR 32
41#define WRITE_POINT_MAX 32
1c6fdbd8 42
9ddffaf8
KO
43/*
44 * 0 is never a valid open_bucket_idx_t:
45 */
374153c2
KO
46typedef u16 open_bucket_idx_t;
47
1c6fdbd8
KO
48struct open_bucket {
49 spinlock_t lock;
50 atomic_t pin;
374153c2 51 open_bucket_idx_t freelist;
9ddffaf8 52 open_bucket_idx_t hash;
374153c2
KO
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 */
cd575ddf 58 u8 ec_idx;
7635e1a6 59 enum bch_data_type data_type:6;
b030f691
KO
60 unsigned valid:1;
61 unsigned on_partial_list:1;
abe19d45 62
abe19d45
KO
63 u8 dev;
64 u8 gen;
822835ff 65 u32 sectors_free;
abe19d45 66 u64 bucket;
cd575ddf 67 struct ec_stripe_new *ec;
1c6fdbd8
KO
68};
69
ef337c54
KO
70#define OPEN_BUCKET_LIST_MAX 15
71
72struct open_buckets {
374153c2
KO
73 open_bucket_idx_t nr;
74 open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX];
ef337c54
KO
75};
76
cd575ddf
KO
77struct dev_stripe_state {
78 u64 next_alloc[BCH_SB_MEMBERS_MAX];
79};
80
b17d3cec
KO
81#define WRITE_POINT_STATES() \
82 x(stopped) \
83 x(waiting_io) \
84 x(waiting_work) \
85 x(running)
86
87enum write_point_state {
88#define x(n) WRITE_POINT_##n,
89 WRITE_POINT_STATES()
90#undef x
91 WRITE_POINT_STATE_NR
92};
93
1c6fdbd8 94struct write_point {
b17d3cec
KO
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;
1c6fdbd8 101
b17d3cec
KO
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;
1e81f89b 109 } __aligned(SMP_CACHE_BYTES);
b17d3cec
KO
110
111 struct {
112 struct work_struct index_update_work;
113
114 struct list_head writes;
115 spinlock_t writes_lock;
1c6fdbd8 116
b17d3cec
KO
117 enum write_point_state state;
118 u64 last_state_change;
119 u64 time[WRITE_POINT_STATE_NR];
1e81f89b 120 } __aligned(SMP_CACHE_BYTES);
1c6fdbd8
KO
121};
122
123struct write_point_specifier {
124 unsigned long v;
125};
126
1c6fdbd8 127#endif /* _BCACHEFS_ALLOC_TYPES_H */