]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/journal_reclaim.h
Update bcachefs sources to 4837f82ee1 bcachefs: Use cached iterators for alloc btree
[bcachefs-tools-debian] / libbcachefs / journal_reclaim.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_JOURNAL_RECLAIM_H
3 #define _BCACHEFS_JOURNAL_RECLAIM_H
4
5 #define JOURNAL_PIN     (32 * 1024)
6
7 enum journal_space_from {
8         journal_space_discarded,
9         journal_space_clean_ondisk,
10         journal_space_clean,
11 };
12
13 unsigned bch2_journal_dev_buckets_available(struct journal *,
14                                             struct journal_device *,
15                                             enum journal_space_from);
16 void bch2_journal_space_available(struct journal *);
17
18 static inline bool journal_pin_active(struct journal_entry_pin *pin)
19 {
20         return pin->seq != 0;
21 }
22
23 static inline struct journal_entry_pin_list *
24 journal_seq_pin(struct journal *j, u64 seq)
25 {
26         EBUG_ON(seq < j->pin.front || seq >= j->pin.back);
27
28         return &j->pin.data[seq & j->pin.mask];
29 }
30
31 void bch2_journal_pin_put(struct journal *, u64);
32 void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
33
34 void __bch2_journal_pin_add(struct journal *, u64, struct journal_entry_pin *,
35                             journal_pin_flush_fn);
36
37 static inline void bch2_journal_pin_add(struct journal *j, u64 seq,
38                                         struct journal_entry_pin *pin,
39                                         journal_pin_flush_fn flush_fn)
40 {
41         if (unlikely(!journal_pin_active(pin) || pin->seq > seq))
42                 __bch2_journal_pin_add(j, seq, pin, flush_fn);
43 }
44
45 void bch2_journal_pin_update(struct journal *, u64,
46                              struct journal_entry_pin *,
47                              journal_pin_flush_fn);
48
49 void bch2_journal_pin_copy(struct journal *,
50                            struct journal_entry_pin *,
51                            struct journal_entry_pin *,
52                            journal_pin_flush_fn);
53
54 void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);
55
56 void bch2_journal_do_discards(struct journal *);
57 void bch2_journal_reclaim(struct journal *);
58 void bch2_journal_reclaim_work(struct work_struct *);
59
60 bool bch2_journal_flush_pins(struct journal *, u64);
61
62 static inline bool bch2_journal_flush_all_pins(struct journal *j)
63 {
64         return bch2_journal_flush_pins(j, U64_MAX);
65 }
66
67 int bch2_journal_flush_device_pins(struct journal *, int);
68
69 #endif /* _BCACHEFS_JOURNAL_RECLAIM_H */