]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/lru.h
Update bcachefs sources to 070ec8d07b bcachefs: Snapshot depth, skiplist fields
[bcachefs-tools-debian] / libbcachefs / lru.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_LRU_H
3 #define _BCACHEFS_LRU_H
4
5 #define LRU_TIME_BITS   48
6 #define LRU_TIME_MAX    ((1ULL << LRU_TIME_BITS) - 1)
7
8 static inline struct bpos lru_pos(u16 lru_id, u64 dev_bucket, u64 time)
9 {
10         EBUG_ON(time > LRU_TIME_MAX);
11
12         return POS(((u64) lru_id << LRU_TIME_BITS)|time, dev_bucket);
13 }
14
15 static inline u64 lru_pos_id(struct bpos pos)
16 {
17         return pos.inode >> LRU_TIME_BITS;
18 }
19
20 static inline u64 lru_pos_time(struct bpos pos)
21 {
22         return pos.inode & ~(~0ULL << LRU_TIME_BITS);
23 }
24
25 #define BCH_LRU_TYPES()         \
26         x(read)                 \
27         x(fragmentation)
28
29 enum bch_lru_type {
30 #define x(n) BCH_LRU_##n,
31         BCH_LRU_TYPES()
32 #undef x
33 };
34
35 #define BCH_LRU_FRAGMENTATION_START     ((1U << 16) - 1)
36
37 static inline enum bch_lru_type lru_type(struct bkey_s_c l)
38 {
39         u16 lru_id = l.k->p.inode >> 48;
40
41         if (lru_id == BCH_LRU_FRAGMENTATION_START)
42                 return BCH_LRU_fragmentation;
43         return BCH_LRU_read;
44 }
45
46 int bch2_lru_invalid(const struct bch_fs *, struct bkey_s_c,
47                      enum bkey_invalid_flags, struct printbuf *);
48 void bch2_lru_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
49
50 void bch2_lru_pos_to_text(struct printbuf *, struct bpos);
51
52 #define bch2_bkey_ops_lru ((struct bkey_ops) {  \
53         .key_invalid    = bch2_lru_invalid,     \
54         .val_to_text    = bch2_lru_to_text,     \
55         .min_val_size   = 8,                    \
56 })
57
58 int bch2_lru_del(struct btree_trans *, u16, u64, u64);
59 int bch2_lru_set(struct btree_trans *, u16, u64, u64);
60 int bch2_lru_change(struct btree_trans *, u16, u64, u64, u64);
61
62 int bch2_check_lrus(struct bch_fs *);
63
64 #endif /* _BCACHEFS_LRU_H */