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 bucket_alloc_state { 12 enum { 13 BTREE_BITMAP_NO, 14 BTREE_BITMAP_YES, 15 BTREE_BITMAP_ANY, 16 } btree_bitmap; 17 18 u64 buckets_seen; 19 u64 skipped_open; 20 u64 skipped_need_journal_commit; 21 u64 need_journal_commit; 22 u64 skipped_nocow; 23 u64 skipped_nouse; 24 u64 skipped_mi_btree_bitmap; 25 }; 26 27 #define BCH_WATERMARKS() \ 28 x(stripe) \ 29 x(normal) \ 30 x(copygc) \ 31 x(btree) \ 32 x(btree_copygc) \ 33 x(reclaim) \ 34 x(interior_updates) 35 36 enum bch_watermark { 37 #define x(name) BCH_WATERMARK_##name, 38 BCH_WATERMARKS() 39 #undef x 40 BCH_WATERMARK_NR, 41 }; 42 43 #define BCH_WATERMARK_BITS 3 44 #define BCH_WATERMARK_MASK ~(~0U << BCH_WATERMARK_BITS) 45 46 #define OPEN_BUCKETS_COUNT 1024 47 48 #define WRITE_POINT_HASH_NR 32 49 #define WRITE_POINT_MAX 32 50 51 /* 52 * 0 is never a valid open_bucket_idx_t: 53 */ 54 typedef u16 open_bucket_idx_t; 55 56 struct open_bucket { 57 spinlock_t lock; 58 atomic_t pin; 59 open_bucket_idx_t freelist; 60 open_bucket_idx_t hash; 61 62 /* 63 * When an open bucket has an ec_stripe attached, this is the index of 64 * the block in the stripe this open_bucket corresponds to: 65 */ 66 u8 ec_idx; 67 enum bch_data_type data_type:6; 68 unsigned valid:1; 69 unsigned on_partial_list:1; 70 71 u8 dev; 72 u8 gen; 73 u32 sectors_free; 74 u64 bucket; 75 struct ec_stripe_new *ec; 76 }; 77 78 #define OPEN_BUCKET_LIST_MAX 15 79 80 struct open_buckets { 81 open_bucket_idx_t nr; 82 open_bucket_idx_t v[OPEN_BUCKET_LIST_MAX]; 83 }; 84 85 struct dev_stripe_state { 86 u64 next_alloc[BCH_SB_MEMBERS_MAX]; 87 }; 88 89 #define WRITE_POINT_STATES() \ 90 x(stopped) \ 91 x(waiting_io) \ 92 x(waiting_work) \ 93 x(runnable) \ 94 x(running) 95 96 enum write_point_state { 97 #define x(n) WRITE_POINT_##n, 98 WRITE_POINT_STATES() 99 #undef x 100 WRITE_POINT_STATE_NR 101 }; 102 103 struct write_point { 104 struct { 105 struct hlist_node node; 106 struct mutex lock; 107 u64 last_used; 108 unsigned long write_point; 109 enum bch_data_type data_type; 110 111 /* calculated based on how many pointers we're actually going to use: */ 112 unsigned sectors_free; 113 114 struct open_buckets ptrs; 115 struct dev_stripe_state stripe; 116 117 u64 sectors_allocated; 118 } __aligned(SMP_CACHE_BYTES); 119 120 struct { 121 struct work_struct index_update_work; 122 123 struct list_head writes; 124 spinlock_t writes_lock; 125 126 enum write_point_state state; 127 u64 last_state_change; 128 u64 time[WRITE_POINT_STATE_NR]; 129 u64 last_runtime; 130 } __aligned(SMP_CACHE_BYTES); 131 }; 132 133 struct write_point_specifier { 134 unsigned long v; 135 }; 136 137 #endif /* _BCACHEFS_ALLOC_TYPES_H */ 138