blob: 0e4e2eec5c1db85f4a7d4340147ddbe3263f8bc6 [file] [log] [blame]
Dan Magenheimerc3ba9692012-04-09 17:06:54 -06001#ifndef _LINUX_FRONTSWAP_H
2#define _LINUX_FRONTSWAP_H
3
4#include <linux/swap.h>
5#include <linux/mm.h>
6#include <linux/bitops.h>
7
8struct frontswap_ops {
9 void (*init)(unsigned);
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040010 int (*store)(unsigned, pgoff_t, struct page *);
11 int (*load)(unsigned, pgoff_t, struct page *);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060012 void (*invalidate_page)(unsigned, pgoff_t);
13 void (*invalidate_area)(unsigned);
14};
15
16extern bool frontswap_enabled;
17extern struct frontswap_ops
18 frontswap_register_ops(struct frontswap_ops *ops);
19extern void frontswap_shrink(unsigned long);
20extern unsigned long frontswap_curr_pages(void);
21extern void frontswap_writethrough(bool);
22
23extern void __frontswap_init(unsigned type);
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040024extern int __frontswap_store(struct page *page);
25extern int __frontswap_load(struct page *page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060026extern void __frontswap_invalidate_page(unsigned, pgoff_t);
27extern void __frontswap_invalidate_area(unsigned);
28
29#ifdef CONFIG_FRONTSWAP
30
31static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
32{
33 bool ret = false;
34
35 if (frontswap_enabled && sis->frontswap_map)
36 ret = test_bit(offset, sis->frontswap_map);
37 return ret;
38}
39
40static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset)
41{
42 if (frontswap_enabled && sis->frontswap_map)
43 set_bit(offset, sis->frontswap_map);
44}
45
46static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset)
47{
48 if (frontswap_enabled && sis->frontswap_map)
49 clear_bit(offset, sis->frontswap_map);
50}
51
52static inline void frontswap_map_set(struct swap_info_struct *p,
53 unsigned long *map)
54{
55 p->frontswap_map = map;
56}
57
58static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
59{
60 return p->frontswap_map;
61}
62#else
63/* all inline routines become no-ops and all externs are ignored */
64
65#define frontswap_enabled (0)
66
67static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
68{
69 return false;
70}
71
72static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset)
73{
74}
75
76static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset)
77{
78}
79
80static inline void frontswap_map_set(struct swap_info_struct *p,
81 unsigned long *map)
82{
83}
84
85static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
86{
87 return NULL;
88}
89#endif
90
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040091static inline int frontswap_store(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060092{
93 int ret = -1;
94
95 if (frontswap_enabled)
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040096 ret = __frontswap_store(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060097 return ret;
98}
99
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -0400100static inline int frontswap_load(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600101{
102 int ret = -1;
103
104 if (frontswap_enabled)
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -0400105 ret = __frontswap_load(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600106 return ret;
107}
108
109static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset)
110{
111 if (frontswap_enabled)
112 __frontswap_invalidate_page(type, offset);
113}
114
115static inline void frontswap_invalidate_area(unsigned type)
116{
117 if (frontswap_enabled)
118 __frontswap_invalidate_area(type);
119}
120
121static inline void frontswap_init(unsigned type)
122{
123 if (frontswap_enabled)
124 __frontswap_init(type);
125}
126
127#endif /* _LINUX_FRONTSWAP_H */