reduce the size of ppage by 8 bytes using signly linked list
[lunaix-os.git] / lunaix-os / includes / lunaix / ds / lru.h
1 #ifndef __LUNAIX_LRU_H
2 #define __LUNAIX_LRU_H
3
4 #include <lunaix/ds/llist.h>
5 #include <lunaix/ds/spinlock.h>
6 #include <lunaix/types.h>
7
8 struct lru_node
9 {
10     struct llist_header lru_nodes;
11 };
12
13 typedef int (*evict_cb)(struct lru_node* lru_obj);
14
15 struct lru_zone
16 {
17     struct llist_header lead_node;
18     struct llist_header zones;
19     char name[32];
20     evict_cb try_evict;
21     spinlock_t lock;
22
23     unsigned int objects;
24     unsigned int hotness;
25     struct {
26         unsigned int n_single;
27         unsigned int n_half;
28         unsigned int n_full;
29     } evict_stats;
30
31     union {
32         struct {
33             bool delayed_free:1;
34             unsigned char attempts;
35         };
36         unsigned int flags;
37     };
38 };
39
40 struct lru_zone*
41 lru_new_zone(const char* name, evict_cb try_evict_cb);
42
43 void
44 lru_use_one(struct lru_zone* zone, struct lru_node* node);
45
46 void
47 lru_evict_one(struct lru_zone* zone);
48
49 void
50 lru_remove(struct lru_zone* zone, struct lru_node* node);
51
52 void
53 lru_evict_half(struct lru_zone* zone);
54
55 void
56 lru_evict_all(struct lru_zone* zone);
57
58 void
59 lru_free_zone(struct lru_zone* zone);
60
61 #endif /* __LUNAIX_LRU_H */