]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/journal_reclaim.h
Update bcachefs sources to 5241335413 bcachefs: Fix for spinning in journal reclaim...
[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         if (p && !j->reclaim_kicked) {
12                 j->reclaim_kicked = true;
13                 if (p)
14                         wake_up_process(p);
15         }
16 }
17
18 unsigned bch2_journal_dev_buckets_available(struct journal *,
19                                             struct journal_device *,
20                                             enum journal_space_from);
21 void bch2_journal_space_available(struct journal *);
22
23 static inline bool journal_pin_active(struct journal_entry_pin *pin)
24 {
25         return pin->seq != 0;
26 }
27
28 static inline struct journal_entry_pin_list *
29 journal_seq_pin(struct journal *j, u64 seq)
30 {
31         EBUG_ON(seq < j->pin.front || seq >= j->pin.back);
32
33         return &j->pin.data[seq & j->pin.mask];
34 }
35
36 void __bch2_journal_pin_put(struct journal *, u64);
37 void bch2_journal_pin_put(struct journal *, u64);
38 void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
39
40 void bch2_journal_pin_set(struct journal *, u64, struct journal_entry_pin *,
41                           journal_pin_flush_fn);
42
43 static inline void bch2_journal_pin_add(struct journal *j, u64 seq,
44                                         struct journal_entry_pin *pin,
45                                         journal_pin_flush_fn flush_fn)
46 {
47         if (unlikely(!journal_pin_active(pin) || pin->seq > seq))
48                 bch2_journal_pin_set(j, seq, pin, flush_fn);
49 }
50
51 static inline void bch2_journal_pin_copy(struct journal *j,
52                                          struct journal_entry_pin *dst,
53                                          struct journal_entry_pin *src,
54                                          journal_pin_flush_fn flush_fn)
55 {
56         /* Guard against racing with journal_pin_drop(src): */
57         u64 seq = READ_ONCE(src->seq);
58
59         if (seq)
60                 bch2_journal_pin_add(j, seq, dst, flush_fn);
61 }
62
63 static inline void bch2_journal_pin_update(struct journal *j, u64 seq,
64                                            struct journal_entry_pin *pin,
65                                            journal_pin_flush_fn flush_fn)
66 {
67         if (unlikely(!journal_pin_active(pin) || pin->seq < seq))
68                 bch2_journal_pin_set(j, seq, pin, flush_fn);
69 }
70
71 void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);
72
73 void bch2_journal_do_discards(struct journal *);
74 int bch2_journal_reclaim(struct journal *);
75
76 void bch2_journal_reclaim_stop(struct journal *);
77 int bch2_journal_reclaim_start(struct journal *);
78
79 bool bch2_journal_flush_pins(struct journal *, u64);
80
81 static inline bool bch2_journal_flush_all_pins(struct journal *j)
82 {
83         return bch2_journal_flush_pins(j, U64_MAX);
84 }
85
86 int bch2_journal_flush_device_pins(struct journal *, int);
87
88 #endif /* _BCACHEFS_JOURNAL_RECLAIM_H */