blob: 9bbb28e90b934fa27618537e85c901e0bf8efbda [file] [log] [blame]
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -08001/* 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
Kent Overstreetae10fe02022-11-04 16:06:55 -040011struct bucket_alloc_state {
Kent Overstreetc6705092024-04-20 16:25:34 -040012 enum {
13 BTREE_BITMAP_NO,
14 BTREE_BITMAP_YES,
15 BTREE_BITMAP_ANY,
16 } btree_bitmap;
17
Kent Overstreetae10fe02022-11-04 16:06:55 -040018 u64 buckets_seen;
19 u64 skipped_open;
20 u64 skipped_need_journal_commit;
Kent Overstreeta8b3a672022-11-02 17:12:00 -040021 u64 skipped_nocow;
Kent Overstreetae10fe02022-11-04 16:06:55 -040022 u64 skipped_nouse;
Kent Overstreetc6705092024-04-20 16:25:34 -040023 u64 skipped_mi_btree_bitmap;
Kent Overstreetae10fe02022-11-04 16:06:55 -040024};
25
Kent Overstreete53a9612023-06-24 19:30:10 -040026#define BCH_WATERMARKS() \
Kent Overstreetec14fc62023-06-27 17:32:38 -040027 x(stripe) \
Kent Overstreete53a9612023-06-24 19:30:10 -040028 x(normal) \
Kent Overstreetec14fc62023-06-27 17:32:38 -040029 x(copygc) \
30 x(btree) \
31 x(btree_copygc) \
Kent Overstreete2a316b2024-04-01 19:20:36 -040032 x(reclaim) \
33 x(interior_updates)
Kent Overstreet3e154712022-03-13 19:27:55 -040034
Kent Overstreete53a9612023-06-24 19:30:10 -040035enum bch_watermark {
36#define x(name) BCH_WATERMARK_##name,
37 BCH_WATERMARKS()
Kent Overstreet3e154712022-03-13 19:27:55 -040038#undef x
Kent Overstreete53a9612023-06-24 19:30:10 -040039 BCH_WATERMARK_NR,
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -080040};
41
Kent Overstreetec14fc62023-06-27 17:32:38 -040042#define BCH_WATERMARK_BITS 3
Kent Overstreetbf5a2612023-08-01 20:06:45 -040043#define BCH_WATERMARK_MASK ~(~0U << BCH_WATERMARK_BITS)
Kent Overstreetec14fc62023-06-27 17:32:38 -040044
Kent Overstreet374153c2020-06-09 15:44:03 -040045#define OPEN_BUCKETS_COUNT 1024
Kent Overstreetb092dad2018-11-04 21:55:35 -050046
47#define WRITE_POINT_HASH_NR 32
48#define WRITE_POINT_MAX 32
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -080049
Kent Overstreet9ddffaf2021-12-25 21:43:29 -050050/*
51 * 0 is never a valid open_bucket_idx_t:
52 */
Kent Overstreet374153c2020-06-09 15:44:03 -040053typedef u16 open_bucket_idx_t;
54
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -080055struct open_bucket {
56 spinlock_t lock;
57 atomic_t pin;
Kent Overstreet374153c2020-06-09 15:44:03 -040058 open_bucket_idx_t freelist;
Kent Overstreet9ddffaf2021-12-25 21:43:29 -050059 open_bucket_idx_t hash;
Kent Overstreet374153c2020-06-09 15:44:03 -040060
61 /*
62 * When an open bucket has an ec_stripe attached, this is the index of
63 * the block in the stripe this open_bucket corresponds to:
64 */
Kent Overstreetcd575dd2018-11-01 15:13:19 -040065 u8 ec_idx;
Kent Overstreet7635e1a2023-02-25 02:22:49 -050066 enum bch_data_type data_type:6;
Kent Overstreetb030f692019-01-19 13:13:29 -050067 unsigned valid:1;
68 unsigned on_partial_list:1;
Kent Overstreetabe19d42021-12-25 21:21:46 -050069
Kent Overstreetabe19d42021-12-25 21:21:46 -050070 u8 dev;
71 u8 gen;
Kent Overstreet822835f2022-04-01 01:29:59 -040072 u32 sectors_free;
Kent Overstreetabe19d42021-12-25 21:21:46 -050073 u64 bucket;
Kent Overstreetcd575dd2018-11-01 15:13:19 -040074 struct ec_stripe_new *ec;
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -080075};
76
Kent Overstreetef337c52018-10-06 04:12:42 -040077#define OPEN_BUCKET_LIST_MAX 15
78
79struct open_buckets {
Kent Overstreet374153c2020-06-09 15:44:03 -040080 open_bucket_idx_t nr;
81 open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX];
Kent Overstreetef337c52018-10-06 04:12:42 -040082};
83
Kent Overstreetcd575dd2018-11-01 15:13:19 -040084struct dev_stripe_state {
85 u64 next_alloc[BCH_SB_MEMBERS_MAX];
86};
87
Kent Overstreetb17d3ce2022-10-31 16:13:05 -040088#define WRITE_POINT_STATES() \
89 x(stopped) \
90 x(waiting_io) \
91 x(waiting_work) \
92 x(running)
93
94enum write_point_state {
95#define x(n) WRITE_POINT_##n,
96 WRITE_POINT_STATES()
97#undef x
98 WRITE_POINT_STATE_NR
99};
100
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -0800101struct write_point {
Kent Overstreetb17d3ce2022-10-31 16:13:05 -0400102 struct {
103 struct hlist_node node;
104 struct mutex lock;
105 u64 last_used;
106 unsigned long write_point;
107 enum bch_data_type data_type;
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -0800108
Kent Overstreetb17d3ce2022-10-31 16:13:05 -0400109 /* calculated based on how many pointers we're actually going to use: */
110 unsigned sectors_free;
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -0800111
Kent Overstreetb17d3ce2022-10-31 16:13:05 -0400112 struct open_buckets ptrs;
113 struct dev_stripe_state stripe;
114
115 u64 sectors_allocated;
Kent Overstreet1e81f892023-08-07 12:04:05 -0400116 } __aligned(SMP_CACHE_BYTES);
Kent Overstreetb17d3ce2022-10-31 16:13:05 -0400117
118 struct {
119 struct work_struct index_update_work;
120
121 struct list_head writes;
122 spinlock_t writes_lock;
123
124 enum write_point_state state;
125 u64 last_state_change;
126 u64 time[WRITE_POINT_STATE_NR];
Kent Overstreet1e81f892023-08-07 12:04:05 -0400127 } __aligned(SMP_CACHE_BYTES);
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -0800128};
129
130struct write_point_specifier {
131 unsigned long v;
132};
133
Kent Overstreet1c6fdbd2017-03-16 22:18:50 -0800134#endif /* _BCACHEFS_ALLOC_TYPES_H */