bcachefs: Erasure coding fixes & refactoring
[linux-block.git] / fs / bcachefs / journal_reclaim.h
CommitLineData
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
7static 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 18unsigned bch2_journal_dev_buckets_available(struct journal *,
03d5eaed
KO
19 struct journal_device *,
20 enum journal_space_from);
e5a66496
KO
21void bch2_journal_space_available(struct journal *);
22
1c6fdbd8
KO
23static inline bool journal_pin_active(struct journal_entry_pin *pin)
24{
4077991c 25 return pin->seq != 0;
1c6fdbd8
KO
26}
27
28static inline struct journal_entry_pin_list *
29journal_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 36void __bch2_journal_pin_put(struct journal *, u64);
e5a66496 37void bch2_journal_pin_put(struct journal *, u64);
1c6fdbd8 38void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
3f58a197 39
231db03c
KO
40void bch2_journal_pin_set(struct journal *, u64, struct journal_entry_pin *,
41 journal_pin_flush_fn);
3f58a197
KO
42
43static 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
51static 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
63static 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 71void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);
1c6fdbd8 72
2384db8f 73void bch2_journal_do_discards(struct journal *);
afa7cb0c 74int bch2_journal_reclaim(struct journal *);
b7a9bbfc
KO
75
76void bch2_journal_reclaim_stop(struct journal *);
77int bch2_journal_reclaim_start(struct journal *);
1c6fdbd8 78
039fc4c5 79bool bch2_journal_flush_pins(struct journal *, u64);
1c6fdbd8 80
039fc4c5 81static 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
86int bch2_journal_flush_device_pins(struct journal *, int);
87
88#endif /* _BCACHEFS_JOURNAL_RECLAIM_H */