Commit | Line | Data |
---|---|---|
1c6fdbd8 KO |
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 | ||
b7a9bbfc KO |
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 | ||
e5a66496 | 18 | unsigned bch2_journal_dev_buckets_available(struct journal *, |
03d5eaed KO |
19 | struct journal_device *, |
20 | enum journal_space_from); | |
e5a66496 KO |
21 | void bch2_journal_space_available(struct journal *); |
22 | ||
1c6fdbd8 KO |
23 | static inline bool journal_pin_active(struct journal_entry_pin *pin) |
24 | { | |
4077991c | 25 | return pin->seq != 0; |
1c6fdbd8 KO |
26 | } |
27 | ||
28 | static inline struct journal_entry_pin_list * | |
29 | journal_seq_pin(struct journal *j, u64 seq) | |
30 | { | |
4077991c | 31 | EBUG_ON(seq < j->pin.front || seq >= j->pin.back); |
1c6fdbd8 KO |
32 | |
33 | return &j->pin.data[seq & j->pin.mask]; | |
34 | } | |
35 | ||
ebb84d09 | 36 | void __bch2_journal_pin_put(struct journal *, u64); |
e5a66496 | 37 | void bch2_journal_pin_put(struct journal *, u64); |
1c6fdbd8 | 38 | void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *); |
3f58a197 | 39 | |
231db03c KO |
40 | void bch2_journal_pin_set(struct journal *, u64, struct journal_entry_pin *, |
41 | journal_pin_flush_fn); | |
3f58a197 KO |
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 | { | |
00b8ccf7 | 47 | if (unlikely(!journal_pin_active(pin) || pin->seq > seq)) |
231db03c | 48 | bch2_journal_pin_set(j, seq, pin, flush_fn); |
3f58a197 KO |
49 | } |
50 | ||
231db03c KO |
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 | { | |
d483dd17 KO |
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); | |
231db03c | 61 | } |
2ca88e5a | 62 | |
231db03c KO |
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 | } | |
3f58a197 | 70 | |
4077991c | 71 | void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *); |
1c6fdbd8 | 72 | |
2384db8f | 73 | void bch2_journal_do_discards(struct journal *); |
afa7cb0c | 74 | int bch2_journal_reclaim(struct journal *); |
b7a9bbfc KO |
75 | |
76 | void bch2_journal_reclaim_stop(struct journal *); | |
77 | int bch2_journal_reclaim_start(struct journal *); | |
1c6fdbd8 | 78 | |
039fc4c5 | 79 | bool bch2_journal_flush_pins(struct journal *, u64); |
1c6fdbd8 | 80 | |
039fc4c5 | 81 | static inline bool bch2_journal_flush_all_pins(struct journal *j) |
1c6fdbd8 | 82 | { |
039fc4c5 | 83 | return bch2_journal_flush_pins(j, U64_MAX); |
1c6fdbd8 KO |
84 | } |
85 | ||
86 | int bch2_journal_flush_device_pins(struct journal *, int); | |
87 | ||
88 | #endif /* _BCACHEFS_JOURNAL_RECLAIM_H */ |