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 enum journal_space_from {
8 journal_space_discarded,
9 journal_space_clean_ondisk,
13 static inline void journal_reclaim_kick(struct journal *j)
15 struct task_struct *p = READ_ONCE(j->reclaim_thread);
17 if (p && !j->reclaim_kicked) {
18 j->reclaim_kicked = true;
24 unsigned bch2_journal_dev_buckets_available(struct journal *,
25 struct journal_device *,
26 enum journal_space_from);
27 void bch2_journal_space_available(struct journal *);
29 static inline bool journal_pin_active(struct journal_entry_pin *pin)
34 static inline struct journal_entry_pin_list *
35 journal_seq_pin(struct journal *j, u64 seq)
37 EBUG_ON(seq < j->pin.front || seq >= j->pin.back);
39 return &j->pin.data[seq & j->pin.mask];
42 void bch2_journal_pin_put(struct journal *, u64);
43 void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
45 void __bch2_journal_pin_add(struct journal *, u64, struct journal_entry_pin *,
46 journal_pin_flush_fn);
48 static inline void bch2_journal_pin_add(struct journal *j, u64 seq,
49 struct journal_entry_pin *pin,
50 journal_pin_flush_fn flush_fn)
52 if (unlikely(!journal_pin_active(pin) || pin->seq > seq))
53 __bch2_journal_pin_add(j, seq, pin, flush_fn);
56 void bch2_journal_pin_update(struct journal *, u64,
57 struct journal_entry_pin *,
58 journal_pin_flush_fn);
60 void bch2_journal_pin_copy(struct journal *,
61 struct journal_entry_pin *,
62 struct journal_entry_pin *,
63 journal_pin_flush_fn);
65 void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);
67 void bch2_journal_do_discards(struct journal *);
68 void bch2_journal_reclaim(struct journal *);
70 void bch2_journal_reclaim_stop(struct journal *);
71 int bch2_journal_reclaim_start(struct journal *);
73 bool bch2_journal_flush_pins(struct journal *, u64);
75 static inline bool bch2_journal_flush_all_pins(struct journal *j)
77 return bch2_journal_flush_pins(j, U64_MAX);
80 int bch2_journal_flush_device_pins(struct journal *, int);
82 #endif /* _BCACHEFS_JOURNAL_RECLAIM_H */