1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_JOURNAL_RECLAIM_H
3 #define _BCACHEFS_JOURNAL_RECLAIM_H
5 #define JOURNAL_PIN (32 * 1024)
7 static inline void journal_reclaim_kick(struct journal *j)
9 struct task_struct *p = READ_ONCE(j->reclaim_thread);
11 j->reclaim_kicked = true;
16 unsigned bch2_journal_dev_buckets_available(struct journal *,
17 struct journal_device *,
18 enum journal_space_from);
19 void bch2_journal_space_available(struct journal *);
21 static inline bool journal_pin_active(struct journal_entry_pin *pin)
26 static inline struct journal_entry_pin_list *
27 journal_seq_pin(struct journal *j, u64 seq)
29 EBUG_ON(seq < j->pin.front || seq >= j->pin.back);
31 return &j->pin.data[seq & j->pin.mask];
34 void __bch2_journal_pin_put(struct journal *, u64);
35 void bch2_journal_pin_put(struct journal *, u64);
36 void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
38 void bch2_journal_pin_set(struct journal *, u64, struct journal_entry_pin *,
39 journal_pin_flush_fn);
41 static inline void bch2_journal_pin_add(struct journal *j, u64 seq,
42 struct journal_entry_pin *pin,
43 journal_pin_flush_fn flush_fn)
45 if (unlikely(!journal_pin_active(pin) || pin->seq > seq))
46 bch2_journal_pin_set(j, seq, pin, flush_fn);
49 static inline void bch2_journal_pin_copy(struct journal *j,
50 struct journal_entry_pin *dst,
51 struct journal_entry_pin *src,
52 journal_pin_flush_fn flush_fn)
54 /* Guard against racing with journal_pin_drop(src): */
55 u64 seq = READ_ONCE(src->seq);
58 bch2_journal_pin_add(j, seq, dst, flush_fn);
61 static inline void bch2_journal_pin_update(struct journal *j, u64 seq,
62 struct journal_entry_pin *pin,
63 journal_pin_flush_fn flush_fn)
65 if (unlikely(!journal_pin_active(pin) || pin->seq < seq))
66 bch2_journal_pin_set(j, seq, pin, flush_fn);
69 void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);
71 void bch2_journal_do_discards(struct journal *);
72 int bch2_journal_reclaim(struct journal *);
74 void bch2_journal_reclaim_stop(struct journal *);
75 int bch2_journal_reclaim_start(struct journal *);
77 bool bch2_journal_flush_pins(struct journal *, u64);
79 static inline bool bch2_journal_flush_all_pins(struct journal *j)
81 return bch2_journal_flush_pins(j, U64_MAX);
84 int bch2_journal_flush_device_pins(struct journal *, int);
86 #endif /* _BCACHEFS_JOURNAL_RECLAIM_H */