1 #ifndef _BCACHEFS_JOURNAL_TYPES_H
2 #define _BCACHEFS_JOURNAL_TYPES_H
4 #include <linux/cache.h>
5 #include <linux/workqueue.h>
7 #include "alloc_types.h"
8 #include "super_types.h"
14 * We put two of these in struct journal; we used them for writes to the
15 * journal that are being staged or in flight.
22 struct closure_waitlist wait;
24 unsigned buf_size; /* size in bytes of @data */
25 unsigned sectors; /* maximum size for current entry */
26 unsigned disk_sectors; /* maximum size entry could have been, if
27 buf_size was bigger */
28 unsigned u64s_reserved;
30 unsigned long has_inode[1024 / sizeof(unsigned long)];
34 * Something that makes a journal entry dirty - i.e. a btree node that has to be
38 struct journal_entry_pin_list {
39 struct list_head list;
40 struct list_head flushed;
42 struct bch_devs_list devs;
46 struct journal_entry_pin;
47 typedef void (*journal_pin_flush_fn)(struct journal *j,
48 struct journal_entry_pin *, u64);
50 struct journal_entry_pin {
51 struct list_head list;
52 journal_pin_flush_fn flush;
56 /* corresponds to a btree node with a blacklisted bset: */
57 struct blacklisted_node {
59 enum btree_id btree_id;
63 struct journal_seq_blacklist {
64 struct list_head list;
68 struct journal_entry_pin pin;
70 struct blacklisted_node *entries;
82 union journal_res_state {
92 u64 cur_entry_offset:20,
101 #define JOURNAL_ENTRY_SIZE_MIN (64U << 10) /* 64k */
102 #define JOURNAL_ENTRY_SIZE_MAX (4U << 20) /* 4M */
105 * We stash some journal state as sentinal values in cur_entry_offset:
106 * note - cur_entry_offset is in units of u64s
108 #define JOURNAL_ENTRY_OFFSET_MAX ((1U << 20) - 1)
110 #define JOURNAL_ENTRY_CLOSED_VAL (JOURNAL_ENTRY_OFFSET_MAX - 1)
111 #define JOURNAL_ENTRY_ERROR_VAL (JOURNAL_ENTRY_OFFSET_MAX)
114 * JOURNAL_NEED_WRITE - current (pending) journal entry should be written ASAP,
115 * either because something's waiting on the write to complete or because it's
116 * been dirty too long and the timer's expired.
126 /* Embedded in struct bch_fs */
128 /* Fastpath stuff up front: */
132 union journal_res_state reservations;
134 /* Max size of current journal entry */
135 unsigned cur_entry_u64s;
136 unsigned cur_entry_sectors;
138 /* Reserved space in journal entry to be used just prior to write */
139 unsigned entry_u64s_reserved;
141 unsigned buf_size_want;
144 * Two journal entries -- one is currently open for new entries, the
145 * other is possibly being written out.
147 struct journal_buf buf[2];
151 /* if nonzero, we may not open a new journal entry: */
154 /* Used when waiting because the journal was full */
155 wait_queue_head_t wait;
156 struct closure_waitlist async_wait;
159 struct delayed_work write_work;
161 /* Sequence number of most recent journal entry (last entry in @pin) */
164 /* seq, last_seq from the most recent journal entry successfully written */
169 * FIFO of journal entries whose btree updates have not yet been
172 * Each entry is a reference count. The position in the FIFO is the
173 * entry's sequence number relative to @seq.
175 * The journal entry itself holds a reference count, put when the
176 * journal entry is written out. Each btree node modified by the journal
177 * entry also holds a reference count, put when the btree node is
180 * When a reference count reaches zero, the journal entry is no longer
181 * needed. When all journal entries in the oldest journal bucket are no
182 * longer needed, the bucket can be discarded and reused.
185 u64 front, back, size, mask;
186 struct journal_entry_pin_list *data;
189 struct journal_entry_pin *flush_in_progress;
190 wait_queue_head_t pin_flush_wait;
192 u64 replay_journal_seq;
194 struct mutex blacklist_lock;
195 struct list_head seq_blacklist;
196 struct journal_seq_blacklist *new_blacklist;
198 struct write_point wp;
201 struct delayed_work reclaim_work;
202 unsigned long last_flushed;
204 /* protects advancing ja->last_idx: */
205 struct mutex reclaim_lock;
206 unsigned write_delay_ms;
207 unsigned reclaim_delay_ms;
209 u64 res_get_blocked_start;
211 u64 write_start_time;
213 struct time_stats *write_time;
214 struct time_stats *delay_time;
215 struct time_stats *blocked_time;
216 struct time_stats *flush_seq_time;
218 #ifdef CONFIG_DEBUG_LOCK_ALLOC
219 struct lockdep_map res_map;
224 * Embedded in struct bch_dev. First three fields refer to the array of journal
225 * buckets, in bch_sb.
227 struct journal_device {
229 * For each journal bucket, contains the max sequence number of the
230 * journal writes it contains - so we know when a bucket can be reused.
234 unsigned sectors_free;
236 /* Journal bucket we're currently writing to */
239 /* Last journal bucket that still contains an open journal entry */
242 * j->lock and j->reclaim_lock must both be held to modify, j->lock
243 * sufficient to read:
249 /* Bio for journal reads/writes to this device */
252 /* for bch_journal_read_device */
257 * journal_entry_res - reserve space in every journal entry:
259 struct journal_entry_res {
263 #endif /* _BCACHEFS_JOURNAL_TYPES_H */