]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/journal_reclaim.h
Update bcachefs sources to feaca6edbd24 mean and variance: Promote to lib/math
[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 static inline void journal_reclaim_kick(struct journal *j)
8 {
9         struct task_struct *p = READ_ONCE(j->reclaim_thread);
10
11         j->reclaim_kicked = true;
12         if (p)
13                 wake_up_process(p);
14 }
15
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 *);
20
21 static inline bool journal_pin_active(struct journal_entry_pin *pin)
22 {
23         return pin->seq != 0;
24 }
25
26 static inline struct journal_entry_pin_list *
27 journal_seq_pin(struct journal *j, u64 seq)
28 {
29         EBUG_ON(seq < j->pin.front || seq >= j->pin.back);
30
31         return &j->pin.data[seq & j->pin.mask];
32 }
33
34 void bch2_journal_reclaim_fast(struct journal *);
35 bool __bch2_journal_pin_put(struct journal *, u64);
36 void bch2_journal_pin_put(struct journal *, u64);
37 void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
38
39 void bch2_journal_pin_set(struct journal *, u64, struct journal_entry_pin *,
40                           journal_pin_flush_fn);
41
42 static inline void bch2_journal_pin_add(struct journal *j, u64 seq,
43                                         struct journal_entry_pin *pin,
44                                         journal_pin_flush_fn flush_fn)
45 {
46         if (unlikely(!journal_pin_active(pin) || pin->seq > seq))
47                 bch2_journal_pin_set(j, seq, pin, flush_fn);
48 }
49
50 void bch2_journal_pin_copy(struct journal *,
51                            struct journal_entry_pin *,
52                            struct journal_entry_pin *,
53                            journal_pin_flush_fn);
54
55 static inline void bch2_journal_pin_update(struct journal *j, u64 seq,
56                                            struct journal_entry_pin *pin,
57                                            journal_pin_flush_fn flush_fn)
58 {
59         if (unlikely(!journal_pin_active(pin) || pin->seq < seq))
60                 bch2_journal_pin_set(j, seq, pin, flush_fn);
61 }
62
63 void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);
64
65 void bch2_journal_do_discards(struct journal *);
66 int bch2_journal_reclaim(struct journal *);
67
68 void bch2_journal_reclaim_stop(struct journal *);
69 int bch2_journal_reclaim_start(struct journal *);
70
71 bool bch2_journal_flush_pins(struct journal *, u64);
72
73 static inline bool bch2_journal_flush_all_pins(struct journal *j)
74 {
75         return bch2_journal_flush_pins(j, U64_MAX);
76 }
77
78 int bch2_journal_flush_device_pins(struct journal *, int);
79
80 #endif /* _BCACHEFS_JOURNAL_RECLAIM_H */